Skip to content

BUG: in DataFrame.reset_index() only call maybe_upcast_putmask with ndarrays #36876

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 10 commits into from
Oct 11, 2020

Conversation

arw2019
Copy link
Member

@arw2019 arw2019 commented Oct 5, 2020

@jreback jreback added Bug Categorical Categorical Data Type MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Oct 7, 2020
@jreback jreback added this to the 1.2 milestone Oct 7, 2020
@@ -650,6 +650,32 @@ def test_loc_slice(self):
expected = self.df.iloc[[2, 3, 4]]
tm.assert_frame_equal(result, expected)

def test_reindexing_with_missing_values(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 both of the examples from the OP.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -650,6 +650,32 @@ def test_loc_slice(self):
expected = self.df.iloc[[2, 3, 4]]
tm.assert_frame_equal(result, expected)

def test_reindexing_with_missing_values(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

move to pandas/tests/frame/test_alter_axes.py

you can make a new class there if you'd like and put this there

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}
)

tm.assert_frame_equal(res, expected)
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 also round-trip again, e.g. .set_index(['level_0', 'level_1']).reset_index() and compare with expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -650,6 +650,32 @@ def test_loc_slice(self):
expected = self.df.iloc[[2, 3, 4]]
tm.assert_frame_equal(result, expected)

def test_reindexing_with_missing_values(self):
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -650,6 +650,32 @@ def test_loc_slice(self):
expected = self.df.iloc[[2, 3, 4]]
tm.assert_frame_equal(result, expected)

def test_reindexing_with_missing_values(self):
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}
)

tm.assert_frame_equal(res, expected)
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -171,21 +173,6 @@ def test_assign_columns(self, float_frame):
tm.assert_series_equal(float_frame["C"], df["baz"], check_names=False)
tm.assert_series_equal(float_frame["hi"], df["foo2"], check_names=False)

def test_set_index_preserve_categorical_dtype(self):
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 moved this to sit with the only other categorical test (the one I'm adding) in TestCategoricalIndex class

if mask.any():
if isinstance(values, np.ndarray):
values, _ = maybe_upcast_putmask(values, mask, np.nan)
else:
Copy link
Member Author

Choose a reason for hiding this comment

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

@jreback added this since you last looked - we handle nan in maybe_upcast_mask if values is an ndarray else fill with np.nan

@jreback
Copy link
Contributor

jreback commented Oct 10, 2020

can you merge master and ping on green-ish

@arw2019
Copy link
Member Author

arw2019 commented Oct 11, 2020

@jreback Green-ish (the failures are 6 tests from pandas/tests/tools/test_to_datetime.py)

@arw2019
Copy link
Member Author

arw2019 commented Oct 11, 2020

@jreback all green now

@jreback jreback merged commit eb8c654 into pandas-dev:master Oct 11, 2020
@jreback
Copy link
Contributor

jreback commented Oct 11, 2020

thanks @arw2019

@arw2019
Copy link
Member Author

arw2019 commented Oct 11, 2020

Thanks @jreback for reviewing!

@arw2019 arw2019 deleted the GH24206 branch October 11, 2020 20:05
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Oct 26, 2020
…darrays (pandas-dev#36876)

* BUG: add check so maybe_upcast_putmask is only called  with ndarray

* TST: add tests

* DOC: add whatsnew

* feedback: test roundtrip

* feedback: parametrize on both examples from OP

* move test to frame/test_alter_axes.py

* fill mask in index with nan when not calling maybe_upcast_putmask

* restore the fix
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
…darrays (pandas-dev#36876)

* BUG: add check so maybe_upcast_putmask is only called  with ndarray

* TST: add tests

* DOC: add whatsnew

* feedback: test roundtrip

* feedback: parametrize on both examples from OP

* move test to frame/test_alter_axes.py

* fill mask in index with nan when not calling maybe_upcast_putmask

* restore the fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: reset_index of MultiIndex with CategoricalIndex levels with missing values fails
2 participants