|
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
|
@@ -3059,12 +3058,20 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3059 | 3058 | if bins is None:
|
3060 | 3059 | lab, lev = algorithms.factorize(val, sort=True)
|
3061 | 3060 | else:
|
3062 |
| - cat, bins = cut(val, bins, retbins=True) |
| 3061 | + raise NotImplementedError('this is broken') |
| 3062 | + lab, bins = cut(val, bins, retbins=True) |
3063 | 3063 | # bins[:-1] for backward compat;
|
3064 | 3064 | # o.w. cat.categories could be better
|
3065 |
| - lab, lev, dropna = cat.codes, bins[:-1], False |
3066 |
| - |
3067 |
| - sorter = np.lexsort((lab, ids)) |
| 3065 | + # cat = Categorical(cat) |
| 3066 | + # lab, lev, dropna = cat.codes, bins[:-1], False |
| 3067 | + |
| 3068 | + if (lab.dtype == object |
| 3069 | + and lib.is_interval_array_fixed_closed(lab[notnull(lab)])): |
| 3070 | + lab_index = Index(lab) |
| 3071 | + assert isinstance(lab, IntervalIndex) |
| 3072 | + sorter = np.lexsort((lab_index.left, lab_index.right, ids)) |
| 3073 | + else: |
| 3074 | + sorter = np.lexsort((lab, ids)) |
3068 | 3075 | ids, lab = ids[sorter], lab[sorter]
|
3069 | 3076 |
|
3070 | 3077 | # group boundaries are where group ids change
|
@@ -3105,12 +3112,13 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3105 | 3112 | acc = rep(d)
|
3106 | 3113 | out /= acc
|
3107 | 3114 |
|
3108 |
| - if sort and bins is None: |
| 3115 | + if sort: # and bins is None: |
3109 | 3116 | cat = ids[inc][mask] if dropna else ids[inc]
|
3110 | 3117 | sorter = np.lexsort((out if ascending else -out, cat))
|
3111 | 3118 | out, labels[-1] = out[sorter], labels[-1][sorter]
|
3112 | 3119 |
|
3113 |
| - if bins is None: |
| 3120 | + # if bins is None: |
| 3121 | + if True: |
3114 | 3122 | mi = MultiIndex(levels=levels, labels=labels, names=names,
|
3115 | 3123 | verify_integrity=False)
|
3116 | 3124 |
|
|
0 commit comments