@@ -3950,7 +3950,7 @@ def _create_axes(
3950
3950
new_name = name or f"values_block_{ i } "
3951
3951
data_converted = _maybe_convert_for_string_atom (
3952
3952
new_name ,
3953
- blk ,
3953
+ blk . values ,
3954
3954
existing_col = existing_col ,
3955
3955
min_itemsize = min_itemsize ,
3956
3956
nan_rep = nan_rep ,
@@ -4933,19 +4933,20 @@ def _unconvert_index(data, kind: str, encoding: str, errors: str) -> np.ndarray
4933
4933
4934
4934
def _maybe_convert_for_string_atom (
4935
4935
name : str ,
4936
- block : Block ,
4936
+ bvalues : ArrayLike ,
4937
4937
existing_col ,
4938
4938
min_itemsize ,
4939
4939
nan_rep ,
4940
4940
encoding ,
4941
4941
errors ,
4942
4942
columns : list [str ],
4943
4943
):
4944
- bvalues = block .values
4945
4944
4946
4945
if bvalues .dtype != object :
4947
4946
return bvalues
4948
4947
4948
+ bvalues = cast (np .ndarray , bvalues )
4949
+
4949
4950
dtype_name = bvalues .dtype .name
4950
4951
inferred_type = lib .infer_dtype (bvalues , skipna = False )
4951
4952
@@ -4961,13 +4962,9 @@ def _maybe_convert_for_string_atom(
4961
4962
elif not (inferred_type == "string" or dtype_name == "object" ):
4962
4963
return bvalues
4963
4964
4964
- blocks : list [Block ] = block .fillna (nan_rep , downcast = False )
4965
- # Note: because block is always object dtype, fillna goes
4966
- # through a path such that the result is always a 1-element list
4967
- assert len (blocks ) == 1
4968
- block = blocks [0 ]
4969
-
4970
- data = block .values
4965
+ mask = isna (bvalues )
4966
+ data = bvalues .copy ()
4967
+ data [mask ] = nan_rep
4971
4968
4972
4969
# see if we have a valid string type
4973
4970
inferred_type = lib .infer_dtype (data , skipna = False )
@@ -4979,7 +4976,7 @@ def _maybe_convert_for_string_atom(
4979
4976
# expected behaviour:
4980
4977
# search block for a non-string object column by column
4981
4978
for i in range (data .shape [0 ]):
4982
- col = block . iget ( i )
4979
+ col = data [ i ]
4983
4980
inferred_type = lib .infer_dtype (col , skipna = False )
4984
4981
if inferred_type != "string" :
4985
4982
error_column_label = columns [i ] if len (columns ) > i else f"No.{ i } "
@@ -4991,11 +4988,7 @@ def _maybe_convert_for_string_atom(
4991
4988
4992
4989
# itemsize is the maximum length of a string (along any dimension)
4993
4990
4994
- # error: Argument 1 to "_convert_string_array" has incompatible type "Union[ndarray,
4995
- # ExtensionArray]"; expected "ndarray"
4996
- data_converted = _convert_string_array (
4997
- data , encoding , errors # type: ignore[arg-type]
4998
- ).reshape (data .shape )
4991
+ data_converted = _convert_string_array (data , encoding , errors ).reshape (data .shape )
4999
4992
itemsize = data_converted .itemsize
5000
4993
5001
4994
# specified min_itemsize?
0 commit comments