Skip to content

Commit

Permalink
BUG: raise if invalid freq is passed (pandas-dev#23546)
Browse files Browse the repository at this point in the history
  • Loading branch information
toobaz authored and tm9k1 committed Nov 19, 2018
1 parent 23854f9 commit 34a76a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,11 @@ class Timestamp(_Timestamp):
if ts.value == NPY_NAT:
return NaT

if is_string_object(freq):
freq = to_offset(freq)
elif not is_offset_object(freq):
if freq is None:
# GH 22311: Try to extract the frequency of a given Timestamp input
freq = getattr(ts_input, 'freq', None)
elif not is_offset_object(freq):
freq = to_offset(freq)

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

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/plotting/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ def _assert_less(ts1, ts2):
_assert_less(ts, ts + Micro(50))

def test_convert_nested(self):
inner = [Timestamp('2017-01-01', Timestamp('2017-01-02'))]
inner = [Timestamp('2017-01-01'), Timestamp('2017-01-02')]
data = [inner, inner]
result = self.dtc.convert(data, None, None)
expected = [self.dtc.convert(x, None, None) for x in data]
assert result == expected
assert (np.array(result) == expected).all()


class TestPeriodConverter(object):
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ def test_construct_timestamp_preserve_original_frequency(self):
expected = offsets.Day()
assert result == expected

def test_constructor_invalid_frequency(self):
# GH 22311
with tm.assert_raises_regex(ValueError, "Invalid frequency:"):
Timestamp('2012-01-01', freq=[])


class TestTimestamp(object):

Expand Down

0 comments on commit 34a76a0

Please sign in to comment.