|
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
|
@@ -3127,12 +3126,20 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3127 | 3126 | if bins is None:
|
3128 | 3127 | lab, lev = algorithms.factorize(val, sort=True)
|
3129 | 3128 | else:
|
3130 |
| - cat, bins = cut(val, bins, retbins=True) |
| 3129 | + raise NotImplementedError('this is broken') |
| 3130 | + lab, bins = cut(val, bins, retbins=True) |
3131 | 3131 | # bins[:-1] for backward compat;
|
3132 | 3132 | # o.w. cat.categories could be better
|
3133 |
| - lab, lev, dropna = cat.codes, bins[:-1], False |
3134 |
| - |
3135 |
| - sorter = np.lexsort((lab, ids)) |
| 3133 | + # cat = Categorical(cat) |
| 3134 | + # lab, lev, dropna = cat.codes, bins[:-1], False |
| 3135 | + |
| 3136 | + if (lab.dtype == object |
| 3137 | + and lib.is_interval_array_fixed_closed(lab[notnull(lab)])): |
| 3138 | + lab_index = Index(lab) |
| 3139 | + assert isinstance(lab, IntervalIndex) |
| 3140 | + sorter = np.lexsort((lab_index.left, lab_index.right, ids)) |
| 3141 | + else: |
| 3142 | + sorter = np.lexsort((lab, ids)) |
3136 | 3143 | ids, lab = ids[sorter], lab[sorter]
|
3137 | 3144 |
|
3138 | 3145 | # group boundaries are where group ids change
|
@@ -3173,12 +3180,13 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3173 | 3180 | acc = rep(d)
|
3174 | 3181 | out /= acc
|
3175 | 3182 |
|
3176 |
| - if sort and bins is None: |
| 3183 | + if sort: # and bins is None: |
3177 | 3184 | cat = ids[inc][mask] if dropna else ids[inc]
|
3178 | 3185 | sorter = np.lexsort((out if ascending else -out, cat))
|
3179 | 3186 | out, labels[-1] = out[sorter], labels[-1][sorter]
|
3180 | 3187 |
|
3181 |
| - if bins is None: |
| 3188 | + # if bins is None: |
| 3189 | + if True: |
3182 | 3190 | mi = MultiIndex(levels=levels, labels=labels, names=names,
|
3183 | 3191 | verify_integrity=False)
|
3184 | 3192 |
|
|
0 commit comments