Skip to content

Commit 209188e

Browse files
author
Matt Roeschke
committed
Add the actual test
1 parent a9078d3 commit 209188e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

pandas/tests/reshape/test_pivot.py

+40
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,46 @@ def test_pivot_with_tz(self, method):
429429
pv = pd.pivot(df, index='dt1', columns='dt2', values='data1')
430430
tm.assert_frame_equal(pv, expected)
431431

432+
def test_pivot_tz_in_values(self):
433+
# GH 14948
434+
df = pd.DataFrame([{'uid': u'aa',
435+
'ts': pd.Timestamp('2016-08-12 13:00:00-0700',
436+
tz='US/Pacific')},
437+
{'uid': u'aa',
438+
'ts': pd.Timestamp('2016-08-12 08:00:00-0700',
439+
tz='US/Pacific')},
440+
{'uid': u'aa',
441+
'ts': pd.Timestamp('2016-08-12 14:00:00-0700',
442+
tz='US/Pacific')},
443+
{'uid': u'aa',
444+
'ts': pd.Timestamp('2016-08-25 11:00:00-0700',
445+
tz='US/Pacific')},
446+
{'uid': u'aa',
447+
'ts': pd.Timestamp('2016-08-25 13:00:00-0700',
448+
tz='US/Pacific')}])
449+
450+
df = df.set_index('ts').reset_index()
451+
mins = df.ts.map(lambda x: x.replace(hour=0, minute=0,
452+
second=0, microsecond=0))
453+
454+
result = pd.pivot_table(df.set_index('ts').reset_index(),
455+
values='ts', index=['uid'], columns=[mins],
456+
aggfunc=np.min)
457+
expected = pd.DataFrame(
458+
[
459+
[pd.Timestamp('2016-08-12 08:00:00-0700', tz='US/Pacific'),
460+
pd.Timestamp('2016-08-25 11:00:00-0700', tz='US/Pacific')]
461+
],
462+
index=pd.Index(['aa'], name='uid'),
463+
columns=pd.DatetimeIndex(
464+
[
465+
pd.Timestamp('2016-08-12 00:00:00', tz='US/Pacific'),
466+
pd.Timestamp('2016-08-25 00:00:00', tz='US/Pacific')
467+
],
468+
name='ts')
469+
)
470+
tm.assert_frame_equal(result, expected)
471+
432472
@pytest.mark.parametrize('method', [True, False])
433473
def test_pivot_periods(self, method):
434474
df = DataFrame({'p1': [pd.Period('2013-01-01', 'D'),

0 commit comments

Comments
 (0)