Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merging dataframes with None value #1225

Merged
merged 3 commits into from
Sep 27, 2023
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
2 changes: 1 addition & 1 deletion evadb/models/storage/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def merge_column_wise(cls, batches: List[Batch], auto_renaming=False) -> Batch:
frame_index == frames_index[i - 1]
), "Merging of DataFrames with unmatched indices can cause undefined behavior"

new_frames = pd.concat(frames, axis=1, copy=False, ignore_index=False).ffill()
new_frames = pd.concat(frames, axis=1, copy=False, ignore_index=False)
if new_frames.columns.duplicated().any():
logger.debug("Duplicated column name detected {}".format(new_frames))
return Batch(new_frames)
Expand Down
23 changes: 23 additions & 0 deletions test/unit_tests/models/storage/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ def test_merge_column_wise_batch_frame(self):
# Special case
self.assertEqual(Batch.merge_column_wise([]), Batch())

# Cases with None
batch_1 = Batch(frames=pd.DataFrame({"id": [0, None, 1]}))
batch_2 = Batch(frames=pd.DataFrame({"data": [None, 0, None]}))
batch_res = Batch(
frames=pd.DataFrame({"id": [0, None, 1], "data": [None, 0, None]})
)
self.assertEqual(Batch.merge_column_wise([batch_1, batch_2]), batch_res)

# Cases with filter
df_1 = pd.DataFrame({"id": [-10, 1, 2]})
df_2 = pd.DataFrame({"data": [-20, 2, 3]})
df_1 = df_1[df_1 < 0].dropna()
df_1.reset_index(drop=True, inplace=True)
df_2 = df_2[df_2 < 0].dropna()
df_2.reset_index(drop=True, inplace=True)
batch_1 = Batch(frames=df_1)
batch_2 = Batch(frames=df_2)
df_res = pd.DataFrame({"id": [-10, 1, 2], "data": [-20, 2, 3]})
df_res = df_res[df_res < 0].dropna()
df_res.reset_index(drop=True, inplace=True)
batch_res = Batch(frames=df_res)
self.assertEqual(Batch.merge_column_wise([batch_1, batch_2]), batch_res)

def test_should_fail_for_list(self):
frames = [{"id": 0, "data": [1, 2]}, {"id": 1, "data": [1, 2]}]
self.assertRaises(ValueError, Batch, frames)
Expand Down