Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit df4d8d3

Browse files
Pre-migration to Numba 0.50 (#887)
1 parent f1f40ec commit df4d8d3

File tree

8 files changed

+262
-217
lines changed

8 files changed

+262
-217
lines changed

sdc/datatypes/hpat_pandas_series_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4887,7 +4887,7 @@ def sdc_pandas_series_skew(self, axis=None, skipna=None, level=None, numeric_onl
48874887
.. only:: developer
48884888
Test: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_skew*
48894889
"""
4890-
_func_name = 'Method Series.skew()'
4890+
_func_name = 'Method Series.skew().'
48914891

48924892
ty_checker = TypeChecker(_func_name)
48934893
ty_checker.check(self, SeriesType)

sdc/extensions/indexes/range_index_ext.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def pd_range_index_overload(start=None, stop=None, step=None, dtype=None, copy=F
9797
raise SDCLimitation(f"{_func_name} Unsupported parameter. Given 'fastpath': {fastpath}")
9898

9999
dtype_is_np_int64 = dtype is types.NumberClass(types.int64)
100+
dtype_is_unicode_str = isinstance(dtype, (types.UnicodeType, types.StringLiteral))
100101
if not _check_dtype_param_type(dtype):
101102
ty_checker.raise_exc(dtype, 'int64 dtype', 'dtype')
102103

@@ -119,10 +120,11 @@ def pd_range_index_ctor_dummy_impl(
119120
raise TypeError("RangeIndex(...) must be called with integers")
120121

121122
return pd_range_index_ctor_dummy_impl
123+
122124
def pd_range_index_ctor_impl(start=None, stop=None, step=None, dtype=None, copy=False, name=None, fastpath=None):
123125

124126
if not (dtype is None
125-
or dtype == 'int64'
127+
or dtype_is_unicode_str and dtype == 'int64'
126128
or dtype_is_np_int64):
127129
raise TypeError("Invalid to pass a non-int64 dtype to RangeIndex")
128130

@@ -154,9 +156,9 @@ def box_range_index(typ, val, c):
154156
mod_name = c.context.insert_const_string(c.builder.module, "pandas")
155157
pd_class_obj = c.pyapi.import_module_noblock(mod_name)
156158

157-
range_index = numba.core.cgutils.create_struct_proxy(
159+
range_index = cgutils.create_struct_proxy(
158160
typ)(c.context, c.builder, val)
159-
range_index_data = numba.core.cgutils.create_struct_proxy(
161+
range_index_data = cgutils.create_struct_proxy(
160162
RangeIndexDataType)(c.context, c.builder, range_index.data)
161163

162164
start = c.pyapi.from_native_value(types.int64, range_index_data.start)
@@ -168,6 +170,7 @@ def box_range_index(typ, val, c):
168170
copy = c.pyapi.bool_from_bool(
169171
c.context.get_constant(types.bool_, False)
170172
)
173+
171174
if typ.is_named:
172175
name = c.pyapi.from_native_value(types.unicode_type, range_index.name)
173176
else:
@@ -266,6 +269,7 @@ def pd_range_index_dtype_overload(self):
266269
return None
267270

268271
range_index_dtype = self.dtype
272+
269273
def pd_range_index_dtype_impl(self):
270274
return range_index_dtype
271275

sdc/functions/numpy_like.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def sdc_astype_overload(self, dtype):
124124

125125
if not isinstance(dtype, (types.functions.NumberClass, types.Function, types.Literal)):
126126
def impl(self, dtype):
127-
return astype(self, literally(dtype))
127+
return literally(dtype)
128128

129129
return impl
130130

@@ -900,11 +900,14 @@ def nancumsum_impl(arr, like_pandas=False):
900900
partial_sum = numpy.zeros(len(chunks), dtype=retty)
901901
result = numpy.empty_like(arr)
902902

903+
# below line is only needed since Literal[bool] var cannot be converted to bool
904+
# in a prange due to a bug related to absence of BooleanLiterals in Numba
905+
_like_pandas = True if like_pandas else False
903906
for i in prange(len(chunks)):
904907
chunk = chunks[i]
905908
partial = zero
906909
for j in range(chunk.start, chunk.stop):
907-
if like_pandas:
910+
if _like_pandas:
908911
result[j] = partial + arr[j]
909912
if ~is_nan(arr[j]):
910913
partial = result[j]

sdc/tests/test_indexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from sdc.tests.test_base import TestCase
3535
from sdc.utilities.sdc_typing_utils import kwsparams2list
3636
from sdc.tests.test_series import _make_func_from_text
37-
from numba.errors import TypingError
37+
from numba.core.errors import TypingError
3838

3939

4040
test_global_index_names = [None, 'abc', 'index']

sdc/tests/test_rolling.py

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
from sdc.tests.test_series import gen_frand_array
4242
from sdc.tests.test_utils import (count_array_REPs, count_parfor_REPs,
4343
skip_numba_jit, skip_sdc_jit,
44-
test_global_input_data_float64)
44+
test_global_input_data_float64,
45+
assert_raises_ty_checker)
4546

4647

4748
LONG_TEST = (int(os.environ['SDC_LONG_ROLLING_TEST']) != 0
@@ -480,42 +481,42 @@ def test_impl(obj, window, min_periods, center,
480481
win_type, on, axis, closed).min()
481482

482483
hpat_func = self.jit(test_impl)
483-
msg_tmpl = 'Method rolling(). The object {}\n given: {}\n expected: {}'
484484

485-
with self.assertRaises(TypingError) as raises:
486-
hpat_func(obj, '1', None, False, None, None, 0, None)
487-
msg = msg_tmpl.format('window', 'unicode_type', 'int')
488-
self.assertIn(msg, str(raises.exception))
489-
490-
with self.assertRaises(TypingError) as raises:
491-
hpat_func(obj, 1, '1', False, None, None, 0, None)
492-
msg = msg_tmpl.format('min_periods', 'unicode_type', 'None, int')
493-
self.assertIn(msg, str(raises.exception))
494-
495-
with self.assertRaises(TypingError) as raises:
496-
hpat_func(obj, 1, None, 0, None, None, 0, None)
497-
msg = msg_tmpl.format('center', 'int64', 'bool')
498-
self.assertIn(msg, str(raises.exception))
499-
500-
with self.assertRaises(TypingError) as raises:
501-
hpat_func(obj, 1, None, False, -1, None, 0, None)
502-
msg = msg_tmpl.format('win_type', 'int64', 'str')
503-
self.assertIn(msg, str(raises.exception))
504-
505-
with self.assertRaises(TypingError) as raises:
506-
hpat_func(obj, 1, None, False, None, -1, 0, None)
507-
msg = msg_tmpl.format('on', 'int64', 'str')
508-
self.assertIn(msg, str(raises.exception))
509-
510-
with self.assertRaises(TypingError) as raises:
511-
hpat_func(obj, 1, None, False, None, None, None, None)
512-
msg = msg_tmpl.format('axis', 'none', 'int, str')
513-
self.assertIn(msg, str(raises.exception))
514-
515-
with self.assertRaises(TypingError) as raises:
516-
hpat_func(obj, 1, None, False, None, None, 0, -1)
517-
msg = msg_tmpl.format('closed', 'int64', 'str')
518-
self.assertIn(msg, str(raises.exception))
485+
method_name = 'Method rolling().'
486+
assert_raises_ty_checker(self,
487+
[method_name, 'window', 'unicode_type', 'int'],
488+
hpat_func,
489+
obj, '1', None, False, None, None, 0, None)
490+
491+
assert_raises_ty_checker(self,
492+
[method_name, 'min_periods', 'unicode_type', 'None, int'],
493+
hpat_func,
494+
obj, 1, '1', False, None, None, 0, None)
495+
496+
assert_raises_ty_checker(self,
497+
[method_name, 'center', 'int64', 'bool'],
498+
hpat_func,
499+
obj, 1, None, 0, None, None, 0, None)
500+
501+
assert_raises_ty_checker(self,
502+
[method_name, 'win_type', 'int64', 'str'],
503+
hpat_func,
504+
obj, 1, None, False, -1, None, 0, None)
505+
506+
assert_raises_ty_checker(self,
507+
[method_name, 'on', 'int64', 'str'],
508+
hpat_func,
509+
obj, 1, None, False, None, -1, 0, None)
510+
511+
assert_raises_ty_checker(self,
512+
[method_name, 'axis', 'none', 'int, str'],
513+
hpat_func,
514+
obj, 1, None, False, None, None, None, None)
515+
516+
assert_raises_ty_checker(self,
517+
[method_name, 'closed', 'int64', 'str'],
518+
hpat_func,
519+
obj, 1, None, False, None, None, 0, -1)
519520

520521
def _test_rolling_apply_mean(self, obj):
521522
def test_impl(obj, window, min_periods):
@@ -548,10 +549,10 @@ def func(x):
548549

549550
hpat_func = self.jit(test_impl)
550551

551-
with self.assertRaises(TypingError) as raises:
552-
hpat_func(obj, 1)
553-
msg = 'Method rolling.apply(). The object raw\n given: int64\n expected: bool'
554-
self.assertIn(msg, str(raises.exception))
552+
assert_raises_ty_checker(self,
553+
['Method rolling.apply().', 'raw', 'int64', 'bool'],
554+
hpat_func,
555+
obj, 1)
555556

556557
def _test_rolling_apply_args(self, obj):
557558
def test_impl(obj, window, min_periods, q):
@@ -610,10 +611,10 @@ def test_impl(obj, pairwise):
610611

611612
hpat_func = self.jit(test_impl)
612613

613-
with self.assertRaises(TypingError) as raises:
614-
hpat_func(obj, 1)
615-
msg = 'Method rolling.corr(). The object pairwise\n given: int64\n expected: bool'
616-
self.assertIn(msg, str(raises.exception))
614+
assert_raises_ty_checker(self,
615+
['Method rolling.corr().', 'pairwise', 'int64', 'bool'],
616+
hpat_func,
617+
obj, 1)
617618

618619
def _test_rolling_count(self, obj):
619620
def test_impl(obj, window, min_periods):
@@ -666,17 +667,16 @@ def test_impl(obj, pairwise, ddof):
666667

667668
hpat_func = self.jit(test_impl)
668669

669-
msg_tmpl = 'Method rolling.cov(). The object {}\n given: {}\n expected: {}'
670+
method_name = 'Method rolling.cov().'
671+
assert_raises_ty_checker(self,
672+
[method_name, 'pairwise', 'int64', 'bool'],
673+
hpat_func,
674+
obj, 1, 1)
670675

671-
with self.assertRaises(TypingError) as raises:
672-
hpat_func(obj, 1, 1)
673-
msg = msg_tmpl.format('pairwise', 'int64', 'bool')
674-
self.assertIn(msg, str(raises.exception))
675-
676-
with self.assertRaises(TypingError) as raises:
677-
hpat_func(obj, None, '1')
678-
msg = msg_tmpl.format('ddof', 'unicode_type', 'int')
679-
self.assertIn(msg, str(raises.exception))
676+
assert_raises_ty_checker(self,
677+
[method_name, 'ddof', 'unicode_type', 'int'],
678+
hpat_func,
679+
obj, None, '1')
680680

681681
def _test_rolling_kurt(self, obj):
682682
def test_impl(obj, window, min_periods):
@@ -777,17 +777,16 @@ def test_impl(obj, quantile, interpolation):
777777

778778
hpat_func = self.jit(test_impl)
779779

780-
msg_tmpl = 'Method rolling.quantile(). The object {}\n given: {}\n expected: {}'
780+
method_name = 'Method rolling.quantile().'
781+
assert_raises_ty_checker(self,
782+
[method_name, 'quantile', 'unicode_type', 'float'],
783+
hpat_func,
784+
obj, '0.5', 'linear')
781785

782-
with self.assertRaises(TypingError) as raises:
783-
hpat_func(obj, '0.5', 'linear')
784-
msg = msg_tmpl.format('quantile', 'unicode_type', 'float')
785-
self.assertIn(msg, str(raises.exception))
786-
787-
with self.assertRaises(TypingError) as raises:
788-
hpat_func(obj, 0.5, None)
789-
msg = msg_tmpl.format('interpolation', 'none', 'str')
790-
self.assertIn(msg, str(raises.exception))
786+
assert_raises_ty_checker(self,
787+
[method_name, 'interpolation', 'none', 'str'],
788+
hpat_func,
789+
obj, 0.5, None)
791790

792791
def _test_rolling_quantile_exception_unsupported_values(self, obj):
793792
def test_impl(obj, quantile, interpolation):
@@ -836,10 +835,10 @@ def _test_rolling_std_exception_unsupported_ddof(self, obj):
836835
hpat_func = self.jit(test_impl)
837836

838837
window, min_periods, invalid_ddof = 3, 2, '1'
839-
with self.assertRaises(TypingError) as raises:
840-
hpat_func(obj, window, min_periods, invalid_ddof)
841-
msg = 'Method rolling.std(). The object ddof\n given: unicode_type\n expected: int'
842-
self.assertIn(msg, str(raises.exception))
838+
assert_raises_ty_checker(self,
839+
['Method rolling.std().', 'ddof', 'unicode_type', 'int'],
840+
hpat_func,
841+
obj, window, min_periods, invalid_ddof)
843842

844843
def _test_rolling_sum(self, obj):
845844
def test_impl(obj, window, min_periods):
@@ -874,10 +873,10 @@ def _test_rolling_var_exception_unsupported_ddof(self, obj):
874873
hpat_func = self.jit(test_impl)
875874

876875
window, min_periods, invalid_ddof = 3, 2, '1'
877-
with self.assertRaises(TypingError) as raises:
878-
hpat_func(obj, window, min_periods, invalid_ddof)
879-
msg = 'Method rolling.var(). The object ddof\n given: unicode_type\n expected: int'
880-
self.assertIn(msg, str(raises.exception))
876+
assert_raises_ty_checker(self,
877+
['Method rolling.var().', 'ddof', 'unicode_type', 'int'],
878+
hpat_func,
879+
obj, window, min_periods, invalid_ddof)
881880

882881
@skip_sdc_jit('DataFrame.rolling.min() unsupported exceptions')
883882
def test_df_rolling_unsupported_values(self):

0 commit comments

Comments
 (0)