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