|
43 | 43 | from pandas.core.categorical import Categorical
|
44 | 44 | from pandas.core.frame import DataFrame
|
45 | 45 | from pandas.core.generic import NDFrame
|
46 |
| -from pandas.core.index import (Index, MultiIndex, CategoricalIndex, |
47 |
| - _ensure_index) |
| 46 | +from pandas.core.interval import IntervalIndex |
48 | 47 | from pandas.core.internals import BlockManager, make_block
|
49 | 48 | from pandas.core.series import Series
|
50 | 49 | from pandas.core.panel import Panel
|
@@ -3146,12 +3145,20 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3146 | 3145 | if bins is None:
|
3147 | 3146 | lab, lev = algorithms.factorize(val, sort=True)
|
3148 | 3147 | else:
|
3149 |
| - cat, bins = cut(val, bins, retbins=True) |
| 3148 | + raise NotImplementedError('this is broken') |
| 3149 | + lab, bins = cut(val, bins, retbins=True) |
3150 | 3150 | # bins[:-1] for backward compat;
|
3151 | 3151 | # o.w. cat.categories could be better
|
3152 |
| - lab, lev, dropna = cat.codes, bins[:-1], False |
3153 |
| - |
3154 |
| - sorter = np.lexsort((lab, ids)) |
| 3152 | + # cat = Categorical(cat) |
| 3153 | + # lab, lev, dropna = cat.codes, bins[:-1], False |
| 3154 | + |
| 3155 | + if (lab.dtype == object |
| 3156 | + and lib.is_interval_array_fixed_closed(lab[notnull(lab)])): |
| 3157 | + lab_index = Index(lab) |
| 3158 | + assert isinstance(lab, IntervalIndex) |
| 3159 | + sorter = np.lexsort((lab_index.left, lab_index.right, ids)) |
| 3160 | + else: |
| 3161 | + sorter = np.lexsort((lab, ids)) |
3155 | 3162 | ids, lab = ids[sorter], lab[sorter]
|
3156 | 3163 |
|
3157 | 3164 | # group boundaries are where group ids change
|
@@ -3192,12 +3199,13 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3192 | 3199 | acc = rep(d)
|
3193 | 3200 | out /= acc
|
3194 | 3201 |
|
3195 |
| - if sort and bins is None: |
| 3202 | + if sort: # and bins is None: |
3196 | 3203 | cat = ids[inc][mask] if dropna else ids[inc]
|
3197 | 3204 | sorter = np.lexsort((out if ascending else -out, cat))
|
3198 | 3205 | out, labels[-1] = out[sorter], labels[-1][sorter]
|
3199 | 3206 |
|
3200 |
| - if bins is None: |
| 3207 | + # if bins is None: |
| 3208 | + if True: |
3201 | 3209 | mi = MultiIndex(levels=levels, labels=labels, names=names,
|
3202 | 3210 | verify_integrity=False)
|
3203 | 3211 |
|
|
0 commit comments