Skip to content

API/PERF/BUG: infer dtypes when enlarging #9521

Closed
@jreback

Description

@jreback

So this can be fixed by inferring after the set. We need to do this because we first set the value to a null-type (nan/NaT), then set the value. This works fine for datetime/timedelta/floats/strings, but not for integers which get set as float.

However, this can be an expensive operation as potentially the entire column needs to be scaned for nulls.

In [4]: df = pd.DataFrame()

In [5]: df.loc[1,'foo'] = 2

In [6]: df
Out[6]: 
   foo
1    2

In [7]: df.dtypes
Out[7]: 
foo    float64
dtype: object

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions