@@ -1793,17 +1793,25 @@ def indices(self):
1793
1793
def group_info (self ):
1794
1794
ngroups = self .ngroups
1795
1795
obs_group_ids = np .arange (ngroups )
1796
- comp_ids = np .repeat (np .arange (ngroups ), np .diff (np .r_ [0 , self .bins ]))
1796
+ rep = np .diff (np .r_ [0 , self .bins ])
1797
+
1798
+ if ngroups == len (self .bins ):
1799
+ comp_ids = np .repeat (np .arange (ngroups ), rep )
1800
+ else :
1801
+ comp_ids = np .repeat (np .r_ [- 1 , np .arange (ngroups )], rep )
1802
+
1797
1803
return comp_ids , obs_group_ids , ngroups
1798
1804
1799
1805
@cache_readonly
1800
1806
def ngroups (self ):
1801
- return len (self .binlabels )
1807
+ return len (self .result_index )
1802
1808
1803
1809
@cache_readonly
1804
1810
def result_index (self ):
1805
- mask = self .binlabels .asi8 == tslib .iNaT
1806
- return self .binlabels [~ mask ]
1811
+ if len (self .binlabels ) != 0 and isnull (self .binlabels [0 ]):
1812
+ return self .binlabels [1 :]
1813
+
1814
+ return self .binlabels
1807
1815
1808
1816
@property
1809
1817
def levels (self ):
@@ -1839,40 +1847,14 @@ def size(self):
1839
1847
#----------------------------------------------------------------------
1840
1848
# cython aggregation
1841
1849
1842
- _cython_functions = {
1843
- 'add' : 'group_add_bin' ,
1844
- 'prod' : 'group_prod_bin' ,
1845
- 'mean' : 'group_mean_bin' ,
1846
- 'min' : 'group_min_bin' ,
1847
- 'max' : 'group_max_bin' ,
1848
- 'var' : 'group_var_bin' ,
1849
- 'ohlc' : 'group_ohlc' ,
1850
- 'first' : {
1851
- 'name' : 'group_nth_bin' ,
1852
- 'f' : lambda func , a , b , c , d : func (a , b , c , d , 1 )
1853
- },
1854
- 'last' : 'group_last_bin' ,
1855
- 'count' : 'group_count_bin' ,
1856
- }
1850
+ _cython_functions = {'ohlc' : 'group_ohlc' }
1851
+ _cython_functions .update (BaseGrouper ._cython_functions )
1852
+ _cython_functions .pop ('median' )
1857
1853
1858
1854
_name_functions = {
1859
1855
'ohlc' : lambda * args : ['open' , 'high' , 'low' , 'close' ]
1860
1856
}
1861
1857
1862
- def _aggregate (self , result , counts , values , agg_func , is_numeric = True ):
1863
-
1864
- if values .ndim > 3 :
1865
- # punting for now
1866
- raise NotImplementedError ("number of dimensions is currently "
1867
- "limited to 3" )
1868
- elif values .ndim > 2 :
1869
- for i , chunk in enumerate (values .transpose (2 , 0 , 1 )):
1870
- agg_func (result [:, :, i ], counts , chunk , self .bins )
1871
- else :
1872
- agg_func (result , counts , values , self .bins )
1873
-
1874
- return result
1875
-
1876
1858
def agg_series (self , obj , func ):
1877
1859
dummy = obj [:0 ]
1878
1860
grouper = lib .SeriesBinGrouper (obj , func , self .bins , dummy )
0 commit comments