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 13 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
20 changes: 14 additions & 6 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,13 @@ def test_constructor_list_of_odicts(self):
expected = DataFrame(index=[0])
tm.assert_frame_equal(result, expected)

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))
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could you put the reindex in the expected = ... statement


def test_constructor_ordered_dict_preserve_order(self):
# see gh-13304
expected = DataFrame([[2, 1]], columns=["b", "a"])
Expand Down Expand Up @@ -1493,16 +1500,17 @@ def test_from_dict_columns_parameter(self):
)

@pytest.mark.parametrize(
"data_dict, keys",
"data_dict, keys, orient",
[
([{("a",): 1}, {("a",): 2}], [("a",)]),
([OrderedDict([(("a",), 1), (("b",), 2)])], [("a",), ("b",)]),
([{("a", "b"): 1}], [("a", "b")]),
({}, [], "index"),
([{("a",): 1}, {("a",): 2}], [("a",)], "columns"),
([OrderedDict([(("a",), 1), (("b",), 2)])], [("a",), ("b",)], "columns"),
([{("a", "b"): 1}], [("a", "b")], "columns"),
],
)
def test_constructor_from_dict_tuples(self, data_dict, keys):
def test_constructor_from_dict_tuples(self, data_dict, keys, orient):
# GH 16769
df = DataFrame.from_dict(data_dict)
df = DataFrame.from_dict(data_dict, orient)

result = df.columns
expected = Index(keys, dtype="object", tupleize_cols=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def test_detect_chained_assignment():

msg = "A value is trying to be set on a copy of a slice from a DataFrame"
with pytest.raises(com.SettingWithCopyError, match=msg):
zed["eyes"]["right"].fillna(value=555, inplace=True)
return_value = zed["eyes"]["right"].fillna(value=555, inplace=True)
assert return_value is None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed this one


def test_cache_updating():
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