|
42 | 42 | from pandas.core.categorical import Categorical
|
43 | 43 | from pandas.core.frame import DataFrame
|
44 | 44 | from pandas.core.generic import NDFrame
|
45 |
| -from pandas.core.index import (Index, MultiIndex, CategoricalIndex, |
46 |
| - _ensure_index) |
| 45 | +from pandas.core.interval import IntervalIndex |
47 | 46 | from pandas.core.internals import BlockManager, make_block
|
48 | 47 | from pandas.core.series import Series
|
49 | 48 | from pandas.core.panel import Panel
|
@@ -3086,12 +3085,20 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3086 | 3085 | if bins is None:
|
3087 | 3086 | lab, lev = algos.factorize(val, sort=True)
|
3088 | 3087 | else:
|
3089 |
| - cat, bins = cut(val, bins, retbins=True) |
| 3088 | + raise NotImplementedError('this is broken') |
| 3089 | + lab, bins = cut(val, bins, retbins=True) |
3090 | 3090 | # bins[:-1] for backward compat;
|
3091 | 3091 | # o.w. cat.categories could be better
|
3092 |
| - lab, lev, dropna = cat.codes, bins[:-1], False |
3093 |
| - |
3094 |
| - sorter = np.lexsort((lab, ids)) |
| 3092 | + # cat = Categorical(cat) |
| 3093 | + # lab, lev, dropna = cat.codes, bins[:-1], False |
| 3094 | + |
| 3095 | + if (lab.dtype == object |
| 3096 | + and lib.is_interval_array_fixed_closed(lab[notnull(lab)])): |
| 3097 | + lab_index = Index(lab) |
| 3098 | + assert isinstance(lab, IntervalIndex) |
| 3099 | + sorter = np.lexsort((lab_index.left, lab_index.right, ids)) |
| 3100 | + else: |
| 3101 | + sorter = np.lexsort((lab, ids)) |
3095 | 3102 | ids, lab = ids[sorter], lab[sorter]
|
3096 | 3103 |
|
3097 | 3104 | # group boundaries are where group ids change
|
@@ -3132,12 +3139,13 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3132 | 3139 | acc = rep(d)
|
3133 | 3140 | out /= acc
|
3134 | 3141 |
|
3135 |
| - if sort and bins is None: |
| 3142 | + if sort: # and bins is None: |
3136 | 3143 | cat = ids[inc][mask] if dropna else ids[inc]
|
3137 | 3144 | sorter = np.lexsort((out if ascending else -out, cat))
|
3138 | 3145 | out, labels[-1] = out[sorter], labels[-1][sorter]
|
3139 | 3146 |
|
3140 |
| - if bins is None: |
| 3147 | + # if bins is None: |
| 3148 | + if True: |
3141 | 3149 | mi = MultiIndex(levels=levels, labels=labels, names=names,
|
3142 | 3150 | verify_integrity=False)
|
3143 | 3151 |
|
|
0 commit comments