Skip to content

Commit 02cb76e

Browse files
committed
shorten object selector tests using dtypes comparison
1 parent 192027f commit 02cb76e

1 file changed

Lines changed: 2 additions & 25 deletions

File tree

skrub/selectors/tests/test_selectors.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,7 @@ def test_dtype_selectors(df_module):
8080
# pandas doesn't have a 'date' dtype, only datetime
8181
assert df_module.name == "pandas"
8282
assert s.any_date().expand(df) == ["datetime-col"]
83-
object_cols = s.object().expand(df)
84-
# `date-col` holds Python `datetime.date` instances and always falls
85-
# back to `object`.
86-
assert "date-col" in object_cols
87-
assert "int-col" not in object_cols
88-
assert "float-col" not in object_cols
89-
assert "cat-col" not in object_cols
90-
if df_module.description == "pandas-numpy-dtypes":
91-
assert "bool-col" in object_cols
92-
pandas_major = int(pd.__version__.split(".")[0])
93-
if pandas_major < 3:
94-
assert "str-col" in object_cols
95-
else:
96-
assert "str-col" not in object_cols
97-
else:
98-
assert "bool-col" not in object_cols
99-
assert "str-col" not in object_cols
83+
assert s.object().expand(df) == df.dtypes[df.dtypes == object].index.tolist()
10084

10185

10286
def test_has_dtype(df_module):
@@ -123,14 +107,7 @@ def test_dtype_pandas_object():
123107
df = pd.DataFrame({"string-object": ["foo", "bar"], "object-object": ["baz", 42]})
124108

125109
assert s.string().expand(df) == ["string-object"]
126-
object_cols = s.object().expand(df)
127-
assert "object-object" in object_cols
128-
# The all-string column only carries the `object` dtype on pandas < 3.0.
129-
pandas_major = int(pd.__version__.split(".")[0])
130-
if pandas_major < 3:
131-
assert "string-object" in object_cols
132-
else:
133-
assert "string-object" not in object_cols
110+
assert s.object().expand(df) == df.dtypes[df.dtypes == object].index.tolist()
134111

135112

136113
def test_object_selector_pandas_string_extension():

0 commit comments

Comments
 (0)