From 9ff3ba8d18b8e7c6243b16a09f5b27a06f4039dc Mon Sep 17 00:00:00 2001 From: "Daniel G, Krakowczyk" Date: Thu, 14 Sep 2023 09:44:13 +0200 Subject: [PATCH] feat: Add EventDataFrame.clone() --- src/pymovements/events/frame.py | 10 ++++++++++ tests/events/frame_test.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/pymovements/events/frame.py b/src/pymovements/events/frame.py index 6ce425bb4..1c8921a79 100644 --- a/src/pymovements/events/frame.py +++ b/src/pymovements/events/frame.py @@ -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: diff --git a/tests/events/frame_test.py b/tests/events/frame_test.py index 4c616ec75..4cf7d55b0 100644 --- a/tests/events/frame_test.py +++ b/tests/events/frame_test.py @@ -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)