Skip to content

BUG: __getitem__ with boolean type #10607

Closed
@felixlaumon

Description

@felixlaumon

If a series contains boolean data, value_counts() do not return the count in the descending order. However the counts are correct if accessing through iloc. I supposed that is because 0 is cast into False and 1 is cast into True?

import pandas as pd

str_series = pd.Series(['f', 'f', 't', 't', 't'])
bool_series = pd.Series([False, False, True, True, True])

counts = bool_series.value_counts()
assert counts.index[0] == True
assert counts.index[1] == False
assert counts[0] == 3 # counts[0] is actually 2
assert counts[1] == 2 # counts[1] is actually 3

counts = bool_series.value_counts()
assert counts.index[0] == True
assert counts.index[1] == False
assert counts.iloc[0] == 3 # this works
assert counts.iloc[1] == 2 # this works

counts = str_series.value_counts()
assert counts.index[0] == 't'
assert counts.index[1] == 'f'
assert counts[0] == 3
assert counts[1] == 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions