@@ -46,7 +46,10 @@ def typeof_pd_dataframe(val, c):
4646# register series types for import
4747@typeof_impl .register (pd .Series )
4848def typeof_pd_str_series (val , c ):
49- return SeriesType (_infer_series_dtype (val ))
49+ index_type = _infer_index_type (val .index )
50+ is_named = val .name is not None
51+ return SeriesType (
52+ _infer_series_dtype (val ), index = index_type , is_named = is_named )
5053
5154
5255@typeof_impl .register (pd .Index )
@@ -124,7 +127,6 @@ def _infer_series_dtype(S):
124127 raise ValueError ("data type for column {} not supported" .format (S .name ))
125128
126129
127-
128130def _infer_series_list_dtype (S ):
129131 for i in range (len (S )):
130132 first_val = S .iloc [i ]
@@ -142,6 +144,15 @@ def _infer_series_list_dtype(S):
142144 "data type for column {} not supported" .format (S .name ))
143145
144146
147+ def _infer_index_type (index ):
148+ # TODO: support proper inference
149+ if index .dtype == np .dtype ('O' ) and len (index ) > 0 :
150+ first_val = index [0 ]
151+ if isinstance (first_val , str ):
152+ return string_array_type
153+ return types .none
154+
155+
145156@box (DataFrameType )
146157def box_dataframe (typ , val , c ):
147158 context = c .context
@@ -251,6 +262,14 @@ def unbox_series(typ, val, c):
251262 arr_obj = c .pyapi .object_getattr_string (val , "values" )
252263 series = cgutils .create_struct_proxy (typ )(c .context , c .builder )
253264 series .data = _unbox_series_data (typ .dtype , typ .data , arr_obj , c ).value
265+ # TODO: other indices
266+ if typ .index == string_array_type :
267+ index_obj = c .pyapi .object_getattr_string (val , "index" )
268+ series .index = unbox_str_series (string_array_type , index_obj , c ).value
269+ if typ .is_named :
270+ name_obj = c .pyapi .object_getattr_string (val , "name" )
271+ series .name = numba .unicode .unbox_unicode_str (
272+ string_type , name_obj , c ).value
254273 # TODO: handle index and name
255274 c .pyapi .decref (arr_obj )
256275 return NativeValue (series ._getvalue ())
0 commit comments