|
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
|
@@ -3072,12 +3071,20 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3072 | 3071 | if bins is None:
|
3073 | 3072 | lab, lev = algorithms.factorize(val, sort=True)
|
3074 | 3073 | else:
|
3075 |
| - cat, bins = cut(val, bins, retbins=True) |
| 3074 | + raise NotImplementedError('this is broken') |
| 3075 | + lab, bins = cut(val, bins, retbins=True) |
3076 | 3076 | # bins[:-1] for backward compat;
|
3077 | 3077 | # o.w. cat.categories could be better
|
3078 |
| - lab, lev, dropna = cat.codes, bins[:-1], False |
3079 |
| - |
3080 |
| - sorter = np.lexsort((lab, ids)) |
| 3078 | + # cat = Categorical(cat) |
| 3079 | + # lab, lev, dropna = cat.codes, bins[:-1], False |
| 3080 | + |
| 3081 | + if (lab.dtype == object |
| 3082 | + and lib.is_interval_array_fixed_closed(lab[notnull(lab)])): |
| 3083 | + lab_index = Index(lab) |
| 3084 | + assert isinstance(lab, IntervalIndex) |
| 3085 | + sorter = np.lexsort((lab_index.left, lab_index.right, ids)) |
| 3086 | + else: |
| 3087 | + sorter = np.lexsort((lab, ids)) |
3081 | 3088 | ids, lab = ids[sorter], lab[sorter]
|
3082 | 3089 |
|
3083 | 3090 | # group boundaries are where group ids change
|
@@ -3118,12 +3125,13 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3118 | 3125 | acc = rep(d)
|
3119 | 3126 | out /= acc
|
3120 | 3127 |
|
3121 |
| - if sort and bins is None: |
| 3128 | + if sort: # and bins is None: |
3122 | 3129 | cat = ids[inc][mask] if dropna else ids[inc]
|
3123 | 3130 | sorter = np.lexsort((out if ascending else -out, cat))
|
3124 | 3131 | out, labels[-1] = out[sorter], labels[-1][sorter]
|
3125 | 3132 |
|
3126 |
| - if bins is None: |
| 3133 | + # if bins is None: |
| 3134 | + if True: |
3127 | 3135 | mi = MultiIndex(levels=levels, labels=labels, names=names,
|
3128 | 3136 | verify_integrity=False)
|
3129 | 3137 |
|
|
0 commit comments