Skip to content

BUG: fix+test assigning invalid NAT-like to DTA/TDA/PA #27331

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

Merged
merged 8 commits into from
Jul 11, 2019

Conversation

jbrockmendel
Copy link
Member

Broken off from #27311 for cleaner scope and to troubleshoot platform-specific failures. Related but orthogonal to #27323.

@jreback jreback added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Jul 11, 2019
expected = type(array)._from_sequence([pd.NaT, array[1], array[2]])

casting_nats = {
TimedeltaArray: [pd.NaT, np.timedelta64("NaT", "ns")],
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 too complicated, just provide the expected alongside the values above

DatetimeArray: [pd.NaT, np.datetime64("NaT", "ns")],
PeriodArray: [pd.NaT],
}[type(array)]
non_casting_nats = {
Copy link
Contributor

Choose a reason for hiding this comment

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

this would be better to parameterize over the non_casting_nats and the casting_nats in a separate test. too much going on here.

Copy link
Member Author

Choose a reason for hiding this comment

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

changed

@@ -651,3 +651,38 @@ def test_array_interface(self, period_index):
result = np.asarray(arr, dtype="S20")
expected = np.asarray(arr).astype("S20")
tm.assert_numpy_array_equal(result, expected)

Copy link
Contributor

Choose a reason for hiding this comment

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

are there other setitem tests? put near those

],
ids=lambda x: type(x).__name__,
)
def test_nat_assignment_array(array):
Copy link
Contributor

Choose a reason for hiding this comment

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

assignment -> setitem

Copy link
Member Author

Choose a reason for hiding this comment

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

changed

@jbrockmendel
Copy link
Member Author

comments addressed i think

def test_casting_nat_setitem_array(array, casting_nats):
expected = type(array)._from_sequence([pd.NaT, array[1], array[2]])

for nat in casting_nats:
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 make another level of parameterization to make these truly separate tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so; the casting_nats parameter depends on the array parameter.

I've been looking at pytest extensions that might make this kind of thing possible

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

small comment, but followup ok

@@ -559,3 +559,27 @@ def remove_na_arraylike(arr):
return arr[notna(arr)]
else:
return arr[notna(lib.values_from_object(arr))]


def is_valid_nat_for_dtype(obj, dtype):
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 type these(followup ok)

@jreback jreback added this to the 0.25.0 milestone Jul 11, 2019
@jreback jreback added Period Period data type Timedelta Timedelta data type Datetime Datetime data dtype labels Jul 11, 2019
@jreback jreback merged commit 76cca0e into pandas-dev:master Jul 11, 2019
@jbrockmendel jbrockmendel deleted the wrong_nat3 branch July 11, 2019 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Period Period data type Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants