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