File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -2242,7 +2242,7 @@ def construct_from_string(cls, string: str) -> ArrowDtype:
2242
2242
)
2243
2243
if not string .endswith ("[pyarrow]" ):
2244
2244
raise TypeError (f"'{ string } ' must end with '[pyarrow]'" )
2245
- if string == "string[pyarrow]" :
2245
+ if string in ( "string[pyarrow]" , "str[pyarrow]" ) :
2246
2246
# Ensure Registry.find skips ArrowDtype to use StringDtype instead
2247
2247
raise TypeError ("string[pyarrow] should be constructed by StringDtype" )
2248
2248
Original file line number Diff line number Diff line change @@ -835,3 +835,30 @@ def test_pandas_dtype_string_dtypes(string_storage):
835
835
with pd .option_context ("string_storage" , string_storage ):
836
836
result = pandas_dtype ("string" )
837
837
assert result == pd .StringDtype (string_storage , na_value = pd .NA )
838
+
839
+
840
+ def test_pandas_dtype_string_dtype_alias_with_storage ():
841
+ with pytest .raises (TypeError , match = "not understood" ):
842
+ pandas_dtype ("str[python]" )
843
+
844
+ with pytest .raises (TypeError , match = "not understood" ):
845
+ pandas_dtype ("str[pyarrow]" )
846
+
847
+ result = pandas_dtype ("string[python]" )
848
+ assert result == pd .StringDtype ("python" , na_value = pd .NA )
849
+
850
+ if HAS_PYARROW :
851
+ result = pandas_dtype ("string[pyarrow]" )
852
+ assert result == pd .StringDtype ("pyarrow" , na_value = pd .NA )
853
+ else :
854
+ with pytest .raises (
855
+ ImportError , match = "required for PyArrow backed StringArray"
856
+ ):
857
+ pandas_dtype ("string[pyarrow]" )
858
+
859
+
860
+ @td .skip_if_installed ("pyarrow" )
861
+ def test_construct_from_string_without_pyarrow_installed ():
862
+ # GH 57928
863
+ with pytest .raises (ImportError , match = "pyarrow>=10.0.1 is required" ):
864
+ pd .Series ([- 1.5 , 0.2 , None ], dtype = "float32[pyarrow]" )
You can’t perform that action at this time.
0 commit comments