@@ -11,6 +11,8 @@ class providing the base-class of operations.
11
11
from contextlib import contextmanager
12
12
import datetime
13
13
from functools import partial , wraps
14
+ import inspect
15
+ import re
14
16
import types
15
17
from typing import FrozenSet , List , Optional , Tuple , Type , Union
16
18
@@ -613,48 +615,53 @@ def _make_wrapper(self, name):
613
615
return self .apply (lambda self : getattr (self , name ))
614
616
615
617
f = getattr (type (self ._selected_obj ), name )
618
+ sig = inspect .signature (f )
616
619
617
620
def wrapper (* args , ** kwargs ):
618
621
# a little trickery for aggregation functions that need an axis
619
622
# argument
620
- kwargs_with_axis = kwargs .copy ()
621
- if "axis" not in kwargs_with_axis or kwargs_with_axis ["axis" ] is None :
622
- kwargs_with_axis ["axis" ] = self .axis
623
-
624
- def curried_with_axis (x ):
625
- return f (x , * args , ** kwargs_with_axis )
623
+ if "axis" in sig .parameters :
624
+ if kwargs .get ("axis" , None ) is None :
625
+ kwargs ["axis" ] = self .axis
626
626
627
627
def curried (x ):
628
628
return f (x , * args , ** kwargs )
629
629
630
630
# preserve the name so we can detect it when calling plot methods,
631
631
# to avoid duplicates
632
- curried .__name__ = curried_with_axis . __name__ = name
632
+ curried .__name__ = name
633
633
634
634
# special case otherwise extra plots are created when catching the
635
635
# exception below
636
636
if name in base .plotting_methods :
637
637
return self .apply (curried )
638
638
639
639
try :
640
- return self .apply (curried_with_axis )
641
- except Exception :
642
- try :
643
- return self .apply (curried )
644
- except Exception :
645
-
646
- # related to : GH3688
647
- # try item-by-item
648
- # this can be called recursively, so need to raise
649
- # ValueError
650
- # if we don't have this method to indicated to aggregate to
651
- # mark this column as an error
652
- try :
653
- return self ._aggregate_item_by_item (name , * args , ** kwargs )
654
- except AttributeError :
655
- # e.g. SparseArray has no flags attr
656
- raise ValueError
657
-
640
+ return self .apply (curried )
641
+ except TypeError as err :
642
+ if not re .search (
643
+ "reduction operation '.*' not allowed for this dtype" , str (err )
644
+ ):
645
+ # We don't have a cython implementation
646
+ # TODO: is the above comment accurate?
647
+ raise
648
+
649
+ # related to : GH3688
650
+ # try item-by-item
651
+ # this can be called recursively, so need to raise
652
+ # ValueError
653
+ # if we don't have this method to indicated to aggregate to
654
+ # mark this column as an error
655
+ try :
656
+ return self ._aggregate_item_by_item (name , * args , ** kwargs )
657
+ except AttributeError :
658
+ # e.g. SparseArray has no flags attr
659
+ # FIXME: 'SeriesGroupBy' has no attribute '_aggregate_item_by_item'
660
+ # occurs in idxmax() case
661
+ # in tests.groupby.test_function.test_non_cython_api
662
+ raise ValueError
663
+
664
+ wrapper .__name__ = name
658
665
return wrapper
659
666
660
667
def get_group (self , name , obj = None ):
0 commit comments