Skip to content

Commit 8b26a7d

Browse files
tests and mypy fixes
1 parent 1c69e29 commit 8b26a7d

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

pandas/core/methods/corr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def transform_ord_cat_cols_to_coded_cols(df: DataFrame) -> DataFrame:
2121
result = df
2222
made_copy = False
2323
for idx, dtype in enumerate(df.dtypes):
24-
if not dtype == "category" or not dtype.ordered:
24+
if not dtype == "category" or not dtype.ordered: # type: ignore[attr-defined]
2525
continue
2626
col = result._ixs(idx, axis=1)
2727
if not made_copy:

pandas/tests/methods/corr.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@
5353
ordered=True,
5454
)
5555
),
56-
"unordered": Series(
57-
Categorical(["x", "y", "x"], ordered=False)
58-
),
56+
"unordered": Series(Categorical(["x", "y", "x"], ordered=False)),
5957
"num": Series([10, 20, 30]),
6058
"text": Series(["u", "v", "w"]),
6159
}
@@ -65,17 +63,16 @@
6563
# codes: a=0, c=2, b=1
6664
"ordered": Series([0, 2, 1], dtype="int8"),
6765
# unordered categorical should be untouched (still categorical)
68-
"unordered": Series(
69-
Categorical(["x", "y", "x"], ordered=False)
70-
),
66+
"unordered": Series(Categorical(["x", "y", "x"], ordered=False)),
7167
"num": Series([10, 20, 30]),
7268
"text": Series(["u", "v", "w"]),
7369
}
7470
),
7571
id="mixed-types-only-ordered-changes",
7672
),
7773
pytest.param(
78-
# 3 Duplicate column names: first 'dup' is ordered categorical, second 'dup' is non-categorical
74+
# 3 Duplicate column names: first 'dup' is ordered categorical,
75+
# second 'dup' is non-categorical
7976
DataFrame(
8077
{
8178
"dup": Series(
@@ -99,7 +96,8 @@
9996
id="duplicate-names-ordered-first",
10097
),
10198
pytest.param(
102-
# 4 Duplicate column names: first 'dup' is non-categorical, second 'dup' is ordered categorical, third 'dup' is ordered categorical
99+
# 4 Duplicate column names: first 'dup' is non-categorical,
100+
# second 'dup' is ordered categorical, third 'dup' is ordered categorical
103101
DataFrame(
104102
{
105103
"dup": Series(["a", "b", "c"]), # non-categorical (object)
@@ -121,7 +119,8 @@
121119
),
122120
DataFrame(
123121
{
124-
# First stays object; second turns into codes [0,1,NaN] and third changes into codes [0, 1, 2] as well
122+
# First stays object; second turns into codes [0, 1, NaN]
123+
# and third changes into codes [0, 1, 2]
125124
"dup": Series(["a", "b", "c"]),
126125
"dup": Series([0.0, 1.0, np.nan]),
127126
"dup": Series([0, 1, 2], dtype="int8"),
@@ -135,4 +134,4 @@ def test_transform_ord_cat_cols_to_coded_cols(input_df, expected_df):
135134
out_df = transform_ord_cat_cols_to_coded_cols(input_df)
136135
assert list(out_df.columns) == list(expected_df.columns)
137136
for i, col in enumerate(out_df.columns):
138-
tm.assert_series_equal(out_df.iloc[:, i], expected_df.iloc[:, i])
137+
tm.assert_series_equal(out_df.iloc[:, i], expected_df.iloc[:, i])

0 commit comments

Comments
 (0)