-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TST: Add astype_nansafe datetime tests #28533
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 all commits
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
import pandas.util._test_decorators as td | ||
|
||
from pandas.core.dtypes.cast import astype_nansafe | ||
import pandas.core.dtypes.common as com | ||
from pandas.core.dtypes.dtypes import ( | ||
CategoricalDtype, | ||
|
@@ -706,3 +707,24 @@ def test__get_dtype_fails(input_param, expected_error_message): | |
) | ||
def test__is_dtype_type(input_param, result): | ||
assert com._is_dtype_type(input_param, lambda tipo: tipo == result) | ||
|
||
|
||
@pytest.mark.parametrize("from_type", [np.datetime64, np.timedelta64]) | ||
@pytest.mark.parametrize( | ||
"to_type", | ||
[ | ||
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. can you add a test for the object path (for dtype=) when its a datetime/timedelta 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. What would the expected output be for that case? I would think it'd agree with
|
||
np.uint8, | ||
np.uint16, | ||
np.uint32, | ||
np.int8, | ||
np.int16, | ||
np.int32, | ||
np.float16, | ||
np.float32, | ||
], | ||
) | ||
def test_astype_datetime64_bad_dtype_raises(from_type, to_type): | ||
arr = np.array([from_type("2018")]) | ||
|
||
with pytest.raises(TypeError, match="cannot astype"): | ||
astype_nansafe(arr, dtype=to_type) |
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.
Could this get used elsewhere? If so might be good to make a shared fixture for
numeric_dtype
or something to the effectThere 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 particular setup might be a little specific in that all the
to_types
have lesser precision than thefrom_types
, but did you have something in mind?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 ok