Skip to content

Commit 416e9c8

Browse files
committed
Test separated into own test. Added issue comment. Updated df var names so more explicit in tm assertion call.
1 parent ebe5972 commit 416e9c8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pandas/tests/reshape/test_pivot.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,24 @@ def test_pivot_table(self, observed):
6565
index + [columns])['D'].agg(np.mean).unstack()
6666
tm.assert_frame_equal(table, expected)
6767

68+
def test_pivot_table_categorical_observed(self, observed):
69+
# issue #24923
6870
df = pd.DataFrame({'col1': list('abcde'),
6971
'col2': list('fghij'),
7072
'col3': [1, 2, 3, 4, 5]})
7173

7274
df.col1 = df.col1.astype('category')
7375
df.col2 = df.col1.astype('category')
7476

75-
df_pivot = df.pivot_table(index='col1', values='col3',
77+
expected = df.pivot_table(index='col1', values='col3',
7678
columns='col2', aggfunc=np.sum,
7779
fill_value=0)
7880

79-
df_pivot_observed = df.pivot_table(index='col1', values='col3',
80-
columns='col2', aggfunc=np.sum,
81-
fill_value=0, observed=observed)
81+
result = df.pivot_table(index='col1', values='col3',
82+
columns='col2', aggfunc=np.sum,
83+
fill_value=0, observed=observed)
8284

83-
tm.assert_frame_equal(df_pivot, df_pivot_observed)
85+
tm.assert_frame_equal(result, expected)
8486

8587
def test_pivot_table_nocols(self):
8688
df = DataFrame({'rows': ['a', 'b', 'c'],

0 commit comments

Comments
 (0)