Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing review comments #1
  • Loading branch information
kozlov-alexey committed Jan 27, 2021
commit e3c5022850da56d912517f7981f83185dd8f6100
20 changes: 11 additions & 9 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 @@ -257,13 +255,12 @@ def pd_int64_index_contains_overload(self, val):

def pd_int64_index_contains_impl(self, val):
# TO-DO: add operator.contains support for arrays in Numba
found = 0
for i in prange(len(self._data)):
Comment thread
kozlov-alexey marked this conversation as resolved.
Resolved
if val == self._data[i]:
break
else:
return False
found += 1

return True
return found > 0

return pd_int64_index_contains_impl

Expand Down Expand Up @@ -291,7 +288,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):
Comment thread
kozlov-alexey marked this conversation as resolved.
Resolved

_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 +406,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'):
Comment thread
kozlov-alexey marked this conversation as resolved.
Resolved
# 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
Comment thread
kozlov-alexey marked this conversation as resolved.
Resolved

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