used `pytest.mark.skipif` to skip the testUsed `pytest.mark.skipif` to skip instead of try .. extept TypeError
@@ -108,8 +108,12 @@ def test_sanitize_dataframe_infs():
assert list(df_clean['x']) == [0, 1, 2, None, None, None]
+@pytest.mark.skipif(
+ not hasattr(pd, "Int64Dtype"),
+ reason="Nullable integers not supported in pandas v{}".format(pd.__version__)
+ )
def test_sanitize_nullable_integers():
- try:
+
df = pd.DataFrame(
{
"int_np": [1, 2, 3, 4, 5],
@@ -120,8 +124,6 @@ def test_sanitize_nullable_integers():
"float_inf": [1, 2, None, 4, (float("inf"))],
}
)
- except TypeError: # dtype not supported
- return
df_clean = sanitize_dataframe(df)
assert {col.dtype.name for _, col in df_clean.iteritems()} == {"object"}
@@ -139,8 +141,11 @@ def test_sanitize_nullable_integers():
}
+@pytest.mark.skipif(
+ not hasattr(pd, "StringDtype"),
+ reason="dedicated String dtype not supported in pandas v{}".format(pd.__version__)
+ )
def test_sanitize_string_dtype():
- try:
df = pd.DataFrame(
{
"string_object": ["a", "b", "c", "d"],
@@ -149,8 +154,6 @@ def test_sanitize_string_dtype():
"string_string_null": pd.array(["a", "b", None, "d"], dtype="string"),
}
)
- except TypeError: # dtype not supported
- return
df_clean = sanitize_dataframe(df)
assert {col.dtype.name for _, col in df_clean.iteritems()} == {"object"}
