Skip to content

Commit 18f6db4

Browse files
author
Jean-Mathieu Deschenes
committed
Using pytest parametrize as per @jreback suggestion.
1 parent 0ba907c commit 18f6db4

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

pandas/tests/indexing/test_timedelta.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
import pandas as pd
24
from pandas.util import testing as tm
35

@@ -20,20 +22,22 @@ def test_boolean_indexing(self):
2022
dtype='int64')
2123
tm.assert_frame_equal(expected, result)
2224

23-
def test_list_like_indexing(self):
25+
@pytest.mark.parametrize("indexer, expected",
26+
[(0, [20, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
27+
(slice(4, 8), [0, 1, 2, 3, 20, 20, 20, 20, 8, 9],),
28+
([3, 5], [0, 1, 2, 20, 4, 20, 6, 7, 8, 9])])
29+
def test_list_like_indexing(self, indexer, expected):
2430
# GH 16637
2531
df = pd.DataFrame({'x': range(10)}, dtype="int64")
2632
df.index = pd.to_timedelta(range(10), unit='s')
33+
try:
34+
df.loc[df.index[indexer], 'x'] = 20
35+
except ValueError:
36+
raise ValueError(indexer)
2737

28-
conditions = [df.index[0], df.index[4:8], df.index[[3, 5]]]
29-
expected_data = [[20, 1, 2, 3, 4, 5, 6, 7, 8, 9],
30-
[0, 1, 2, 3, 20, 20, 20, 20, 8, 9],
31-
[0, 1, 2, 20, 4, 20, 6, 7, 8, 9]]
32-
for cond, data in zip(conditions, expected_data):
33-
result = df.copy()
34-
result.loc[cond, 'x'] = 20
35-
expected = pd.DataFrame(data,
36-
index=pd.to_timedelta(range(10), unit='s'),
37-
columns=['x'],
38-
dtype="int64")
39-
tm.assert_frame_equal(expected, result)
38+
expected = pd.DataFrame(expected,
39+
index=pd.to_timedelta(range(10), unit='s'),
40+
columns=['x'],
41+
dtype="int64")
42+
43+
tm.assert_frame_equal(expected, df)

0 commit comments

Comments
 (0)