-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: astype with timedelta and datetime string (#22100) #22107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
8cb0654
52257e3
7196cf5
e508d93
3a182a3
7be8de9
21c0520
74e670b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -24,7 +24,8 @@ | |||
find_common_type, | ||||
construct_1d_object_array_from_listlike, | ||||
construct_1d_ndarray_preserving_na, | ||||
construct_1d_arraylike_from_scalar) | ||||
construct_1d_arraylike_from_scalar, | ||||
astype_nansafe) | ||||
from pandas.core.dtypes.dtypes import ( | ||||
CategoricalDtype, | ||||
DatetimeTZDtype, | ||||
|
@@ -456,3 +457,17 @@ def test_cast_1d_arraylike_from_scalar_categorical(self): | |||
def test_construct_1d_ndarray_preserving_na(values, dtype, expected): | ||||
result = construct_1d_ndarray_preserving_na(values, dtype=dtype) | ||||
tm.assert_numpy_array_equal(result, expected) | ||||
|
||||
|
||||
@pytest.mark.parametrize('arr, dtype, expected', [ | ||||
(np.array(['0:0:1'], dtype='object'), | ||||
'timedelta64[ns]', 'timedelta64[ns]'), | ||||
(np.array(['2000'], dtype='object'), | ||||
'datetime64[ns]', 'datetime64[ns]'), | ||||
(np.array(['2000'], dtype='object'), | ||||
'datetime64', 'datetime64[ns]'), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can be made less verbose (easier to read if on one line, but not a huge deal) by changing |
||||
]) | ||||
def test_astype_nansafe(arr, dtype, expected): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI whatever the solution is here would impact the other limitation with pandas/pandas/io/json/table_schema.py Line 304 in d010469
I'd be fine with just raising as part of this PR until its explicitly resolved but just bringing that up for visibility |
||||
# GH #22100 | ||||
result = astype_nansafe(arr, dtype) | ||||
assert is_dtype_equal(result.dtype, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_TD_DTYPE is specifically
timedelta64[ns]
. Are there paths that get here with e.g.timedelta64[D]
? (I'm assuming those should be excluded too.IIRC datetimete64 dtype won't trigger
np.issubtype(dtype.type, np.integer)
, am I remembering incorrectly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, seems I was wrong about datetime64, they worked fine before.