Skip to content

ERR: setting a column with a scalar and no index should raise #16823

Closed
@jreback

Description

@jreback

xref #10017 (comment)

This should raise like [5] below.

In [2]: df = DataFrame()

In [3]: df['foo'] = 1

In [4]: df
Out[4]: 
Empty DataFrame
Columns: [foo]
Index: []
In [5]: DataFrame({'foo': 1})
ValueError: If using all scalar values, you must pass an index
I
n [17]: df.loc[1] = 1
\ValueError: cannot set a frame with no defined columns

Even though this is technically valid code (in [4]), IOW the scalar is reindexed to a 0-len index, this immediately loses information This should raise an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasIndexingRelated to indexing on series/frames, not to indexes themselvesReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions