Skip to content

Commit 5d23a26

Browse files
CLN: Fix issues reported by pre-commit hooks
1 parent e799d33 commit 5d23a26

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

pandas/tests/reshape/test_pivot.py

+16-18
Original file line numberDiff line numberDiff line change
@@ -2856,9 +2856,14 @@ def test_pivot_margins_with_none_index(self):
28562856
def test_pivot_with_pyarrow_categorical(self):
28572857
# GH#53051
28582858

2859-
# Create dataframe with categorical colum
2859+
pytest.importorskip("pyarrow")
2860+
2861+
# Create dataframe with categorical column
28602862
df = (
2861-
pd.DataFrame([("A", 1), ("B", 2), ("C", 3)], columns=["string_column", "number_column"])
2863+
DataFrame(
2864+
[("A", 1), ("B", 2), ("C", 3)],
2865+
columns=["string_column", "number_column"],
2866+
)
28622867
.astype({"string_column": "string", "number_column": "float32"})
28632868
.astype({"string_column": "category", "number_column": "float32"})
28642869
)
@@ -2869,25 +2874,18 @@ def test_pivot_with_pyarrow_categorical(self):
28692874
buffer.seek(0) # Reset buffer position
28702875
df = pd.read_parquet(buffer, dtype_backend="pyarrow")
28712876

2872-
28732877
# Check that pivot works
28742878
df = df.pivot(columns=["string_column"], values=["number_column"])
28752879

28762880
# Assert that values of result are correct to prevent silent failure
2877-
multi_index = pd.MultiIndex.from_arrays(
2878-
[
2879-
["number_column", "number_column", "number_column"],
2880-
["A", "B", "C"]
2881-
],
2882-
names=(None, "string_column")
2881+
multi_index = MultiIndex.from_arrays(
2882+
[["number_column", "number_column", "number_column"], ["A", "B", "C"]],
2883+
names=(None, "string_column"),
28832884
)
2884-
df_expected = pd.DataFrame(
2885-
[
2886-
[1.0, np.nan, np.nan],
2887-
[np.nan, 2.0, np.nan],
2888-
[np.nan, np.nan, 3.0]
2889-
],
2890-
columns=multi_index
2885+
df_expected = DataFrame(
2886+
[[1.0, np.nan, np.nan], [np.nan, 2.0, np.nan], [np.nan, np.nan, 3.0]],
2887+
columns=multi_index,
2888+
)
2889+
tm.assert_frame_equal(
2890+
df, df_expected, check_dtype=False, check_column_type=False
28912891
)
2892-
tm.assert_frame_equal(df, df_expected, check_dtype=False, check_column_type=False)
2893-

pandas/tests/test_multilevel.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,14 @@ def test_multiindex_dt_with_nan(self):
322322
def test_multiindex_with_pyarrow_categorical(self):
323323
# GH#53051
324324

325-
# Create dataframe with categorical colum
325+
pytest.importorskip("pyarrow")
326+
327+
# Create dataframe with categorical column
326328
df = (
327-
pd.DataFrame([("A", 1), ("B", 2), ("C", 3)], columns=["string_column", "number_column"])
329+
DataFrame(
330+
[["A", 1], ["B", 2], ["C", 3]],
331+
columns=["string_column", "number_column"],
332+
)
328333
.astype({"string_column": "string", "number_column": "float32"})
329334
.astype({"string_column": "category", "number_column": "float32"})
330335
)
@@ -335,7 +340,6 @@ def test_multiindex_with_pyarrow_categorical(self):
335340
buffer.seek(0) # Reset buffer position
336341
df = pd.read_parquet(buffer, dtype_backend="pyarrow")
337342

338-
339343
# Check that index can be set
340344
df.set_index(["string_column", "number_column"])
341345

0 commit comments

Comments
 (0)