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

Commit 02d56d0

Browse files
authored
Re-implement df.index based on new structure (#853)
1 parent 85f6e15 commit 02d56d0

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

sdc/datatypes/hpat_pandas_dataframe_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def hpat_pandas_dataframe_index(df):
100100
empty_df = not df.columns
101101

102102
def hpat_pandas_df_index_none_impl(df):
103-
df_len = len(df._data[0]) if empty_df == False else 0 # noqa
103+
df_len = len(df._data[0][0]) if empty_df == False else 0 # noqa
104104

105105
return numpy.arange(df_len)
106106

sdc/tests/test_dataframe.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def test_impl(df):
741741
np.testing.assert_array_equal(sdc_func(df), test_impl(df))
742742

743743
@skip_sdc_jit
744-
@dfRefactoringNotImplemented
744+
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
745745
def test_index_attribute(self):
746746
index_to_test = [[1, 2, 3, 4, 5],
747747
[.1, .2, .3, .4, .5],
@@ -757,7 +757,7 @@ def test_index_attribute(self):
757757
self._test_df_index(df)
758758

759759
@skip_sdc_jit
760-
@dfRefactoringNotImplemented
760+
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
761761
def test_index_attribute_empty(self):
762762
n = 5
763763
np.random.seed(0)
@@ -768,11 +768,45 @@ def test_index_attribute_empty(self):
768768
self._test_df_index(df)
769769

770770
@skip_sdc_jit
771-
@dfRefactoringNotImplemented
771+
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
772772
def test_index_attribute_empty_df(self):
773773
df = pd.DataFrame()
774774
self._test_df_index(df)
775775

776+
def test_index_attribute_no_unboxing(self):
777+
def test_impl(n, index):
778+
np.random.seed(0)
779+
df = pd.DataFrame({
780+
'A': np.ones(n),
781+
'B': np.random.ranf(n)
782+
}, index=index)
783+
return df.index
784+
785+
sdc_impl = self.jit(test_impl)
786+
index_to_test = [
787+
[1, 2, 3, 4, 5],
788+
[.1, .2, .3, .4, .5],
789+
['a', 'b', 'c', 'd', 'e']
790+
]
791+
for index in index_to_test:
792+
with self.subTest(index=index):
793+
n = len(index)
794+
jit_result = sdc_impl(n, index)
795+
ref_result = test_impl(n, index)
796+
np.testing.assert_array_equal(jit_result, ref_result)
797+
798+
def test_index_attribute_default_no_unboxing(self):
799+
def test_impl(n):
800+
np.random.seed(0)
801+
df = pd.DataFrame({
802+
'A': np.ones(n),
803+
'B': np.random.ranf(n)
804+
})
805+
return df.index
806+
807+
sdc_impl = self.jit(test_impl)
808+
np.testing.assert_array_equal(sdc_impl(10), test_impl(10))
809+
776810
@skip_sdc_jit
777811
@skip_numba_jit
778812
def test_df_apply(self):

0 commit comments

Comments
 (0)