Skip to content

Commit

Permalink
Fixing review comments #1
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlov-alexey committed Jan 18, 2021
1 parent ee1e523 commit 5977aa2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
13 changes: 8 additions & 5 deletions sdc/extensions/indexes/int64_index_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@

from sdc.datatypes.range_index_type import RangeIndexType
from sdc.datatypes.int64_index_type import Int64IndexType
from sdc.datatypes.common_functions import SDCLimitation, _sdc_take
from sdc.utilities.utils import sdc_overload, sdc_overload_attribute, sdc_overload_method
from sdc.utilities.sdc_typing_utils import TypeChecker, check_is_numeric_array, check_signed_integer
from sdc.functions.numpy_like import getitem_by_mask
from sdc.functions.numpy_like import astype as nplike_astype
from sdc.functions import numpy_like
from numba.core.boxing import box_array, unbox_array
from sdc.hiframes.api import fix_df_index
from sdc.extensions.indexes.indexes_generic import _check_dtype_param_type
Expand Down Expand Up @@ -128,7 +126,7 @@ def pd_int64_index_ctor_impl(data, dtype=None, copy=False, name=None):
_data = fix_df_index(data)._data

if data_dtype_is_int64 == False: # noqa
_data = nplike_astype(_data, dtype=types.int64)
_data = numpy_like.astype(_data, dtype=types.int64)
else:
if copy:
_data = np.copy(_data)
Expand Down Expand Up @@ -291,7 +289,8 @@ def pd_int64_index_copy_overload(self, name=None, deep=False, dtype=None):
def pd_int64_index_copy_impl(self, name=None, deep=False, dtype=None):

_name = self._name if keep_name == True else name # noqa
return init_int64_index(self._data, _name)
new_index_data = self._data if not deep else numpy_like.copy(self._data)
return init_int64_index(new_index_data, _name)

return pd_int64_index_copy_impl

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

def pd_int64_index_ravel_impl(self, order='C'):
# np.ravel argument order is not supported in Numba
if order != 'C':
raise ValueError(f"Unsupported value for argument 'order' (only default 'C' is supported)")

return self.values

return pd_int64_index_ravel_impl
5 changes: 4 additions & 1 deletion sdc/extensions/indexes/range_index_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,14 @@ def pd_range_index_ravel_overload(self, order='C'):

_func_name = 'Method ravel().'

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

def pd_range_index_ravel_impl(self, order='C'):
# np.ravel argument order is not supported in Numba
if order != 'C':
raise ValueError(f"Unsupported value for argument 'order' (only default 'C' is supported)")

return self.values

return pd_range_index_ravel_impl
31 changes: 31 additions & 0 deletions sdc/tests/indexes/test_int64_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,37 @@ def test_impl(index, value):
result_ref = test_impl(index, value)
np.testing.assert_array_equal(result, result_ref)

def test_int64_index_copy(self):
def test_impl(index, new_name):
return index.copy(name=new_name)
sdc_func = self.jit(test_impl)

for data in _generate_valid_int64_index_data():
for name, new_name in product(test_global_index_names, repeat=2):
index = pd.Int64Index(data, name=name)
with self.subTest(index=index, new_name=new_name):
result = sdc_func(index, new_name)
result_ref = test_impl(index, new_name)
pd.testing.assert_index_equal(result, result_ref)

def test_int64_index_copy_param_deep(self):
def test_impl(index, deep):
return index.copy(deep=deep)
sdc_func = self.jit(test_impl)

index = pd.Int64Index([1, 11, 2])
for deep in [True, False]:
with self.subTest(deep=deep):
result = sdc_func(index, deep)
result_ref = test_impl(index, deep)
pd.testing.assert_index_equal(result, result_ref)
# pandas uses ndarray views when copies index, so for python
# case check that data arrays share the same memory
self.assertEqual(
result._data is index._data,
result_ref._data.base is index._data
)

def test_int64_index_getitem_scalar(self):
def test_impl(index, idx):
return index[idx]
Expand Down

0 comments on commit 5977aa2

Please sign in to comment.