Skip to content

Conversation

@dsaxton
Copy link
Contributor

@dsaxton dsaxton commented Sep 19, 2019

Adds tests for astype_nansafe in situations where we can't perform a datetime casting because of a precision mismatch:

arr                                                                             
# array(['2018-01-01'], dtype='datetime64[D]')

arr.view(np.int32)                                                              
# array([17532,     0], dtype=int32)

arr.view(np.float32)                                                            
# array([2.4568e-41, 0.0000e+00], dtype=float32)

Related to #28492



@pytest.mark.parametrize("from_type", [np.datetime64, np.timedelta64])
@pytest.mark.parametrize(
Copy link
Member

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 effect

Copy link
Contributor Author

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 the from_types, but did you have something in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ok

@WillAyd WillAyd added the Testing pandas testing functions or related to the test suite label Sep 20, 2019
@WillAyd WillAyd added this to the 1.0 milestone Sep 20, 2019


@pytest.mark.parametrize("from_type", [np.datetime64, np.timedelta64])
@pytest.mark.parametrize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ok

@pytest.mark.parametrize("from_type", [np.datetime64, np.timedelta64])
@pytest.mark.parametrize(
"to_type",
[
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 astype from numpy when we don't have any NA values but the result is a bit odd:

[ins] In [3]: arr = np.array([np.datetime64("2018")])                                          

[ins] In [4]: arr.astype("object")                                                             
Out[4]: array([datetime.date(2018, 1, 1)], dtype=object)

[ins] In [5]: astype_nansafe(arr, dtype="object")                                              
Out[5]: array([datetime.datetime(1970, 1, 1, 0, 0)], dtype=object)

@jreback
Copy link
Contributor

jreback commented Sep 23, 2019

how is this PR distinct from #28492

@dsaxton
Copy link
Contributor Author

dsaxton commented Sep 25, 2019

how is this PR distinct from #28492

I was thinking it was worth treating separately since that PR deals with NaT specifically whereas this was testing other paths (non-missing values that nonetheless can't be cast) without any logic changes

@jreback
Copy link
Contributor

jreback commented Sep 25, 2019

i would just close this and merge #28492

@dsaxton dsaxton closed this Sep 25, 2019
@dsaxton dsaxton deleted the astype-test branch September 25, 2019 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Testing pandas testing functions or related to the test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants