@@ -1922,23 +1922,17 @@ def test_pivot_table_values_key_error():
1922
1922
)
1923
1923
@pytest .mark .filterwarnings ("ignore:Dropping invalid columns:FutureWarning" )
1924
1924
@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 ):
1926
1926
# GH8093 & GH26411
1927
1927
override_dtype = None
1928
1928
1929
1929
if (
1930
1930
isinstance (values , Categorical )
1931
1931
and not isinstance (columns , list )
1932
- and op in ["sum" , "prod" , "skew" , "mad" ]
1932
+ and op in ["sum" , "prod" ]
1933
1933
):
1934
1934
# 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
1942
1936
elif (
1943
1937
isinstance (values , Categorical )
1944
1938
and len (keys ) == 1
@@ -1957,7 +1951,11 @@ def test_empty_groupby(columns, keys, values, method, op, request, using_array_m
1957
1951
raises = TypeError , match = "'Categorical' does not implement"
1958
1952
)
1959
1953
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
+ ):
1961
1959
mark = pytest .mark .xfail (
1962
1960
raises = AssertionError , match = "(DataFrame|Series) are different"
1963
1961
)
@@ -1971,20 +1969,6 @@ def test_empty_groupby(columns, keys, values, method, op, request, using_array_m
1971
1969
raises = AssertionError , match = "(DataFrame|Series) are different"
1972
1970
)
1973
1971
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
-
1988
1972
elif isinstance (values , BooleanArray ) and op in ["sum" , "prod" ]:
1989
1973
# We expect to get Int64 back for these
1990
1974
override_dtype = "Int64"
@@ -2015,29 +1999,19 @@ def get_result():
2015
1999
2016
2000
if columns == "C" :
2017
2001
# i.e. SeriesGroupBy
2018
- if op in ["prod" , "sum" , "skew" ]:
2002
+ if op in ["prod" , "sum" ]:
2019
2003
# ops that require more than just ordered-ness
2020
2004
if df .dtypes [0 ].kind == "M" :
2021
2005
# GH#41291
2022
2006
# 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"
2027
2008
with pytest .raises (TypeError , match = msg ):
2028
2009
get_result ()
2029
2010
2030
2011
return
2031
- if op in ["prod" , "sum" , "skew" , "mad" ]:
2032
- if isinstance (values , Categorical ):
2012
+ elif isinstance (values , Categorical ):
2033
2013
# 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"
2041
2015
with pytest .raises (TypeError , match = msg ):
2042
2016
get_result ()
2043
2017
@@ -2084,34 +2058,6 @@ def get_result():
2084
2058
tm .assert_equal (result , expected )
2085
2059
return
2086
2060
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
-
2115
2061
result = get_result ()
2116
2062
expected = df .set_index (keys )[columns ]
2117
2063
if override_dtype is not None :
0 commit comments