@@ -1922,23 +1922,17 @@ def test_pivot_table_values_key_error():
19221922)
19231923@pytest .mark .filterwarnings ("ignore:Dropping invalid columns:FutureWarning" )
19241924@pytest .mark .filterwarnings ("ignore:.*Select only valid:FutureWarning" )
1925- def test_empty_groupby (columns , keys , values , method , op , request , using_array_manager ):
1925+ def test_empty_groupby (columns , keys , values , method , op , request ):
19261926 # GH8093 & GH26411
19271927 override_dtype = None
19281928
19291929 if (
19301930 isinstance (values , Categorical )
19311931 and not isinstance (columns , list )
1932- and op in ["sum" , "prod" , "skew" , "mad" ]
1932+ and op in ["sum" , "prod" ]
19331933 ):
19341934 # handled below GH#41291
1935-
1936- if using_array_manager and op == "mad" :
1937- right_msg = "Cannot interpret 'CategoricalDtype.* as a data type"
1938- msg = "Regex pattern \" 'Categorical' does not implement.*" + right_msg
1939- mark = pytest .mark .xfail (raises = AssertionError , match = msg )
1940- request .node .add_marker (mark )
1941-
1935+ pass
19421936 elif (
19431937 isinstance (values , Categorical )
19441938 and len (keys ) == 1
@@ -1957,7 +1951,11 @@ def test_empty_groupby(columns, keys, values, method, op, request, using_array_m
19571951 raises = TypeError , match = "'Categorical' does not implement"
19581952 )
19591953 request .node .add_marker (mark )
1960- elif isinstance (values , Categorical ) and len (keys ) == 1 and op in ["sum" , "prod" ]:
1954+ elif (
1955+ isinstance (values , Categorical )
1956+ and len (keys ) == 1
1957+ and op in ["mad" , "min" , "max" , "sum" , "prod" , "skew" ]
1958+ ):
19611959 mark = pytest .mark .xfail (
19621960 raises = AssertionError , match = "(DataFrame|Series) are different"
19631961 )
@@ -1971,20 +1969,6 @@ def test_empty_groupby(columns, keys, values, method, op, request, using_array_m
19711969 raises = AssertionError , match = "(DataFrame|Series) are different"
19721970 )
19731971 request .node .add_marker (mark )
1974-
1975- elif (
1976- op == "mad"
1977- and not isinstance (columns , list )
1978- and isinstance (values , pd .DatetimeIndex )
1979- and values .tz is not None
1980- and using_array_manager
1981- ):
1982- mark = pytest .mark .xfail (
1983- raises = TypeError ,
1984- match = r"Cannot interpret 'datetime64\[ns, US/Eastern\]' as a data type" ,
1985- )
1986- request .node .add_marker (mark )
1987-
19881972 elif isinstance (values , BooleanArray ) and op in ["sum" , "prod" ]:
19891973 # We expect to get Int64 back for these
19901974 override_dtype = "Int64"
@@ -2015,29 +1999,19 @@ def get_result():
20151999
20162000 if columns == "C" :
20172001 # i.e. SeriesGroupBy
2018- if op in ["prod" , "sum" , "skew" ]:
2002+ if op in ["prod" , "sum" ]:
20192003 # ops that require more than just ordered-ness
20202004 if df .dtypes [0 ].kind == "M" :
20212005 # GH#41291
20222006 # datetime64 -> prod and sum are invalid
2023- if op == "skew" :
2024- msg = "does not support reduction 'skew'"
2025- else :
2026- msg = "datetime64 type does not support"
2007+ msg = "datetime64 type does not support"
20272008 with pytest .raises (TypeError , match = msg ):
20282009 get_result ()
20292010
20302011 return
2031- if op in ["prod" , "sum" , "skew" , "mad" ]:
2032- if isinstance (values , Categorical ):
2012+ elif isinstance (values , Categorical ):
20332013 # GH#41291
2034- if op == "mad" :
2035- # mad calls mean, which Categorical doesn't implement
2036- msg = "does not support reduction 'mean'"
2037- elif op == "skew" :
2038- msg = f"does not support reduction '{ op } '"
2039- else :
2040- msg = "category type does not support"
2014+ msg = "category type does not support"
20412015 with pytest .raises (TypeError , match = msg ):
20422016 get_result ()
20432017
@@ -2084,34 +2058,6 @@ def get_result():
20842058 tm .assert_equal (result , expected )
20852059 return
20862060
2087- if (
2088- op in ["mad" , "min" , "max" , "skew" ]
2089- and isinstance (values , Categorical )
2090- and len (keys ) == 1
2091- ):
2092- # Categorical doesn't implement, so with numeric_only=True
2093- # these are dropped and we get an empty DataFrame back
2094- result = get_result ()
2095- expected = df .set_index (keys )[[]]
2096-
2097- # with numeric_only=True, these are dropped, and we get
2098- # an empty DataFrame back
2099- if len (keys ) != 1 :
2100- # Categorical is special without 'observed=True'
2101- lev = Categorical ([0 ], dtype = values .dtype )
2102- mi = MultiIndex .from_product ([lev , lev ], names = keys )
2103- expected = DataFrame ([], columns = [], index = mi )
2104- else :
2105- # all columns are dropped, but we end up with one row
2106- # Categorical is special without 'observed=True'
2107- lev = Categorical ([0 ], dtype = values .dtype )
2108- ci = Index (lev , name = keys [0 ])
2109- expected = DataFrame ([], columns = [], index = ci )
2110- # expected = df.set_index(keys)[columns]
2111-
2112- tm .assert_equal (result , expected )
2113- return
2114-
21152061 result = get_result ()
21162062 expected = df .set_index (keys )[columns ]
21172063 if override_dtype is not None :
0 commit comments