Skip to content

TST: add test for Index.where when needing to cast to object dtype #40888

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pandas/tests/indexes/numeric/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,18 @@ def test_where(self, klass, index):
result = index.where(klass(cond))
tm.assert_index_equal(result, expected)

def test_maybe_cast_with_dtype(self):
Copy link
Member

Choose a reason for hiding this comment

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

can you give this a name of the form test_where_[...] ideally more desc

# https://github.com/pandas-dev/pandas/issues/32413
index = Index([1, np.nan])

cond = index.notna()
other = "a" + Index(range(2)).astype(str)

fixed_index = index.where(cond, other)

tm.assert_index_equal(other, Index(["a0", "a1"]))
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

result =
expected =
tm.assert_index_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.

pls parameterize if you have multiple cases

tm.assert_index_equal(fixed_index, Index([1.0, "a1"]))


class TestTake:
@pytest.mark.parametrize("klass", [Float64Index, Int64Index, UInt64Index])
Expand Down