def resolve_type(self, ary): # Wrap the numeric type in NumberClass return types.NumberClass(ary.dtype)
def register_number_classes(register_global): nb_types = set(types.number_domain) nb_types.add(types.bool_) for ty in nb_types: register_global(ty, types.NumberClass(ty))
def pd_range_index_overload(start=None, stop=None, step=None, dtype=None, copy=False, name=None, fastpath=None): _func_name = 'pd.RangeIndex().' ty_checker = TypeChecker(_func_name) if not (isinstance(copy, types.Omitted) or copy is False): raise SDCLimitation( f"{_func_name} Unsupported parameter. Given 'copy': {copy}") if not (isinstance(copy, types.Omitted) or fastpath is None): raise SDCLimitation( f"{_func_name} Unsupported parameter. Given 'fastpath': {fastpath}" ) dtype_is_np_int64 = dtype is types.NumberClass(types.int64) dtype_is_unicode_str = isinstance(dtype, (types.UnicodeType, types.StringLiteral)) if not _check_dtype_param_type(dtype): ty_checker.raise_exc(dtype, 'int64 dtype', 'dtype') # TODO: support ensure_python_int from pandas.core.dtype.common to handle integers as float params if not (isinstance(start, (types.NoneType, types.Omitted, types.Integer)) or start is None): ty_checker.raise_exc(start, 'number or none', 'start') if not (isinstance(stop, (types.NoneType, types.Omitted, types.Integer)) or stop is None): ty_checker.raise_exc(stop, 'number or none', 'stop') if not (isinstance(step, (types.NoneType, types.Omitted, types.Integer)) or step is None): ty_checker.raise_exc(step, 'number or none', 'step') if not (isinstance(name, (types.NoneType, types.Omitted, types.StringLiteral, types.UnicodeType)) or name is None): ty_checker.raise_exc(name, 'string or none', 'name') if ((isinstance(start, (types.NoneType, types.Omitted)) or start is None) and (isinstance(stop, (types.NoneType, types.Omitted)) or stop is None) and (isinstance(step, (types.NoneType, types.Omitted)) or step is None)): def pd_range_index_ctor_dummy_impl(start=None, stop=None, step=None, dtype=None, copy=False, name=None, fastpath=None): raise TypeError("RangeIndex(...) must be called with integers") return pd_range_index_ctor_dummy_impl def pd_range_index_ctor_impl(start=None, stop=None, step=None, dtype=None, copy=False, name=None, fastpath=None): if not (dtype is None or dtype_is_unicode_str and dtype == 'int64' or dtype_is_np_int64): raise TypeError("Invalid to pass a non-int64 dtype to RangeIndex") _start = types.int64(start) if start is not None else types.int64(0) if stop is None: _start, _stop = types.int64(0), types.int64(start) else: _stop = types.int64(stop) _step = types.int64(step) if step is not None else types.int64(1) if _step == 0: raise ValueError("Step must not be zero") return init_range_index(range(_start, _stop, _step), name) return pd_range_index_ctor_impl
def resolve___class__(self, ty): return types.NumberClass(ty)
def test_dtype_values(self): self.assertEqual(typeof(np.int64), types.NumberClass(types.int64)) self.assertEqual(typeof(np.float64), types.NumberClass(types.float64)) self.assertEqual(typeof(np.int32), types.NumberClass(types.int32)) self.assertEqual(typeof(np.int8), types.NumberClass(types.int8))