Skip to content

Adjust Bool evaluation for empty DataFrames to match PEP8 #6964

Closed
@tstriker

Description

@tstriker

Right now, as per the gotchas section, pandas raises a value error on an empty frame
http://pandas.pydata.org/pandas-docs/dev/gotchas.html#gotchas-truth

While documentation describes ambiguity, in the python world there is none.
PEP8 (http://legacy.python.org/dev/peps/pep-0008/) recommends: "For sequences, (strings, lists, tuples), use the fact that empty sequences are false."

The check returns False for None and empty values for all iterables. Further, there are any (https://docs.python.org/2/library/functions.html#any) and all(https://docs.python.org/2/library/functions.html#all) functions for the proposed ambiguity checks.

As currently it's just raising a ValueError, fixing the problem to correctly evaluate representing DataFrame.empty would be backwards compatible.

The check becomes important when working in a mixed environment with pandas and other structures - a simple if foo can become as convoluted as
empty = foo.empty() if (foo is not None and isinstance(foo, pd.DataFrame)) else not foo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions