Skip to content

Commit 2d69034

Browse files
author
y-p
committed
Merge pull request #2991 from y-p/GH2877
ENH/BUG: add tz argument to to_timestamp of Period GH2877
2 parents 15847d6 + 662e427 commit 2d69034

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

doc/source/v0.11.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Bug Fixes
319319
- Fixed slow printing of large Dataframes, due to inefficient dtype
320320
reporting (GH2807_)
321321
- Fix pretty-printing of infinite data structures (closes GH2978_)
322+
- Fixed exception when plotting timeseries bearing a timezone (closes GH2877_)
322323
- str.contains ignored na argument (GH2806_)
323324

324325
See the `full release notes
@@ -330,6 +331,7 @@ on GitHub for a complete list.
330331
.. _GH2837: https://github.com/pydata/pandas/issues/2837
331332
.. _GH2898: https://github.com/pydata/pandas/issues/2898
332333
.. _GH2978: https://github.com/pydata/pandas/issues/2978
334+
.. _GH2877: https://github.com/pydata/pandas/issues/2877
333335
.. _GH2739: https://github.com/pydata/pandas/issues/2739
334336
.. _GH2710: https://github.com/pydata/pandas/issues/2710
335337
.. _GH2806: https://github.com/pydata/pandas/issues/2806

pandas/tools/plotting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ def _no_base(self, freq):
10431043
if (base <= freqmod.FreqGroup.FR_DAY):
10441044
return x[:1].is_normalized
10451045

1046-
return Period(x[0], freq).to_timestamp() == x[0]
1046+
return Period(x[0], freq).to_timestamp(tz=x.tz) == x[0]
10471047
return True
10481048

10491049
def _use_dynamic_x(self):

pandas/tseries/period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def end_time(self):
188188
ordinal = (self + 1).start_time.value - 1
189189
return Timestamp(ordinal)
190190

191-
def to_timestamp(self, freq=None, how='start'):
191+
def to_timestamp(self, freq=None, how='start',tz=None):
192192
"""
193193
Return the Timestamp representation of the Period at the target
194194
frequency at the specified end (how) of the Period
@@ -216,7 +216,7 @@ def to_timestamp(self, freq=None, how='start'):
216216
val = self.asfreq(freq, how)
217217

218218
dt64 = tslib.period_ordinal_to_dt64(val.ordinal, base)
219-
return Timestamp(dt64)
219+
return Timestamp(dt64,tz=tz)
220220

221221
year = _period_field_accessor('year', 0)
222222
month = _period_field_accessor('month', 3)

pandas/tseries/tests/test_period.py

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def test_period_cons_weekly(self):
7777
expected = Period(daystr, freq='D').asfreq(freq)
7878
self.assertEquals(result, expected)
7979

80+
def test_timestamp_tz_arg(self):
81+
import pytz
82+
p = Period('1/1/2005', freq='M').to_timestamp(tz='Europe/Brussels')
83+
self.assertEqual(p.tz,
84+
pytz.timezone('Europe/Brussels').normalize(p).tzinfo)
85+
8086
def test_period_constructor(self):
8187
i1 = Period('1/1/2005', freq='M')
8288
i2 = Period('Jan 2005')

pandas/tseries/tests/test_plotting.py

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def setUp(self):
5151
columns=['A', 'B', 'C'])
5252
for x in idx]
5353

54+
@slow
55+
def test_ts_plot_with_tz(self):
56+
# GH2877
57+
index = date_range('1/1/2011', periods=2, freq='H', tz='Europe/Brussels')
58+
ts = Series([188.5, 328.25], index=index)
59+
ts.plot()
60+
5461
@slow
5562
def test_frame_inferred(self):
5663
# inferred freq

0 commit comments

Comments
 (0)