|
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
|
@@ -3092,12 +3091,20 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3092 | 3091 | if bins is None:
|
3093 | 3092 | lab, lev = algorithms.factorize(val, sort=True)
|
3094 | 3093 | else:
|
3095 |
| - cat, bins = cut(val, bins, retbins=True) |
| 3094 | + raise NotImplementedError('this is broken') |
| 3095 | + lab, bins = cut(val, bins, retbins=True) |
3096 | 3096 | # bins[:-1] for backward compat;
|
3097 | 3097 | # o.w. cat.categories could be better
|
3098 |
| - lab, lev, dropna = cat.codes, bins[:-1], False |
3099 |
| - |
3100 |
| - sorter = np.lexsort((lab, ids)) |
| 3098 | + # cat = Categorical(cat) |
| 3099 | + # lab, lev, dropna = cat.codes, bins[:-1], False |
| 3100 | + |
| 3101 | + if (lab.dtype == object |
| 3102 | + and lib.is_interval_array_fixed_closed(lab[notnull(lab)])): |
| 3103 | + lab_index = Index(lab) |
| 3104 | + assert isinstance(lab, IntervalIndex) |
| 3105 | + sorter = np.lexsort((lab_index.left, lab_index.right, ids)) |
| 3106 | + else: |
| 3107 | + sorter = np.lexsort((lab, ids)) |
3101 | 3108 | ids, lab = ids[sorter], lab[sorter]
|
3102 | 3109 |
|
3103 | 3110 | # group boundaries are where group ids change
|
@@ -3138,12 +3145,13 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3138 | 3145 | acc = rep(d)
|
3139 | 3146 | out /= acc
|
3140 | 3147 |
|
3141 |
| - if sort and bins is None: |
| 3148 | + if sort: # and bins is None: |
3142 | 3149 | cat = ids[inc][mask] if dropna else ids[inc]
|
3143 | 3150 | sorter = np.lexsort((out if ascending else -out, cat))
|
3144 | 3151 | out, labels[-1] = out[sorter], labels[-1][sorter]
|
3145 | 3152 |
|
3146 |
| - if bins is None: |
| 3153 | + # if bins is None: |
| 3154 | + if True: |
3147 | 3155 | mi = MultiIndex(levels=levels, labels=labels, names=names,
|
3148 | 3156 | verify_integrity=False)
|
3149 | 3157 |
|
|
0 commit comments