Skip to content

DataFrame.from_records doesn't get dtype from empty ndarray #3682

Closed
@burdanov

Description

@burdanov
a = np.array([(1, 2)], dtype=[('id', np.int64), ('value', np.int64)])
df = pd.DataFrame.from_records(a, index='id') # ok

b = np.array([], dtype=[('id', np.int64), ('value', np.int64)])
df = pd.DataFrame.from_records(b, index='id') # KeyError: 'id'

The cause is _to_arrays checks for empty data before understanding that ndarray was passed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

        翻译: