Skip to content

Commit 2718cef

Browse files
author
victor
committed
Simplified and added to_timedelta to test.
1 parent c25770d commit 2718cef

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

pandas/tests/scalar/timedelta/test_construction.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,13 @@ def test_td_constructor_value_error():
212212
Timedelta(nanoseconds='abc')
213213

214214

215-
@pytest.mark.parametrize("redundant_unit, expectation", [
216-
("", tm.do_not_raise),
217-
("d", pytest.raises(ValueError)),
218-
("us", pytest.raises(ValueError))])
219-
@pytest.mark.parametrize("unit", [
220-
"d", "m", "s", "us"])
221-
@pytest.mark.parametrize("sign", [
222-
+1, -1])
223-
@pytest.mark.parametrize("num", [
224-
0.001, 1, 10])
225-
def test_string_with_unit(num, sign, unit, redundant_unit, expectation):
215+
@pytest.mark.parametrize("str_unit, unit, expectation", [
216+
("", "s", tm.do_not_raise),
217+
("s", "s", pytest.raises(ValueError)),
218+
("", None, pytest.raises(ValueError)),
219+
("s", "d", pytest.raises(ValueError)),])
220+
def test_string_with_unit(str_unit, unit, expectation):
226221
with expectation:
227-
assert Timedelta(str(sign * num) + redundant_unit, unit=unit) \
228-
== Timedelta(sign * num, unit=unit)
222+
val_str = "10{}".format(str_unit)
223+
assert Timedelta(val_str, unit=unit) == Timedelta(10, unit=unit)
224+
assert pd.to_timedelta(val_str, unit=unit) == Timedelta(10, unit=unit)

0 commit comments

Comments
 (0)