Skip to content

Commit 0abd0d8

Browse files
committed
tests for sorting dataframe in intervalset constructor
1 parent 83a8182 commit 0abd0d8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_metadata.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,44 @@ def test_create_iset_from_df_with_metadata():
111111
np.testing.assert_array_almost_equal(df.end.values, ep.end)
112112

113113

114+
@pytest.mark.parametrize(
115+
"df, expected",
116+
[
117+
# dataframe is sorted and metadata is kept
118+
(
119+
pd.DataFrame(
120+
{
121+
"start": [25.0, 0.0, 10.0, 16.0],
122+
"end": [40.0, 5.0, 15.0, 20.0],
123+
"label": np.arange(4),
124+
}
125+
),
126+
["DataFrame is not sorted by start times"],
127+
),
128+
(
129+
# dataframe is sorted and and metadata is dropped
130+
pd.DataFrame(
131+
{
132+
"start": [25, 0, 10, 16],
133+
"end": [40, 20, 15, 20],
134+
"label": np.arange(4),
135+
}
136+
),
137+
["DataFrame is not sorted by start times", "dropping metadata"],
138+
),
139+
],
140+
)
141+
def test_create_iset_from_df_with_metadata_sort(df, expected):
142+
with warnings.catch_warnings(record=True) as w:
143+
ep = nap.IntervalSet(df)
144+
for e in expected:
145+
assert np.any([e in str(w.message) for w in w])
146+
if "dropping metadata" not in expected:
147+
pd.testing.assert_frame_equal(
148+
ep.as_dataframe(), df.sort_values("start").reset_index(drop=True)
149+
)
150+
151+
114152
@pytest.mark.parametrize(
115153
"index",
116154
[

0 commit comments

Comments
 (0)