20
20
import pandas .core .missing as mis
21
21
import pandas .core .datetools as datetools
22
22
from pandas import compat
23
- from pandas .compat import map , zip , lrange , string_types , isidentifier
23
+ from pandas .compat import map , zip , lrange , string_types , isidentifier , PY3
24
24
from pandas .core .common import (isnull , notnull , is_list_like ,
25
25
_values_from_object , _maybe_promote ,
26
26
_maybe_box_datetimelike , ABCSeries ,
@@ -4976,11 +4976,11 @@ def _add_numeric_operations(cls):
4976
4976
axis_descr , name , name2 = _doc_parms (cls )
4977
4977
4978
4978
cls .any = _make_logical_function (
4979
- 'any' , name , name2 , axis_descr ,
4979
+ cls , 'any' , name , name2 , axis_descr ,
4980
4980
'Return whether any element is True over requested axis' ,
4981
4981
nanops .nanany )
4982
4982
cls .all = _make_logical_function (
4983
- 'all' , name , name2 , axis_descr ,
4983
+ cls , 'all' , name , name2 , axis_descr ,
4984
4984
'Return whether all elements are True over requested axis' ,
4985
4985
nanops .nanall )
4986
4986
@@ -5008,18 +5008,18 @@ def mad(self, axis=None, skipna=None, level=None):
5008
5008
cls .mad = mad
5009
5009
5010
5010
cls .sem = _make_stat_function_ddof (
5011
- 'sem' , name , name2 , axis_descr ,
5011
+ cls , 'sem' , name , name2 , axis_descr ,
5012
5012
"Return unbiased standard error of the mean over requested "
5013
5013
"axis.\n \n Normalized by N-1 by default. This can be changed "
5014
5014
"using the ddof argument" ,
5015
5015
nanops .nansem )
5016
5016
cls .var = _make_stat_function_ddof (
5017
- 'var' , name , name2 , axis_descr ,
5017
+ cls , 'var' , name , name2 , axis_descr ,
5018
5018
"Return unbiased variance over requested axis.\n \n Normalized by "
5019
5019
"N-1 by default. This can be changed using the ddof argument" ,
5020
5020
nanops .nanvar )
5021
5021
cls .std = _make_stat_function_ddof (
5022
- 'std' , name , name2 , axis_descr ,
5022
+ cls , 'std' , name , name2 , axis_descr ,
5023
5023
"Return sample standard deviation over requested axis."
5024
5024
"\n \n Normalized by N-1 by default. This can be changed using the "
5025
5025
"ddof argument" ,
@@ -5038,54 +5038,54 @@ def compound(self, axis=None, skipna=None, level=None):
5038
5038
cls .compound = compound
5039
5039
5040
5040
cls .cummin = _make_cum_function (
5041
- 'min ' , name , name2 , axis_descr , "cumulative minimum" ,
5041
+ cls , 'cummin ' , name , name2 , axis_descr , "cumulative minimum" ,
5042
5042
lambda y , axis : np .minimum .accumulate (y , axis ), np .inf , np .nan )
5043
5043
cls .cumsum = _make_cum_function (
5044
- 'sum ' , name , name2 , axis_descr , "cumulative sum" ,
5044
+ cls , 'cumsum ' , name , name2 , axis_descr , "cumulative sum" ,
5045
5045
lambda y , axis : y .cumsum (axis ), 0. , np .nan )
5046
5046
cls .cumprod = _make_cum_function (
5047
- 'prod ' , name , name2 , axis_descr , "cumulative product" ,
5047
+ cls , 'cumprod ' , name , name2 , axis_descr , "cumulative product" ,
5048
5048
lambda y , axis : y .cumprod (axis ), 1. , np .nan )
5049
5049
cls .cummax = _make_cum_function (
5050
- 'max ' , name , name2 , axis_descr , "cumulative max" ,
5050
+ cls , 'cummax ' , name , name2 , axis_descr , "cumulative max" ,
5051
5051
lambda y , axis : np .maximum .accumulate (y , axis ), - np .inf , np .nan )
5052
5052
5053
5053
cls .sum = _make_stat_function (
5054
- 'sum' , name , name2 , axis_descr ,
5054
+ cls , 'sum' , name , name2 , axis_descr ,
5055
5055
'Return the sum of the values for the requested axis' ,
5056
5056
nanops .nansum )
5057
5057
cls .mean = _make_stat_function (
5058
- 'mean' , name , name2 , axis_descr ,
5058
+ cls , 'mean' , name , name2 , axis_descr ,
5059
5059
'Return the mean of the values for the requested axis' ,
5060
5060
nanops .nanmean )
5061
5061
cls .skew = _make_stat_function (
5062
- 'skew' , name , name2 , axis_descr ,
5062
+ cls , 'skew' , name , name2 , axis_descr ,
5063
5063
'Return unbiased skew over requested axis\n Normalized by N-1' ,
5064
5064
nanops .nanskew )
5065
5065
cls .kurt = _make_stat_function (
5066
- 'kurt' , name , name2 , axis_descr ,
5066
+ cls , 'kurt' , name , name2 , axis_descr ,
5067
5067
"Return unbiased kurtosis over requested axis using Fisher's "
5068
5068
"definition of\n kurtosis (kurtosis of normal == 0.0). Normalized "
5069
5069
"by N-1\n " ,
5070
5070
nanops .nankurt )
5071
5071
cls .kurtosis = cls .kurt
5072
5072
cls .prod = _make_stat_function (
5073
- 'prod' , name , name2 , axis_descr ,
5073
+ cls , 'prod' , name , name2 , axis_descr ,
5074
5074
'Return the product of the values for the requested axis' ,
5075
5075
nanops .nanprod )
5076
5076
cls .product = cls .prod
5077
5077
cls .median = _make_stat_function (
5078
- 'median' , name , name2 , axis_descr ,
5078
+ cls , 'median' , name , name2 , axis_descr ,
5079
5079
'Return the median of the values for the requested axis' ,
5080
5080
nanops .nanmedian )
5081
5081
cls .max = _make_stat_function (
5082
- 'max' , name , name2 , axis_descr ,
5082
+ cls , 'max' , name , name2 , axis_descr ,
5083
5083
"""This method returns the maximum of the values in the object.
5084
5084
If you want the *index* of the maximum, use ``idxmax``. This is
5085
5085
the equivalent of the ``numpy.ndarray`` method ``argmax``.""" ,
5086
5086
nanops .nanmax )
5087
5087
cls .min = _make_stat_function (
5088
- 'min' , name , name2 , axis_descr ,
5088
+ cls , 'min' , name , name2 , axis_descr ,
5089
5089
"""This method returns the minimum of the values in the object.
5090
5090
If you want the *index* of the minimum, use ``idxmin``. This is
5091
5091
the equivalent of the ``numpy.ndarray`` method ``argmin``.""" ,
@@ -5105,7 +5105,7 @@ def nanptp(values, axis=0, skipna=True):
5105
5105
return nmax - nmin
5106
5106
5107
5107
cls .ptp = _make_stat_function (
5108
- 'ptp' , name , name2 , axis_descr ,
5108
+ cls , 'ptp' , name , name2 , axis_descr ,
5109
5109
"""Returns the difference between the maximum value and the
5110
5110
minimum value in the object. This is the equivalent of the
5111
5111
``numpy.ndarray`` method ``ptp``.""" ,
@@ -5238,7 +5238,17 @@ def _doc_parms(cls):
5238
5238
%(outname)s : %(name1)s\n """
5239
5239
5240
5240
5241
- def _make_stat_function (name , name1 , name2 , axis_descr , desc , f ):
5241
+ def _set_function_name (f , name , cls ):
5242
+ f .__name__ = name
5243
+ if PY3 :
5244
+ f .__qualname__ = '{klass}.{name}' .format (
5245
+ klass = cls .__name__ ,
5246
+ name = name )
5247
+ f .__module__ = cls .__module__
5248
+ return f
5249
+
5250
+
5251
+ def _make_stat_function (cls , name , name1 , name2 , axis_descr , desc , f ):
5242
5252
@Substitution (outname = name , desc = desc , name1 = name1 , name2 = name2 ,
5243
5253
axis_descr = axis_descr )
5244
5254
@Appender (_num_doc )
@@ -5255,11 +5265,10 @@ def stat_func(self, axis=None, skipna=None, level=None, numeric_only=None,
5255
5265
return self ._reduce (f , name , axis = axis , skipna = skipna ,
5256
5266
numeric_only = numeric_only )
5257
5267
5258
- stat_func .__name__ = name
5259
- return stat_func
5268
+ return _set_function_name (stat_func , name , cls )
5260
5269
5261
5270
5262
- def _make_stat_function_ddof (name , name1 , name2 , axis_descr , desc , f ):
5271
+ def _make_stat_function_ddof (cls , name , name1 , name2 , axis_descr , desc , f ):
5263
5272
@Substitution (outname = name , desc = desc , name1 = name1 , name2 = name2 ,
5264
5273
axis_descr = axis_descr )
5265
5274
@Appender (_num_ddof_doc )
@@ -5276,17 +5285,16 @@ def stat_func(self, axis=None, skipna=None, level=None, ddof=1,
5276
5285
return self ._reduce (f , name , axis = axis , numeric_only = numeric_only ,
5277
5286
skipna = skipna , ddof = ddof )
5278
5287
5279
- stat_func .__name__ = name
5280
- return stat_func
5288
+ return _set_function_name (stat_func , name , cls )
5281
5289
5282
5290
5283
- def _make_cum_function (name , name1 , name2 , axis_descr , desc , accum_func ,
5291
+ def _make_cum_function (cls , name , name1 , name2 , axis_descr , desc , accum_func ,
5284
5292
mask_a , mask_b ):
5285
5293
@Substitution (outname = name , desc = desc , name1 = name1 , name2 = name2 ,
5286
5294
axis_descr = axis_descr )
5287
5295
@Appender ("Return cumulative {0} over requested axis." .format (name ) +
5288
5296
_cnum_doc )
5289
- def func (self , axis = None , dtype = None , out = None , skipna = True , ** kwargs ):
5297
+ def cum_func (self , axis = None , dtype = None , out = None , skipna = True , ** kwargs ):
5290
5298
validate_kwargs (name , kwargs , 'out' , 'dtype' )
5291
5299
if axis is None :
5292
5300
axis = self ._stat_axis_number
@@ -5312,11 +5320,10 @@ def func(self, axis=None, dtype=None, out=None, skipna=True, **kwargs):
5312
5320
d ['copy' ] = False
5313
5321
return self ._constructor (result , ** d ).__finalize__ (self )
5314
5322
5315
- func .__name__ = name
5316
- return func
5323
+ return _set_function_name (cum_func , name , cls )
5317
5324
5318
5325
5319
- def _make_logical_function (name , name1 , name2 , axis_descr , desc , f ):
5326
+ def _make_logical_function (cls , name , name1 , name2 , axis_descr , desc , f ):
5320
5327
@Substitution (outname = name , desc = desc , name1 = name1 , name2 = name2 ,
5321
5328
axis_descr = axis_descr )
5322
5329
@Appender (_bool_doc )
@@ -5337,8 +5344,8 @@ def logical_func(self, axis=None, bool_only=None, skipna=None, level=None,
5337
5344
numeric_only = bool_only , filter_type = 'bool' ,
5338
5345
name = name )
5339
5346
5340
- logical_func . __name__ = name
5341
- return logical_func
5347
+ return _set_function_name ( logical_func , name , cls )
5348
+
5342
5349
5343
5350
# install the indexes
5344
5351
for _name , _indexer in indexing .get_indexers_list ():
0 commit comments