-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Assignment of column via .loc for numpy non-ns datetimes #27928
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 2 commits
ed9d7f0
49471e7
9efb169
41df89d
6df540c
98a5061
299a5b1
cf18fb9
09ab203
93c2f85
ad771f5
35009b7
6a48ca6
063cc37
d64a2d8
86fd1c1
2ddbc01
48e454a
c8eb91f
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 |
---|---|---|
|
@@ -1026,7 +1026,7 @@ def maybe_cast_to_datetime(value, dtype, errors="raise"): | |
) | ||
|
||
if is_datetime64 and not is_dtype_equal(dtype, _NS_DTYPE): | ||
if dtype.name in ("datetime64", "datetime64[ns]"): | ||
if dtype.name in ("datetime64", "datetime64[ns]", "datetime64[D]"): | ||
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. just use 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. Since |
||
if dtype.name == "datetime64": | ||
raise ValueError(msg.format(dtype=dtype.name)) | ||
dtype = _NS_DTYPE | ||
|
@@ -1044,7 +1044,7 @@ def maybe_cast_to_datetime(value, dtype, errors="raise"): | |
value = [value] | ||
|
||
elif is_timedelta64 and not is_dtype_equal(dtype, _TD_DTYPE): | ||
if dtype.name in ("timedelta64", "timedelta64[ns]"): | ||
if dtype.name in ("timedelta64", "timedelta64[ns]", "timedelta64[D]"): | ||
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.
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. Since |
||
if dtype.name == "timedelta64": | ||
raise ValueError(msg.format(dtype=dtype.name)) | ||
dtype = _TD_DTYPE | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
cast_scalar_to_array, | ||
infer_dtype_from_array, | ||
infer_dtype_from_scalar, | ||
maybe_cast_to_datetime, | ||
) | ||
from pandas.core.dtypes.common import is_dtype_equal | ||
|
||
|
@@ -169,3 +170,14 @@ def test_cast_scalar_to_array(obj, dtype): | |
|
||
arr = cast_scalar_to_array(shape, obj, dtype=dtype) | ||
tm.assert_numpy_array_equal(arr, exp) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
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. its ok to test this i guess, but would need to parameterize on datetime64[D], ns, datetime64 etc and check the result 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. done. I made all possible datetime formats except [ps] (as mentioned above) 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. I think @jreback's comment was requesting testing those other frequencies here. And then assert the result matches too. result = maybe_cast_to_datetime(obj, dtype)
expected = pd.Timestamp(...) # right?
assert result == expected |
||
"obj,dtype", | ||
[ | ||
(np.datetime64("2017-01-01 01:00:00"), "datetime64[D]"), | ||
(np.datetime64("2017-01-01 02:00:00"), "datetime64[D]"), | ||
], | ||
) | ||
def test_maybe_cast_to_datetime(obj, dtype): | ||
maybe_cast_to_datetime(obj, dtype) |
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.
this is a private function, you would have to indicate the user facing experience here instead (e.g. the assignment)