Skip to content

TST: misplaced tests #39598

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 2 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
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
28 changes: 0 additions & 28 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1732,34 +1732,6 @@ def test_setitem(self, uint64_frame):
)


@pytest.mark.parametrize(
"src_idx",
[
Index([]),
pd.CategoricalIndex([]),
],
)
@pytest.mark.parametrize(
"cat_idx",
[
# No duplicates
Index([]),
pd.CategoricalIndex([]),
Index(["A", "B"]),
pd.CategoricalIndex(["A", "B"]),
# Duplicates: GH#38906
Index(["A", "A"]),
pd.CategoricalIndex(["A", "A"]),
],
)
def test_reindex_empty(src_idx, cat_idx):
df = DataFrame(columns=src_idx, index=["K"], dtype="f8")

result = df.reindex(columns=cat_idx)
expected = DataFrame(index=["K"], columns=cat_idx, dtype="f8")
tm.assert_frame_equal(result, expected)


def test_object_casting_indexing_wraps_datetimelike():
# GH#31649, check the indexing methods all the way down the stack
df = DataFrame(
Expand Down
31 changes: 29 additions & 2 deletions pandas/tests/frame/methods/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_reindex_methods_nearest_special(self):
def test_reindex_nearest_tz(self, tz_aware_fixture):
# GH26683
tz = tz_aware_fixture
idx = pd.date_range("2019-01-01", periods=5, tz=tz)
idx = date_range("2019-01-01", periods=5, tz=tz)
df = DataFrame({"x": list(range(5))}, index=idx)

expected = df.head(3)
Expand Down Expand Up @@ -759,7 +759,7 @@ def test_reindex_multi(self):

def test_reindex_multi_categorical_time(self):
# https://github.com/pandas-dev/pandas/issues/21390
midx = pd.MultiIndex.from_product(
midx = MultiIndex.from_product(
[
Categorical(["a", "b", "c"]),
Categorical(date_range("2012-01-01", periods=3, freq="H")),
Expand Down Expand Up @@ -906,3 +906,30 @@ def test_reindex_empty_frame(self, kwargs):
result = df.reindex(idx, **kwargs)
expected = DataFrame({"a": [pd.NA] * 3}, index=idx)
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"src_idx",
[
Index([]),
CategoricalIndex([]),
],
)
@pytest.mark.parametrize(
"cat_idx",
[
# No duplicates
Index([]),
CategoricalIndex([]),
Index(["A", "B"]),
CategoricalIndex(["A", "B"]),
# Duplicates: GH#38906
Index(["A", "A"]),
CategoricalIndex(["A", "A"]),
],
)
def test_reindex_empty(self, src_idx, cat_idx):
df = DataFrame(columns=src_idx, index=["K"], dtype="f8")

result = df.reindex(columns=cat_idx)
expected = DataFrame(index=["K"], columns=cat_idx, dtype="f8")
tm.assert_frame_equal(result, expected)
34 changes: 3 additions & 31 deletions pandas/tests/series/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,29 +607,6 @@ def test_td64_series_assign_nat(nat_val, should_cast):
tm.assert_series_equal(ser, expected)


@pytest.mark.parametrize(
"td",
[
Timedelta("9 days"),
Timedelta("9 days").to_timedelta64(),
Timedelta("9 days").to_pytimedelta(),
],
)
def test_append_timedelta_does_not_cast(td):
# GH#22717 inserting a Timedelta should _not_ cast to int64
expected = Series(["x", td], index=[0, "td"], dtype=object)

ser = Series(["x"])
ser["td"] = td
tm.assert_series_equal(ser, expected)
assert isinstance(ser["td"], Timedelta)

ser = Series(["x"])
ser.loc["td"] = Timedelta("9 days")
tm.assert_series_equal(ser, expected)
assert isinstance(ser["td"], Timedelta)


def test_underlying_data_conversion():
# GH 4080
df = DataFrame({c: [1, 2, 3] for c in ["a", "b", "c"]})
Expand Down Expand Up @@ -759,15 +736,11 @@ def test_getitem_unrecognized_scalar():
timedelta_range("0", periods=20, freq="H"),
],
)
def test_slice_with_zero_step_raises(index):
ts = Series(np.arange(20), index)
def test_slice_with_zero_step_raises(index, frame_or_series, indexer_sli):
ts = frame_or_series(np.arange(20), index=index)

with pytest.raises(ValueError, match="slice step cannot be zero"):
ts[::0]
with pytest.raises(ValueError, match="slice step cannot be zero"):
ts.loc[::0]
with pytest.raises(ValueError, match="slice step cannot be zero"):
ts.iloc[::0]
indexer_sli(ts)[::0]


@pytest.mark.parametrize(
Expand All @@ -784,7 +757,6 @@ def assert_slices_equivalent(l_slc, i_slc):

tm.assert_series_equal(ts[l_slc], expected)
tm.assert_series_equal(ts.loc[l_slc], expected)
tm.assert_series_equal(ts.loc[l_slc], expected)

keystr1 = str(index[9])
keystr2 = str(index[13])
Expand Down
25 changes: 10 additions & 15 deletions pandas/tests/series/indexing/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,24 @@
import pandas._testing as tm


def test_slice_float64():
def test_slice_float64(frame_or_series):
values = np.arange(10.0, 50.0, 2)
index = Index(values)

start, end = values[[5, 15]]

s = Series(np.random.randn(20), index=index)
data = np.random.randn(20, 3)
if frame_or_series is not DataFrame:
data = data[:, 0]

result = s[start:end]
expected = s.iloc[5:16]
tm.assert_series_equal(result, expected)

result = s.loc[start:end]
tm.assert_series_equal(result, expected)

df = DataFrame(np.random.randn(20, 3), index=index)
obj = frame_or_series(data, index=index)

result = df[start:end]
expected = df.iloc[5:16]
tm.assert_frame_equal(result, expected)
result = obj[start:end]
expected = obj.iloc[5:16]
tm.assert_equal(result, expected)

result = df.loc[start:end]
tm.assert_frame_equal(result, expected)
result = obj.loc[start:end]
tm.assert_equal(result, expected)


def test_getitem_setitem_slice_bug():
Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
MultiIndex,
NaT,
Series,
Timedelta,
Timestamp,
date_range,
period_range,
Expand Down Expand Up @@ -508,6 +509,28 @@ def test_setitem_empty_series_timestamp_preserves_dtype(self):
result = series["timestamp"]
assert result == expected

@pytest.mark.parametrize(
"td",
[
Timedelta("9 days"),
Timedelta("9 days").to_timedelta64(),
Timedelta("9 days").to_pytimedelta(),
],
)
def test_append_timedelta_does_not_cast(self, td):
# GH#22717 inserting a Timedelta should _not_ cast to int64
expected = Series(["x", td], index=[0, "td"], dtype=object)

ser = Series(["x"])
ser["td"] = td
tm.assert_series_equal(ser, expected)
assert isinstance(ser["td"], Timedelta)

ser = Series(["x"])
ser.loc["td"] = Timedelta("9 days")
tm.assert_series_equal(ser, expected)
assert isinstance(ser["td"], Timedelta)


def test_setitem_scalar_into_readonly_backing_data():
# GH#14359: test that you cannot mutate a read only buffer
Expand Down