Skip to content
Closed
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions pandas/tests/indexes/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pandas.errors import InvalidIndexError

from pandas import (
DataFrame,
DatetimeIndex,
Float64Index,
Index,
Expand Down Expand Up @@ -248,6 +249,20 @@ def test_putmask_with_wrong_mask(self, index):
index.putmask("foo", fill)


class TestCasting:
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.

This test is better suited in pandas/tests/indexes/base_class/test_where.py

Copy link
Author

Choose a reason for hiding this comment

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

The main issue was the casting so I was not sure, I could move it anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, Generally we group tests by the method calls on the particular objects (Index.where)

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

cond = frame.index.notna()
other = "a" + frame.reset_index().index.astype(str)

fixed_index = frame.index.where(cond, other)

assert (other == Index(["a0", "a1"])).all()
assert (fixed_index == Index([1.0, "a1"])).all()


@pytest.mark.parametrize(
"idx", [Index([1, 2, 3]), Index([0.1, 0.2, 0.3]), Index(["a", "b", "c"])]
)
Expand Down