Skip to content

Commit 498bdd4

Browse files
toobazjreback
authored andcommitted
BUG: raise if invalid freq is passed (#23546)
1 parent 712fa94 commit 498bdd4

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

pandas/_libs/tslibs/timestamps.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,11 @@ class Timestamp(_Timestamp):
733733
if ts.value == NPY_NAT:
734734
return NaT
735735

736-
if is_string_object(freq):
737-
freq = to_offset(freq)
738-
elif not is_offset_object(freq):
736+
if freq is None:
739737
# GH 22311: Try to extract the frequency of a given Timestamp input
740738
freq = getattr(ts_input, 'freq', None)
739+
elif not is_offset_object(freq):
740+
freq = to_offset(freq)
741741

742742
return create_timestamp_from_ts(ts.value, ts.dts, ts.tzinfo, freq)
743743

pandas/tests/plotting/test_converter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ def _assert_less(ts1, ts2):
285285
_assert_less(ts, ts + Micro(50))
286286

287287
def test_convert_nested(self):
288-
inner = [Timestamp('2017-01-01', Timestamp('2017-01-02'))]
288+
inner = [Timestamp('2017-01-01'), Timestamp('2017-01-02')]
289289
data = [inner, inner]
290290
result = self.dtc.convert(data, None, None)
291291
expected = [self.dtc.convert(x, None, None) for x in data]
292-
assert result == expected
292+
assert (np.array(result) == expected).all()
293293

294294

295295
class TestPeriodConverter(object):

pandas/tests/scalar/timestamp/test_timestamp.py

+5
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ def test_construct_timestamp_preserve_original_frequency(self):
575575
expected = offsets.Day()
576576
assert result == expected
577577

578+
def test_constructor_invalid_frequency(self):
579+
# GH 22311
580+
with tm.assert_raises_regex(ValueError, "Invalid frequency:"):
581+
Timestamp('2012-01-01', freq=[])
582+
578583

579584
class TestTimestamp(object):
580585

0 commit comments

Comments
 (0)