Skip to content

TST: Test Series' settitem with Interval and NaN #43844

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 4 commits into from
Oct 5, 2021

Conversation

ElDeveloper
Copy link
Contributor

Fixes #27937. As described in that issue, assigning a mixture of NaN and
Interval values into a slice of a categorical-typed series would raise
an exception. This is no longer the case.

@jreback jreback added this to the 1.4 milestone Oct 1, 2021
@jreback jreback added Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Testing pandas testing functions or related to the test suite labels Oct 1, 2021
@@ -931,6 +931,14 @@ def test_iloc_setitem_td64_values_cast_na(self, value):
expected = Series([NaT, 1, 2], dtype="timedelta64[ns]")
tm.assert_series_equal(series, expected)

def test_setitem_mix_of_nan_and_interval(self):
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 parameterize on all the cases in the OP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I parametrized the NA and the non-NA value, let me know if I should add more cases.

Fixes pandas-dev#27937. As described in that issue, assigning a mixture of NaN and
Interval values into a slice of a categorical-typed series would raise
an exception.  This is no longer the case.
@@ -931,6 +931,16 @@ def test_iloc_setitem_td64_values_cast_na(self, value):
expected = Series([NaT, 1, 2], dtype="timedelta64[ns]")
tm.assert_series_equal(series, expected)

@pytest.mark.parametrize("not_na", [Interval(0, 1), "a", 1.0])
@pytest.mark.parametrize("na", [np.nan, NaT])
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 use nulls_fixture

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very cool, yes. Fixed.

@jreback jreback merged commit 4e8b77d into pandas-dev:master Oct 5, 2021
@jreback
Copy link
Contributor

jreback commented Oct 5, 2021

thanks @ElDeveloper very nice!

@ElDeveloper
Copy link
Contributor Author

Thanks so much for your feedback!

gasparitiago pushed a commit to gasparitiago/pandas that referenced this pull request Oct 9, 2021
rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request Oct 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ValueError on assigning multiple NaN/None to Categorial Series when all categories are Intervals
2 participants