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

Commit 5977aa2

Browse files
committed
Fixing review comments #1
1 parent ee1e523 commit 5977aa2

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

‎sdc/extensions/indexes/int64_index_ext.py‎

Lines changed: 8 additions & 5 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)
@@ -291,7 +289,8 @@ def pd_int64_index_copy_overload(self, name=None, deep=False, dtype=None):
291289
def pd_int64_index_copy_impl(self, name=None, deep=False, dtype=None):
292290

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

296295
return pd_int64_index_copy_impl
297296

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

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

413416
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)