Skip to content

ENH: Make concat succeed on empty list. #40820

@frobnitzem

Description

@frobnitzem

Is your feature request related to a problem?

Yes, pd.concat([]) currently raises the exception, ValueError("No objects to concatenate").

Describe the solution you'd like

To be correct on all input sizes, it should return an empty DataFrame.

API breaking implications

Obviously, concat will no longer detect empty data. However, empty data will detect itself.

Additional context

The concatenation operation is for lists what addition is for numbers. Concatenation of an empty list should produce an empty dataframe, because the empty dataframe represents 0. Consider

sum([])

which python evaluates to 0.

This makes concatenation and sum commute, sum([1] + []) == sum([1]) + sum([]).

This already works for an empty dataframe:

pd.concat([pd.DataFrame({'A':[1]}), pd.DataFrame()])

if is very odd for concat([]) not to produce a DataFrame, since its input has the correct type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions