Skip to content

Series(index=DatetimeIndex(...)) constructor very slow #11433

Closed
@lenolib

Description

@lenolib

When instantiating a series with a datetimeindex but no data value (=None), a very slow codepath is used (involving Timestamp creation), compared to if a NaN value is supplied. The results are identical.

dr = pd.date_range(
    start=datetime(2015,10,26),
    end=datetime(2016,1,1),
    freq='10s'
)  # ~500k long
pd.Series(index=dr)  # slow, 2.78 s
pd.Series(np.nan, index=dr)  # fast, 0.01 s

pandas version 0.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypePerformanceMemory or execution speed performance

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions