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

Commit e3c5022

Browse files
committed
Fixing review comments #1
1 parent ee1e523 commit e3c5022

3 files changed

Lines changed: 46 additions & 10 deletions

File tree

‎sdc/extensions/indexes/int64_index_ext.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@
3939

4040
from sdc.datatypes.range_index_type import RangeIndexType
4141
from sdc.datatypes.int64_index_type import Int64IndexType
42-
from sdc.datatypes.common_functions import SDCLimitation, _sdc_take
4342
from sdc.utilities.utils import sdc_overload, sdc_overload_attribute, sdc_overload_method
4443
from sdc.utilities.sdc_typing_utils import TypeChecker, check_is_numeric_array, check_signed_integer
45-
from sdc.functions.numpy_like import getitem_by_mask
46-
from sdc.functions.numpy_like import astype as nplike_astype
44+
from sdc.functions import numpy_like
4745
from numba.core.boxing import box_array, unbox_array
4846
from sdc.hiframes.api import fix_df_index
4947
from sdc.extensions.indexes.indexes_generic import _check_dtype_param_type
@@ -128,7 +126,7 @@ def pd_int64_index_ctor_impl(data, dtype=None, copy=False, name=None):
128126
_data = fix_df_index(data)._data
129127

130128
if data_dtype_is_int64 == False: # noqa
131-
_data = nplike_astype(_data, dtype=types.int64)
129+
_data = numpy_like.astype(_data, dtype=types.int64)
132130
else:
133131
if copy:
134132
_data = np.copy(_data)
@@ -257,13 +255,12 @@ def pd_int64_index_contains_overload(self, val):
257255

258256
def pd_int64_index_contains_impl(self, val):
259257
# TO-DO: add operator.contains support for arrays in Numba
258+
found = 0
260259
for i in prange(len(self._data)):
261260
if val == self._data[i]:
262-
break
263-
else:
264-
return False
261+
found += 1
265262

266-
return True
263+
return found > 0
267264

268265
return pd_int64_index_contains_impl
269266

@@ -291,7 +288,8 @@ def pd_int64_index_copy_overload(self, name=None, deep=False, dtype=None):
291288
def pd_int64_index_copy_impl(self, name=None, deep=False, dtype=None):
292289

293290
_name = self._name if keep_name == True else name # noqa
294-
return init_int64_index(self._data, _name)
291+
new_index_data = self._data if not deep else numpy_like.copy(self._data)
292+
return init_int64_index(new_index_data, _name)
295293

296294
return pd_int64_index_copy_impl
297295

@@ -408,6 +406,10 @@ def pd_int64_index_ravel_overload(self, order='C'):
408406
raise TypingError('{} Unsupported parameters. Given order: {}'.format(_func_name, order))
409407

410408
def pd_int64_index_ravel_impl(self, order='C'):
409+
# np.ravel argument order is not supported in Numba
410+
if order != 'C':
411+
raise ValueError(f"Unsupported value for argument 'order' (only default 'C' is supported)")
412+
411413
return self.values
412414

413415
return pd_int64_index_ravel_impl

‎sdc/extensions/indexes/range_index_ext.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,14 @@ def pd_range_index_ravel_overload(self, order='C'):
459459

460460
_func_name = 'Method ravel().'
461461

462-
# np.ravel argument order is not supported in Numba
463462
if not (isinstance(order, (types.Omitted, types.StringLiteral, types.UnicodeType)) or order == 'C'):
464463
raise TypingError('{} Unsupported parameters. Given order: {}'.format(_func_name, order))
465464

466465
def pd_range_index_ravel_impl(self, order='C'):
466+
# np.ravel argument order is not supported in Numba
467+
if order != 'C':
468+
raise ValueError(f"Unsupported value for argument 'order' (only default 'C' is supported)")
469+
467470
return self.values
468471

469472
return pd_range_index_ravel_impl

‎sdc/tests/indexes/test_int64_index.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,37 @@ def test_impl(index, value):
194194
result_ref = test_impl(index, value)
195195
np.testing.assert_array_equal(result, result_ref)
196196

197+
def test_int64_index_copy(self):
198+
def test_impl(index, new_name):
199+
return index.copy(name=new_name)
200+
sdc_func = self.jit(test_impl)
201+
202+
for data in _generate_valid_int64_index_data():
203+
for name, new_name in product(test_global_index_names, repeat=2):
204+
index = pd.Int64Index(data, name=name)
205+
with self.subTest(index=index, new_name=new_name):
206+
result = sdc_func(index, new_name)
207+
result_ref = test_impl(index, new_name)
208+
pd.testing.assert_index_equal(result, result_ref)
209+
210+
def test_int64_index_copy_param_deep(self):
211+
def test_impl(index, deep):
212+
return index.copy(deep=deep)
213+
sdc_func = self.jit(test_impl)
214+
215+
index = pd.Int64Index([1, 11, 2])
216+
for deep in [True, False]:
217+
with self.subTest(deep=deep):
218+
result = sdc_func(index, deep)
219+
result_ref = test_impl(index, deep)
220+
pd.testing.assert_index_equal(result, result_ref)
221+
# pandas uses ndarray views when copies index, so for python
222+
# case check that data arrays share the same memory
223+
self.assertEqual(
224+
result._data is index._data,
225+
result_ref._data.base is index._data
226+
)
227+
197228
def test_int64_index_getitem_scalar(self):
198229
def test_impl(index, idx):
199230
return index[idx]

0 commit comments

Comments
 (0)