Skip to content

ENH/BUG: add tz argument to to_timestamp of Period GH2877 #2991

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
2 commits merged into from Mar 15, 2013
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
2 changes: 2 additions & 0 deletions doc/source/v0.11.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Bug Fixes
- Fixed slow printing of large Dataframes, due to inefficient dtype
reporting (GH2807_)
- Fix pretty-printing of infinite data structures (closes GH2978_)
- Fixed exception when plotting timeseries bearing a timezone (closes GH2877_)
- str.contains ignored na argument (GH2806_)

See the `full release notes
Expand All @@ -326,6 +327,7 @@ on GitHub for a complete list.
.. _GH2837: https://github.com/pydata/pandas/issues/2837
.. _GH2898: https://github.com/pydata/pandas/issues/2898
.. _GH2978: https://github.com/pydata/pandas/issues/2978
.. _GH2877: https://github.com/pydata/pandas/issues/2877
.. _GH2739: https://github.com/pydata/pandas/issues/2739
.. _GH2710: https://github.com/pydata/pandas/issues/2710
.. _GH2806: https://github.com/pydata/pandas/issues/2806
Expand Down
2 changes: 1 addition & 1 deletion pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ def _no_base(self, freq):
if (base <= freqmod.FreqGroup.FR_DAY):
return x[:1].is_normalized

return Period(x[0], freq).to_timestamp() == x[0]
return Period(x[0], freq).to_timestamp(tz=x.tz) == x[0]
return True

def _use_dynamic_x(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tseries/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def end_time(self):
ordinal = (self + 1).start_time.value - 1
return Timestamp(ordinal)

def to_timestamp(self, freq=None, how='start'):
def to_timestamp(self, freq=None, how='start',tz=None):
"""
Return the Timestamp representation of the Period at the target
frequency at the specified end (how) of the Period
Expand Down Expand Up @@ -216,7 +216,7 @@ def to_timestamp(self, freq=None, how='start'):
val = self.asfreq(freq, how)

dt64 = tslib.period_ordinal_to_dt64(val.ordinal, base)
return Timestamp(dt64)
return Timestamp(dt64,tz=tz)

year = _period_field_accessor('year', 0)
month = _period_field_accessor('month', 3)
Expand Down
6 changes: 6 additions & 0 deletions pandas/tseries/tests/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def test_period_cons_weekly(self):
expected = Period(daystr, freq='D').asfreq(freq)
self.assertEquals(result, expected)

def test_timestamp_tz_arg(self):
import pytz
p = Period('1/1/2005', freq='M').to_timestamp(tz='Europe/Brussels')
self.assertEqual(p.tz,
pytz.timezone('Europe/Brussels').normalize(p).tzinfo)

def test_period_constructor(self):
i1 = Period('1/1/2005', freq='M')
i2 = Period('Jan 2005')
Expand Down
7 changes: 7 additions & 0 deletions pandas/tseries/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def setUp(self):
columns=['A', 'B', 'C'])
for x in idx]

@slow
def test_ts_plot_with_tz(self):
# GH2877
index = date_range('1/1/2011', periods=2, freq='H', tz='Europe/Brussels')
ts = Series([188.5, 328.25], index=index)
ts.plot()

@slow
def test_frame_inferred(self):
# inferred freq
Expand Down