Skip to content

Commit 85c221a

Browse files
BUG: is_dtype_equal(dtype, "string[pyarrow]") raises if pyarrow not installed (#44327)
1 parent c3a8fcd commit 85c221a

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

doc/source/whatsnew/v1.4.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ Conversion
660660

661661
Strings
662662
^^^^^^^
663-
-
663+
- Fixed bug in checking for ``string[pyarrow]`` dtype incorrectly raising an ImportError when pyarrow is not installed (:issue:`44327`)
664664
-
665665

666666
Interval

pandas/core/dtypes/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def is_dtype_equal(source, target) -> bool:
613613
src = get_dtype(source)
614614
if isinstance(src, ExtensionDtype):
615615
return src == target
616-
except (TypeError, AttributeError):
616+
except (TypeError, AttributeError, ImportError):
617617
return False
618618
elif isinstance(source, str):
619619
return is_dtype_equal(target, source)
@@ -622,7 +622,7 @@ def is_dtype_equal(source, target) -> bool:
622622
source = get_dtype(source)
623623
target = get_dtype(target)
624624
return source == target
625-
except (TypeError, AttributeError):
625+
except (TypeError, AttributeError, ImportError):
626626

627627
# invalid comparison
628628
# object == category will hit this

pandas/tests/dtypes/test_common.py

+7
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def test_period_dtype(self, dtype):
116116
"float": np.dtype(np.float64),
117117
"object": np.dtype(object),
118118
"category": com.pandas_dtype("category"),
119+
"string": pd.StringDtype(),
119120
}
120121

121122

@@ -129,6 +130,12 @@ def test_dtype_equal(name1, dtype1, name2, dtype2):
129130
assert not com.is_dtype_equal(dtype1, dtype2)
130131

131132

133+
@pytest.mark.parametrize("name,dtype", list(dtypes.items()), ids=lambda x: str(x))
134+
def test_pyarrow_string_import_error(name, dtype):
135+
# GH-44276
136+
assert not com.is_dtype_equal(dtype, "string[pyarrow]")
137+
138+
132139
@pytest.mark.parametrize(
133140
"dtype1,dtype2",
134141
[

0 commit comments

Comments
 (0)