@@ -1724,27 +1724,82 @@ def test_pivot_table_values_key_error():
1724
1724
[0 ],
1725
1725
[0.0 ],
1726
1726
["a" ],
1727
- [ Categorical ([0 ])] ,
1727
+ Categorical ([0 ]),
1728
1728
[to_datetime (0 )],
1729
- [ date_range (0 , 1 , 1 , tz = "US/Eastern" )] ,
1730
- [ pd .array ([0 ], dtype = "Int64" )] ,
1731
- [ pd .array ([0 ], dtype = "Float64" )] ,
1732
- [ pd .array ([False ], dtype = "boolean" )] ,
1729
+ date_range (0 , 1 , 1 , tz = "US/Eastern" ),
1730
+ pd .array ([0 ], dtype = "Int64" ),
1731
+ pd .array ([0 ], dtype = "Float64" ),
1732
+ pd .array ([False ], dtype = "boolean" ),
1733
1733
],
1734
1734
)
1735
1735
@pytest .mark .parametrize ("method" , ["attr" , "agg" , "apply" ])
1736
1736
@pytest .mark .parametrize (
1737
1737
"op" , ["idxmax" , "idxmin" , "mad" , "min" , "max" , "sum" , "prod" , "skew" ]
1738
1738
)
1739
- def test_empty_groupby (columns , keys , values , method , op ):
1739
+ def test_empty_groupby (columns , keys , values , method , op , request ):
1740
1740
# GH8093 & GH26411
1741
1741
1742
+ if isinstance (values , Categorical ) and len (keys ) == 1 and method == "apply" :
1743
+ mark = pytest .mark .xfail (raises = TypeError , match = "'str' object is not callable" )
1744
+ request .node .add_marker (mark )
1745
+ elif (
1746
+ isinstance (values , Categorical )
1747
+ and len (keys ) == 1
1748
+ and op in ["idxmax" , "idxmin" ]
1749
+ ):
1750
+ mark = pytest .mark .xfail (
1751
+ raises = ValueError , match = "attempt to get arg(min|max) of an empty sequence"
1752
+ )
1753
+ request .node .add_marker (mark )
1754
+ elif (
1755
+ isinstance (values , Categorical )
1756
+ and len (keys ) == 1
1757
+ and not isinstance (columns , list )
1758
+ ):
1759
+ mark = pytest .mark .xfail (
1760
+ raises = TypeError , match = "'Categorical' does not implement"
1761
+ )
1762
+ request .node .add_marker (mark )
1763
+ elif (
1764
+ isinstance (values , Categorical )
1765
+ and len (keys ) == 1
1766
+ and op in ["mad" , "min" , "max" , "sum" , "prod" , "skew" ]
1767
+ ):
1768
+ mark = pytest .mark .xfail (
1769
+ raises = AssertionError , match = "(DataFrame|Series) are different"
1770
+ )
1771
+ request .node .add_marker (mark )
1772
+ elif (
1773
+ isinstance (values , Categorical )
1774
+ and len (keys ) == 2
1775
+ and op in ["min" , "max" , "sum" ]
1776
+ and method != "apply"
1777
+ ):
1778
+ mark = pytest .mark .xfail (
1779
+ raises = AssertionError , match = "(DataFrame|Series) are different"
1780
+ )
1781
+ request .node .add_marker (mark )
1782
+ elif (
1783
+ isinstance (values , pd .core .arrays .BooleanArray )
1784
+ and op in ["sum" , "prod" ]
1785
+ and method != "apply"
1786
+ ):
1787
+ mark = pytest .mark .xfail (
1788
+ raises = AssertionError , match = "(DataFrame|Series) are different"
1789
+ )
1790
+ request .node .add_marker (mark )
1791
+
1742
1792
override_dtype = None
1743
1793
if isinstance (values [0 ], bool ) and op in ("prod" , "sum" ) and method != "apply" :
1744
1794
# sum/product of bools is an integer
1745
1795
override_dtype = "int64"
1746
1796
1747
- df = DataFrame ([3 * values ], columns = list ("ABC" ))
1797
+ df = DataFrame ({"A" : values , "B" : values , "C" : values }, columns = list ("ABC" ))
1798
+
1799
+ if hasattr (values , "dtype" ):
1800
+ # check that we did the construction right
1801
+ assert (df .dtypes == values .dtype ).all ()
1802
+
1748
1803
df = df .iloc [:0 ]
1749
1804
1750
1805
gb = df .groupby (keys )[columns ]
0 commit comments