@@ -75,16 +75,21 @@ def guess_carried_scalar_type(col):
7575 :param col: column or scalar to inspect
7676 :return: type of first non-None entry, if any , else type(None)
7777 """
78+ # check for scalars first
7879 ct = map_type_to_canonical (type (col ))
7980 if ct in {str , int , float , bool , type (None ), numpy .int64 , numpy .float64 ,
8081 datetime .datetime , datetime .date , datetime .timedelta }:
8182 return ct
83+ # look at a list or Series
84+ if isinstance (col , data_algebra .default_data_model .pd .core .series .Series ):
85+ col = col .values
8286 if len (col ) < 1 :
8387 return type (None )
84- idx = col .notna ().idxmax ()
85- if idx is None :
86- return map_type_to_canonical (type (col [0 ]))
87- return map_type_to_canonical (type (col [idx ]))
88+ good_idx = numpy .where (numpy .logical_not (data_algebra .default_data_model .pd .isna (col )))[0 ]
89+ test_idx = 0
90+ if len (good_idx ) > 0 :
91+ test_idx = good_idx [0 ]
92+ return map_type_to_canonical (type (col [test_idx ]))
8893
8994
9095def guess_column_types (d , * , columns = None ):
@@ -106,7 +111,7 @@ def guess_column_types(d, *, columns=None):
106111 res = dict ()
107112 for c in columns :
108113 gt = guess_carried_scalar_type (d [c ])
109- if (gt is None ) or (not isinstance (gt , type )) or str ( gt ). endswith ( '. Series\' >' ) :
114+ if (gt is None ) or (not isinstance (gt , type )) or gt == data_algebra . default_data_model . pd . core . series . Series :
110115 # pandas.concat() poisons types with Series, don't allow that
111116 return dict ()
112117 res [c ] = gt
0 commit comments