Skip to content

TST verify return none inplace in tests/indexing #35230

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
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
6 changes: 4 additions & 2 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,10 @@ def test_constructor_single_row(self):
data = [OrderedDict([["a", 1.5], ["b", 3], ["c", 4], ["d", 6]])]

result = DataFrame(data)
expected = DataFrame.from_dict(dict(zip([0], data)), orient="index")
tm.assert_frame_equal(result, expected.reindex(result.index))
expected = DataFrame.from_dict(dict(zip([0], data)), orient="index").reindex(
result.index
)
tm.assert_frame_equal(result, expected)

def test_constructor_ordered_dict_preserve_order(self):
# see gh-13304
Expand Down
9 changes: 6 additions & 3 deletions pandas/tests/indexing/multiindex/test_indexing_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ def validate(mi, df, key):
right = df[mask].copy()

if i + 1 != len(key): # partial key
right.drop(cols[: i + 1], axis=1, inplace=True)
right.set_index(cols[i + 1 : -1], inplace=True)
return_value = right.drop(cols[: i + 1], axis=1, inplace=True)
assert return_value is None
return_value = right.set_index(cols[i + 1 : -1], inplace=True)
assert return_value is None
tm.assert_frame_equal(mi.loc[key[: i + 1]], right)

else: # full key
right.set_index(cols[:-1], inplace=True)
return_value = right.set_index(cols[:-1], inplace=True)
assert return_value is None
if len(right) == 1: # single hit
right = Series(
right["jolia"].values, name=right.index[0], index=["jolia"]
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/indexing/multiindex/test_ix.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def test_loc_general(self):
tm.assert_frame_equal(df.loc[key], df.iloc[2:])

# this is ok
df.sort_index(inplace=True)
return_value = df.sort_index(inplace=True)
assert return_value is None
res = df.loc[key]

# col has float dtype, result should be Float64Index
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/indexing/multiindex/test_sorted.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ def test_frame_getitem_not_sorted2(self, key):
df2 = df.set_index(["col1", "col2"])
df2_original = df2.copy()

df2.index.set_levels(["b", "d", "a"], level="col1", inplace=True)
df2.index.set_codes([0, 1, 0, 2], level="col1", inplace=True)
return_value = df2.index.set_levels(["b", "d", "a"], level="col1", inplace=True)
assert return_value is None
return_value = df2.index.set_codes([0, 1, 0, 2], level="col1", inplace=True)
assert return_value is None
assert not df2.index.is_lexsorted()
assert not df2.index.is_monotonic

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/indexing/multiindex/test_xs.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@ def test_series_getitem_multiindex_xs_by_label():
[("a", "one"), ("a", "two"), ("b", "one"), ("b", "two")]
)
s = Series([1, 2, 3, 4], index=idx)
s.index.set_names(["L1", "L2"], inplace=True)
return_value = s.index.set_names(["L1", "L2"], inplace=True)
assert return_value is None
expected = Series([1, 3], index=["a", "b"])
expected.index.set_names(["L1"], inplace=True)
return_value = expected.index.set_names(["L1"], inplace=True)
assert return_value is None

result = s.xs("one", level="L2")
tm.assert_series_equal(result, expected)
Expand Down