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 all commits
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
Re-implement df._set_column based on new strcture
  • Loading branch information
densmirn committed May 21, 2020
commit 35f870da4fe18f4abe94ffc1f90105c08792fbdc
8 changes: 6 additions & 2 deletions sdc/datatypes/hpat_pandas_dataframe_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2620,9 +2620,11 @@ def df_add_column_codelines(self, key):

results = []
for i, col in enumerate(self.columns):
col_loc = self.column_loc[col]
type_id, col_id = col_loc.type_id, col_loc.col_id
res_data = f'res_data_{i}'
func_lines += [
f' data_{i} = self._data[{i}]',
f' data_{i} = self._data[{type_id}][{col_id}]',
f' {res_data} = pandas.Series(data_{i}, index=res_index, name="{col}")',
]
results.append((col, res_data))
Expand All @@ -2648,7 +2650,9 @@ def df_replace_column_codelines(self, key):
if literal_key == col:
func_lines += [f' data_{i} = value']
else:
func_lines += [f' data_{i} = self._data[{i}]']
col_loc = self.column_loc[col]
type_id, col_id = col_loc.type_id, col_loc.col_id
func_lines += [f' data_{i} = self._data[{type_id}][{col_id}]']

res_data = f'res_data_{i}'
func_lines += [
Expand Down
12 changes: 6 additions & 6 deletions sdc/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,21 +638,21 @@ def test_impl(df, key, value):
msg = 'Could not set item for DataFrame with empty columns'
self.assertIn(msg, str(raises.exception))

@dfRefactoringNotImplemented
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
def test_df_add_column(self):
all_data = [{'A': [0, 1, 2], 'C': [0., np.nan, np.inf]}, {}]
key, value = 'B', np.array([1., -1., 0.])

self._test_df_set_column(all_data, key, value)

@dfRefactoringNotImplemented
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
def test_df_add_column_str(self):
all_data = [{'A': [0, 1, 2], 'C': [0., np.nan, np.inf]}, {}]
key, value = 'B', pd.Series(test_global_input_data_unicode_kind4)

self._test_df_set_column(all_data, key, value)

@dfRefactoringNotImplemented
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
def test_df_add_column_exception_invalid_length(self):
df = pd.DataFrame({'A': [0, 1, 2], 'C': [3., 4., 5.]})
key, value = 'B', np.array([1., np.nan, -1., 0.])
Expand All @@ -661,21 +661,21 @@ def test_df_add_column_exception_invalid_length(self):
df = pd.DataFrame({'A': []})
self._test_df_set_column_exception_empty_columns(df, key, value)

@dfRefactoringNotImplemented
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
def test_df_replace_column(self):
all_data = [{'A': [0, 1, 2], 'C': [0., np.nan, np.inf]}]
key, value = 'A', np.array([1., -1., 0.])

self._test_df_set_column(all_data, key, value)

@dfRefactoringNotImplemented
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
def test_df_replace_column_str(self):
all_data = [{'A': [0, 1, 2], 'C': [0., np.nan, np.inf]}]
key, value = 'A', pd.Series(test_global_input_data_unicode_kind4)

self._test_df_set_column(all_data, key, value)

@dfRefactoringNotImplemented
@dfRefactoringNotImplemented # required re-implementing DataFrame unboxing
def test_df_replace_column_exception_invalid_length(self):
df = pd.DataFrame({'A': [0, 1, 2], 'C': [3., 4., 5.]})
key, value = 'A', np.array([1., np.nan, -1., 0.])
Expand Down