File tree 1 file changed +5
-8
lines changed
1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -819,22 +819,19 @@ def value_counts_arraylike(values, dropna: bool):
819
819
# TODO: handle uint8
820
820
f = getattr (htable , f"value_count_{ ndtype } " )
821
821
keys , counts = f (values , dropna )
822
+ # GH 35922. Mimic previous value_counts behavior now that
823
+ # Series.sort_values is stable
824
+ keys = keys [::- 1 ]
825
+ counts = counts [::- 1 ]
822
826
823
827
mask = isna (values )
824
828
if not dropna and mask .any ():
825
829
# GH 35922. Series.sort_values is stable now, so need to
826
- # append NaN counts or move to the end to make sure they are
830
+ # append NaN counts to make sure they are
827
831
# sorted toward the end when calling value_counts
828
832
if not isna (keys ).any ():
829
833
keys = np .append (keys , np .NaN )
830
834
counts = np .append (counts , mask .sum ())
831
- else :
832
- nan_pos = np .where (np .isnan (keys ))
833
- keys [nan_pos ] = keys [- 1 ]
834
- keys [- 1 ] = np .NaN
835
- tmp = counts [nan_pos ]
836
- counts [nan_pos ] = counts [- 1 ]
837
- counts [- 1 ] = tmp
838
835
839
836
keys = _reconstruct_data (keys , original .dtype , original )
840
837
You can’t perform that action at this time.
0 commit comments