Skip to content

BUG: raise if invalid freq is passed #23546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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