Skip to content

Commit

Permalink
feat: Add EventDataFrame.clone()
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrako committed Sep 14, 2023
1 parent ef5898b commit 9ff3ba8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pymovements/events/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ def event_property_columns(self) -> list[str]:
event_property_columns -= set(self._additional_columns)
return list(event_property_columns)

def copy(self) -> EventDataFrame:
"""Return a copy of the EventDataFrame.
Returns
-------
EventDataFrame
A copy of the EventDataFrame.
"""
return EventDataFrame(data=self.frame.clone())

def _add_minimal_schema_columns(self, df: pl.DataFrame) -> pl.DataFrame:
"""Add minimal schema columns to :py:class:`polars.DataFrame` if they are missing."""
if len(df) == 0:
Expand Down
10 changes: 10 additions & 0 deletions tests/events/frame_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,13 @@ def test_event_dataframe_columns_same_as_frame():
event_df = pm.EventDataFrame(**init_kwargs)

assert event_df.columns == event_df.frame.columns


def test_event_dataframe_copy():
events = pm.EventDataFrame(name='saccade', onsets=[0], offsets=[123])
events_copy = events.copy()

# We want to have separate dataframes but with the exact same data.
assert events is not events_copy
assert events.frame is not events_copy.frame
assert_frame_equal(events.frame, events_copy.frame)

0 comments on commit 9ff3ba8

Please sign in to comment.