Skip to content

Commit 9f93ab9

Browse files
committed
Added "an" to whatsnew and added example from original issue to the test - this checks passing observed parameter remains equivalent to not passing.
1 parent 6121313 commit 9f93ab9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ including other versions of pandas.
1919
Other Enhancements
2020
^^^^^^^^^^^^^^^^^^
2121

22-
:meth:`DataFrame.pivot_table` now accepts ``observed`` parameter which is passed to underlying calls to :meth:`DataFrame.groupby` to speed up grouping categorical data. (:issue:`24923`)
22+
:meth:`DataFrame.pivot_table` now accepts an ``observed`` parameter which is passed to underlying calls to :meth:`DataFrame.groupby` to speed up grouping categorical data. (:issue:`24923`)
2323
-
2424
-
2525

pandas/tests/reshape/test_pivot.py

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

68+
df = pd.DataFrame({'col1': list('abcde'),
69+
'col2': list('fghij'),
70+
'col3': [1, 2, 3, 4, 5]})
71+
72+
df.col1 = df.col1.astype('category')
73+
df.col2 = df.col1.astype('category')
74+
75+
df_pivot = df.pivot_table(index='col1', values='col3',
76+
columns='col2', aggfunc=np.sum,
77+
fill_value=0)
78+
79+
df_pivot_observed = df.pivot_table(index='col1', values='col3',
80+
columns='col2', aggfunc=np.sum,
81+
fill_value=0, observed=observed)
82+
83+
tm.assert_frame_equal(df_pivot, df_pivot_observed)
84+
6885
def test_pivot_table_nocols(self):
6986
df = DataFrame({'rows': ['a', 'b', 'c'],
7087
'cols': ['x', 'y', 'z'],

0 commit comments

Comments
 (0)