@@ -192,9 +192,9 @@ def test_pivot_table_categorical(self):
192192 ["c" , "d" , "c" , "d" ], categories = ["c" , "d" , "y" ], ordered = True
193193 )
194194 df = DataFrame ({"A" : cat1 , "B" : cat2 , "values" : [1 , 2 , 3 , 4 ]})
195- msg = "The default value of observed=False is deprecated"
196- with tm . assert_produces_warning ( FutureWarning , match = msg ):
197- result = pivot_table ( df , values = "values" , index = [ "A" , "B" ], dropna = True )
195+ result = pivot_table (
196+ df , values = "values" , index = [ "A" , "B" ], dropna = True , observed = False
197+ )
198198
199199 exp_index = MultiIndex .from_arrays ([cat1 , cat2 ], names = ["A" , "B" ])
200200 expected = DataFrame ({"values" : [1.0 , 2.0 , 3.0 , 4.0 ]}, index = exp_index )
@@ -213,9 +213,9 @@ def test_pivot_table_dropna_categoricals(self, dropna):
213213 )
214214
215215 df ["A" ] = df ["A" ].astype (CategoricalDtype (categories , ordered = False ))
216- msg = "The default value of observed=False is deprecated"
217- with tm . assert_produces_warning ( FutureWarning , match = msg ):
218- result = df . pivot_table ( index = "B" , columns = "A" , values = "C" , dropna = dropna )
216+ result = df . pivot_table (
217+ index = "B" , columns = "A" , values = "C" , dropna = dropna , observed = False
218+ )
219219 expected_columns = Series (["a" , "b" , "c" ], name = "A" )
220220 expected_columns = expected_columns .astype (
221221 CategoricalDtype (categories , ordered = False )
@@ -245,9 +245,7 @@ def test_pivot_with_non_observable_dropna(self, dropna):
245245 }
246246 )
247247
248- msg = "The default value of observed=False is deprecated"
249- with tm .assert_produces_warning (FutureWarning , match = msg ):
250- result = df .pivot_table (index = "A" , values = "B" , dropna = dropna )
248+ result = df .pivot_table (index = "A" , values = "B" , dropna = dropna , observed = False )
251249 if dropna :
252250 values = [2.0 , 3.0 ]
253251 codes = [0 , 1 ]
@@ -278,9 +276,7 @@ def test_pivot_with_non_observable_dropna_multi_cat(self, dropna):
278276 }
279277 )
280278
281- msg = "The default value of observed=False is deprecated"
282- with tm .assert_produces_warning (FutureWarning , match = msg ):
283- result = df .pivot_table (index = "A" , values = "B" , dropna = dropna )
279+ result = df .pivot_table (index = "A" , values = "B" , dropna = dropna , observed = False )
284280 expected = DataFrame (
285281 {"B" : [2.0 , 3.0 , 0.0 ]},
286282 index = Index (
@@ -304,9 +300,7 @@ def test_pivot_with_interval_index(self, left_right, dropna, closed):
304300 interval_values = Categorical (pd .IntervalIndex .from_arrays (left , right , closed ))
305301 df = DataFrame ({"A" : interval_values , "B" : 1 })
306302
307- msg = "The default value of observed=False is deprecated"
308- with tm .assert_produces_warning (FutureWarning , match = msg ):
309- result = df .pivot_table (index = "A" , values = "B" , dropna = dropna )
303+ result = df .pivot_table (index = "A" , values = "B" , dropna = dropna , observed = False )
310304 expected = DataFrame (
311305 {"B" : 1.0 }, index = Index (interval_values .unique (), name = "A" )
312306 )
@@ -327,11 +321,15 @@ def test_pivot_with_interval_index_margins(self):
327321 }
328322 )
329323
330- msg = "The default value of observed=False is deprecated"
331- with tm .assert_produces_warning (FutureWarning , match = msg ):
332- pivot_tab = pivot_table (
333- df , index = "C" , columns = "B" , values = "A" , aggfunc = "sum" , margins = True
334- )
324+ pivot_tab = pivot_table (
325+ df ,
326+ index = "C" ,
327+ columns = "B" ,
328+ values = "A" ,
329+ aggfunc = "sum" ,
330+ margins = True ,
331+ observed = False ,
332+ )
335333
336334 result = pivot_tab ["All" ]
337335 expected = Series (
@@ -1830,9 +1828,9 @@ def test_categorical_margins_category(self, observed):
18301828
18311829 df .y = df .y .astype ("category" )
18321830 df .z = df .z .astype ("category" )
1833- msg = "The default value of observed=False is deprecated"
1834- with tm . assert_produces_warning ( FutureWarning , match = msg ):
1835- table = df . pivot_table ( "x" , "y" , "z" , dropna = observed , margins = True )
1831+ table = df . pivot_table (
1832+ "x" , "y" , "z" , dropna = observed , margins = True , observed = False
1833+ )
18361834 tm .assert_frame_equal (table , expected )
18371835
18381836 def test_margins_casted_to_float (self ):
@@ -1894,11 +1892,14 @@ def test_categorical_aggfunc(self, observed):
18941892 {"C1" : ["A" , "B" , "C" , "C" ], "C2" : ["a" , "a" , "b" , "b" ], "V" : [1 , 2 , 3 , 4 ]}
18951893 )
18961894 df ["C1" ] = df ["C1" ].astype ("category" )
1897- msg = "The default value of observed=False is deprecated"
1898- with tm .assert_produces_warning (FutureWarning , match = msg ):
1899- result = df .pivot_table (
1900- "V" , index = "C1" , columns = "C2" , dropna = observed , aggfunc = "count"
1901- )
1895+ result = df .pivot_table (
1896+ "V" ,
1897+ index = "C1" ,
1898+ columns = "C2" ,
1899+ dropna = observed ,
1900+ aggfunc = "count" ,
1901+ observed = False ,
1902+ )
19021903
19031904 expected_index = pd .CategoricalIndex (
19041905 ["A" , "B" , "C" ], categories = ["A" , "B" , "C" ], ordered = False , name = "C1"
0 commit comments