Skip to content

Commit f03490e

Browse files
committed
Add test
1 parent f1aa78a commit f03490e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pandas/core/computation/pytables.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ def stringify(value):
200200
v = v.tz_convert("UTC")
201201
return TermValue(v, v.value, kind)
202202
elif kind == "timedelta64" or kind == "timedelta":
203-
v = Timedelta(v, unit="s").value
203+
if isinstance(v, str):
204+
v = Timedelta(v).value
205+
else:
206+
v = Timedelta(v, unit="s").value
204207
return TermValue(int(v), v, kind)
205208
elif meta == "category":
206209
metadata = extract_array(self.metadata, extract_numpy=True)

pandas/tests/scalar/timedelta/test_constructors.py

+14
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,17 @@ def test_timedelta_constructor_identity():
289289
expected = Timedelta(np.timedelta64(1, "s"))
290290
result = Timedelta(expected)
291291
assert result is expected
292+
293+
294+
@pytest.mark.parametrize(
295+
"constructor, value, unit, expectation",
296+
[
297+
(Timedelta, "10s", "ms", (ValueError, "unit must be un-specified")),
298+
(to_timedelta, "10s", "ms", (ValueError, "unit must be un-specified")),
299+
(to_timedelta, ["1", 2, 3], "s", (ValueError, "unit must be un-specified")),
300+
],
301+
)
302+
def test_string_with_unit(constructor, value, unit, expectation):
303+
exp, match = expectation
304+
with pytest.raises(exp, match=match):
305+
_ = constructor(value, unit=unit)

0 commit comments

Comments
 (0)