File tree Expand file tree Collapse file tree 3 files changed +4
-14
lines changed Expand file tree Collapse file tree 3 files changed +4
-14
lines changed Original file line number Diff line number Diff line change @@ -1626,7 +1626,7 @@ def _dtype_to_stata_type(dtype, column):
1626
1626
elif dtype .type == np .object_ : # try to coerce it to the biggest string
1627
1627
# not memory efficient, what else could we
1628
1628
# do?
1629
- itemsize = max_len_string_array (column .values )
1629
+ itemsize = max_len_string_array (com . _ensure_object ( column .values ) )
1630
1630
return chr (max (itemsize , 1 ))
1631
1631
elif dtype == np .float64 :
1632
1632
return chr (255 )
@@ -1664,7 +1664,7 @@ def _dtype_to_default_stata_fmt(dtype, column):
1664
1664
if not (inferred_dtype in ('string' , 'unicode' )
1665
1665
or len (column ) == 0 ):
1666
1666
raise ValueError ('Writing general object arrays is not supported' )
1667
- itemsize = max_len_string_array (column .values )
1667
+ itemsize = max_len_string_array (com . _ensure_object ( column .values ) )
1668
1668
if itemsize > 244 :
1669
1669
raise ValueError (excessive_string_length_error % column .name )
1670
1670
return "%" + str (max (itemsize , 1 )) + "s"
Original file line number Diff line number Diff line change @@ -903,21 +903,11 @@ def clean_index_list(list obj):
903
903
ctypedef fused pandas_t:
904
904
str
905
905
unicode
906
- float32_t
907
- float64_t
908
- uint8_t
909
- uint16_t
910
- uint32_t
911
- uint64_t
912
- int8_t
913
- int16_t
914
- int32_t
915
- int64_t
916
906
917
907
918
908
@ cython.boundscheck (False )
919
909
@ cython.wraparound (False )
920
- def max_len_string_array (pandas_t[:] arr ):
910
+ cpdef Py_ssize_t max_len_string_array(pandas_t[:] arr):
921
911
""" return the maximum size of elements in a 1-dim string array """
922
912
cdef:
923
913
Py_ssize_t i, m = 0 , l = 0 , length = arr.shape[0 ]
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def test_max_len_string_array(self):
16
16
self .assertTrue (max_len_string_array (arr ),3 )
17
17
18
18
# unicode
19
- arr = arr .astype ('U' )
19
+ arr = arr .astype ('U' ). astype ( object )
20
20
self .assertTrue (max_len_string_array (arr ),3 )
21
21
22
22
class TestIsscalar (tm .TestCase ):
You can’t perform that action at this time.
0 commit comments