8000 Fixes pack of failed tests · IntelPython/sdc@4991be3 · GitHub
[go: up one dir, main page]

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

Commit 4991be3

Browse files
committed
Fixes pack of failed tests
1 parent abc9fbb commit 4991be3

File tree

7 files changed

+63
-11
lines changed

7 files changed

+63
-11
lines changed

sdc/datatypes/categorical/functions.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
# *****************************************************************************
2626

27-
from sdc.utilities.utils import sdc_overload_attribute
27+
from sdc.utilities.utils import sdc_overload_attribute, sdc_overload
28+
from numba.extending import intrinsic
29+
from numba import types
2830

29-
from .types import CategoricalDtypeType
31+
from .types import CategoricalDtypeType, Categorical
3032

3133

3234
@sdc_overload_attribute(CategoricalDtypeType, 'ordered')
@@ -36,3 +38,29 @@ def pd_CategoricalDtype_categories_overload(self):
3638
def impl(self):
3739
return ordered
3840
return impl
41+
42+
43+
@intrinsic
44+
def _categorical_len(tyctx, arr_type):
45+
ret_type = types.intp
46+
47+
def codegen(context, builder, sig, args):
48+
arr_val, = args
49+
arr_info = context.make_helper(builder, arr_type, arr_val)
50+
res = builder.load(arr_info._get_ptr_by_name('nitems'))
51+
return res
52+
53+
return ret_type(arr_type), codegen
54+
55+
56+
@sdc_overload(len)
57+
def pd_Categorical_len_overload(self):
58+
if not isinstance(self, Categorical):
59+
return None
60+
61+
# Categorical use ArrayModel and don't expose be_type members
62+
# hence we use intrinsic to access those fields. TO-DO: refactor
63+
def impl(self):
64+
return _categorical_len(self)
65+
66+
return impl

sdc/datatypes/series/boxing.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
# *****************************************************************************
2626

2727
from numba.core.imputils import lower_constant
28-
from numba.core import cgutils
28+
from numba.core import cgutils, types
2929

3030
from .types import SeriesType
31+
from sdc.datatypes.indexes.positional_index_type import PositionalIndexType
32+
from sdc.hiframes.boxing import _unbox_index_data
33+
from sdc.extensions.indexes.range_index_ext import unbox_range_index
34+
from sdc.datatypes.indexes.range_index_type import RangeIndexDataType
3135

3236

3337
@lower_constant(SeriesType)
@@ -39,7 +43,21 @@ def constant_Series(context, builder, ty, pyval):
3943
"""
4044
series = cgutils.create_struct_proxy(ty)(context, builder)
4145
series.data = _constant_Series_data(context, builder, ty, pyval)
42-
# TODO: index and name
46+
47+
# TODO: index and name (this only handles PositionalIndexType(False)
48+
# and repeats unboxing, need to refactor to support all indexes)
49+
native_range_index = cgutils.create_struct_proxy(RangeIndexDataType)(context, builder)
50+
native_range_index.start = context.get_constant(types.int64, pyval.index.start)
51+
native_range_index.stop = context.get_constant(types.int64, pyval.index.stop)
52+
native_range_index.step = context.get_constant(types.int64, pyval.index.step)
53+
54+
range_index = cgutils.create_struct_proxy(ty.index.data)(context, builder)
55+
range_index.data = native_range_index._getvalue()
56+
57+
positional_index = cgutils.create_struct_proxy(PositionalIndexType(False))(context, builder)
58+
positional_index.data = range_index._getvalue()
59+
60+
series.index = positional_index._getvalue()
4361
return series._getvalue()
4462

4563

@@ -52,7 +70,11 @@ def _constant_Series_data(context, builder, ty, pyval):
5270

5371
from ..categorical.types import CategoricalDtypeType
5472

55-
if isinstance(ty.dtype, CategoricalDtypeType):
73+
# TO-DO: this requires lower_constant to be implemented for other types
74+
# like indices and so on, until that raise NotImplementedError
75+
if (isinstance(ty.dtype, CategoricalDtypeType)
76+
and ty.index is PositionalIndexType(False)
77+
and ty.is_named is False):
5678
from ..categorical.boxing import constant_Categorical
5779
return constant_Categorical(context, builder, ty.data, pyval.array)
5880

sdc/tests/categorical/test_df_category.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
from sdc.hiframes.pd_dataframe_type import DataFrameType
4040
from sdc.tests.test_utils import skip_numba_jit
41+
from sdc.datatypes.indexes.positional_index_type import PositionalIndexType
4142

4243

4344
class DFCategoryTest(TestCase):
@@ -54,7 +55,7 @@ def test_typeof(self):
5455

5556
assert(isinstance(nb_type, DataFrameType))
5657
assert(nb_type.columns == ('A',))
57-
assert(nb_type.index == types.none)
58+
assert(nb_type.index == PositionalIndexType(False))
5859
assert(nb_type.data[0].pd_dtype == CategoricalDtypeType(categories=[1, 2, 3], ordered=False))
5960
assert(nb_type.data[0] == Categorical(CategoricalDtypeType(categories=[1, 2, 3], ordered=False)))
6061

sdc/tests/categorical/test_series_category.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from sdc.tests.test_base import TestCase
2828

2929
import pandas as pd
30+
import numpy as np
3031
import numba as nb
3132
from numba import types
3233

@@ -35,6 +36,7 @@
3536
CategoricalDtypeType,
3637
Categorical,
3738
)
39+
from sdc.datatypes.indexes.positional_index_type import PositionalIndexType
3840

3941

4042
class SeriesCategoryTest(TestCase):
@@ -51,7 +53,7 @@ def test_typeof(self):
5153

5254
assert(isinstance(nb_type, SeriesType))
5355
assert(nb_type.dtype == CategoricalDtypeType(categories=[1, 2, 3], ordered=False))
54-
assert(nb_type.index == types.none)
56+
assert(nb_type.index == PositionalIndexType(False))
5557
assert(nb_type.data == Categorical(CategoricalDtypeType(categories=[1, 2, 3], ordered=False)))
5658

5759
def test_unboxing(self):

sdc/tests/indexes/test_int64_index.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,9 @@ def test_impl(index, deep):
230230
result = sdc_func(index, deep)
231231
result_ref = test_impl(index, deep)
232232
pd.testing.assert_index_equal(result, result_ref)
233-
# pandas uses ndarray views when copies index, so for python
234-
# case check that data arrays share the same memory
235233
self.assertEqual(
236234
result._data is index._data,
237-
result_ref._data.base is index._data
235+
result_ref._data is index._data
238236
)
239237

240238
def test_int64_index_getitem_scalar(self):

sdc/tests/test_series_ops.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,6 @@ def test_impl(S1, S2, value):
10621062
result_ref = test_impl(S1, scalar, fill_value)
10631063
pd.testing.assert_series_equal(result, result_ref)
10641064

1065-
@unittest.expectedFailure # Numba issue with 1/0 is different (inf) than in Numpy (nan)
10661065
def test_series_binop_floordiv_numeric(self):
10671066
def test_impl(a, b, value):
10681067
return a.floordiv(b, fill_value=value)

sdc/utilities/sdc_typing_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from sdc.str_arr_type import string_array_type
4141
from sdc.datatypes.indexes import *
4242
from sdc.str_arr_ext import StringArrayType
43+
from sdc.datatypes.categorical.types import Categorical
4344

4445

4546
sdc_old_index_types = (types.Array, StringArrayType, )
@@ -65,6 +66,7 @@
6566
sdc_pandas_df_column_types = (
6667
types.Array,
6768
StringArrayType,
69+
Categorical,
6870
)
6971

7072
class TypeChecker:

0 commit comments

Comments
 (0)
0