def resolve_split(self, ary, args, kws): out = SeriesType(types.List(string_type)) if (len(args) == 1 and isinstance(args[0], types.StringLiteral) and len(args[0].literal_value) == 1): out = SeriesType(types.List(string_type), string_array_split_view_type) return signature(out, *args)
def arr_to_series_type(arr): series_type = None if isinstance(arr, types.Array): series_type = SeriesType(arr.dtype, arr) elif arr == string_array_type: # StringArray is readonly series_type = SeriesType(string_type) elif arr == list_string_array_type: series_type = SeriesType(types.List(string_type)) return series_type
def generic(self, args, kws): from sdc.str_arr_ext import is_str_arr_typ assert not kws [va, vb] = args # if one of the inputs is string array if is_str_series_typ(va) or is_str_series_typ(vb): # inputs should be either string array or string assert is_str_arr_typ(va) or va == string_type assert is_str_arr_typ(vb) or vb == string_type return signature(SeriesType(types.boolean), va, vb) if ((is_dt64_series_typ(va) and vb == string_type) or (is_dt64_series_typ(vb) and va == string_type)): return signature(SeriesType(types.boolean), va, vb)
def _resolve_map_func(self, ary, args, kws): dtype = ary.dtype # getitem returns Timestamp for dt_index and series(dt64) if dtype == types.NPDatetime('ns'): dtype = pandas_timestamp_type t = args[0].get_call_type(self.context, (dtype, ), {}) return signature(SeriesType(t.return_type), *args)
def resolve_sort_values(self, ary, args, kws): # output will have permuted input index out_index = ary.index if out_index == types.none: out_index = types.Array(types.intp, 1, 'C') out = SeriesType(ary.dtype, ary.data, out_index) return signature(out, *args)
def generic_expand_cumulative_series(self, args, kws): # taken from arraydecl.py, replaced Array with Series assert not args assert not kws assert isinstance(self.this, SeriesType) return_type = SeriesType(_expand_integer(self.this.dtype)) return signature(return_type, recvr=self.this)
def _groupby_resolve_impl_func_type(series_dtype, method_name): """ Used for typing result value of functions implementing groupby methods, assuming that these implementation call method of Series. """ ty_series = SeriesType(series_dtype) jitted_func = numba.njit(series_method_to_func[method_name]) return cpu_target.typing_context.resolve_function_type( jitted_func, (ty_series, ), {})
def typer(val1, val2): if is_dt64_series_typ(val1) and val2 == pandas_timestamp_type: return SeriesType(types.NPTimedelta('ns')) from sdc.hiframes.pd_index_ext import DatetimeIndexType if isinstance(val1, DatetimeIndexType) and val2 == pandas_timestamp_type: from sdc.hiframes.pd_index_ext import TimedeltaIndexType return TimedeltaIndexType(False)
def generic_resolve(self, s_str, func_name): if sdc.config.config_pipeline_hpat_default and func_name in str2str_methods: template_key = 'strmethod.' + func_name out_typ = SeriesType(string_type) class MethodTemplate(AbstractTemplate): key = template_key def generic(self, args, kws): return signature(out_typ, *args) return types.BoundFunction(MethodTemplate, s_str) if func_name in str2str_methods_excluded: return raise NotImplementedError( 'Series.str.{} is not supported yet'.format(func_name))
def resolve_value_counts(self, ary, args, kws): # output is int series with original data as index out = SeriesType(types.int64, types.Array(types.int64, 1, 'C'), ary.data) return signature(out, *args)
def rolling_generic(self, args, kws): # output is always float64 return signature(SeriesType(types.float64), *args)
def resolve_corr(self, ary, args, kws): return signature(SeriesType(types.float64), *args)
def resolve_apply(self, ary, args, kws): # result is always float64 (see Pandas window.pyx:roll_generic) return signature(SeriesType(types.float64), *args)
def resolve_date_field(self, ary): return SeriesType(types.int64)
def resolve_date(self, ary): return SeriesType(datetime_date_type) # TODO: name, index
def resolve_contains(self, ary, args, kws): return signature(SeriesType(types.bool_), *args)
def resolve_replace(self, ary, args, kws): return signature(SeriesType(string_type), *args)
def resolve_get(self, ary, args, kws): # XXX only list(list(str)) supported return signature(SeriesType(string_type), *args)
def get_series_type(self, col_idx): col_type = self.data[col_idx] return SeriesType(col_type.dtype, col_type, self.index, is_named=True)