Skip to content

CLN: clean categorical indexes tests #37721

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 1 commit into from
Nov 9, 2020
Merged
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
25 changes: 2 additions & 23 deletions pandas/tests/indexing/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ def test_loc_scalar(self):
with pytest.raises(TypeError, match=msg):
df.loc["d"] = 10

msg = (
"cannot insert an item into a CategoricalIndex that is not "
"already an existing category"
)
msg = "'fill_value=d' is not present in this Categorical's categories"
with pytest.raises(ValueError, match=msg):
df.loc["d", "A"] = 10
Expand All @@ -74,9 +70,9 @@ def test_loc_scalar(self):

def test_slicing(self):
cat = Series(Categorical([1, 2, 3, 4]))
reversed = cat[::-1]
reverse = cat[::-1]
exp = np.array([4, 3, 2, 1], dtype=np.int64)
tm.assert_numpy_array_equal(reversed.__array__(), exp)
tm.assert_numpy_array_equal(reverse.__array__(), exp)

df = DataFrame({"value": (np.arange(100) + 1).astype("int64")})
df["D"] = pd.cut(df.value, bins=[0, 25, 50, 75, 100])
Expand Down Expand Up @@ -170,23 +166,6 @@ def test_slicing_and_getting_ops(self):
res_val = df.loc["j", "cats"]
assert res_val == exp_val

# ix
# frame
# res_df = df.loc["j":"k",[0,1]] # doesn't work?
res_df = df.loc["j":"k", :]
tm.assert_frame_equal(res_df, exp_df)
assert is_categorical_dtype(res_df["cats"].dtype)

# row
res_row = df.loc["j", :]
tm.assert_series_equal(res_row, exp_row)
assert isinstance(res_row["cats"], str)

# col
res_col = df.loc[:, "cats"]
tm.assert_series_equal(res_col, exp_col)
assert is_categorical_dtype(res_col.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

most likely these should be re-purposed as tests for loc

Copy link
Member Author

Choose a reason for hiding this comment

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

We have the exact same tests a few lines above, would not have deleted them otherwise (line 149:167)

Copy link
Member Author

Choose a reason for hiding this comment

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

Was duplicated code

Copy link
Member

Choose a reason for hiding this comment

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

thanks for double-checking


# single value
res_val = df.loc["j", df.columns[0]]
assert res_val == exp_val
Expand Down