Skip to content

PERF: fastpath on Period construction from PeriodIndex #5155

Closed
@jreback

Description

@jreback

vbench already in timeseries/period_setitem
very inefficient because on the boxing of the PeriodIndex (to an object index), it recomputes the freq for each Period (even though it is passed), need a fastpath on this type of construction

In [1]: rng = period_range('1/1/1990', freq='S', periods=20000)

In [2]: df = DataFrame(index=range(len(rng)))

In [3]: def f():
   ...:     df['col'] = rng
   ...:     
   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    40000    0.055    0.000    0.095    0.000 abc.py:128(__instancecheck__)
    20000    0.043    0.000    0.345    0.000 period.py:66(__init__)
    20000    0.037    0.000    0.381    0.000 period.py:683(<lambda>)
    80031    0.037    0.000    0.131    0.000 {isinstance}
    20000    0.034    0.000    0.223    0.000 frequencies.py:76(get_freq_code)
    60003    0.029    0.000    0.029    0.000 _weakrefset.py:68(__contains__)
    20000    0.028    0.000    0.063    0.000 frequencies.py:464(_base_and_stride)
    20000    0.028    0.000    0.028    0.000 {method 'match' of '_sre.SRE_Pattern' objects}
    20000    0.027    0.000    0.038    0.000 frequencies.py:767(_period_str_to_code)
    40000    0.023    0.000    0.144    0.000 common.py:1730(is_integer)
        1    0.016    0.016    0.398    0.398 {pandas.lib.map_infer}
    40007    0.010    0.000    0.010    0.000 {getattr}
    20000    0.009    0.000    0.012    0.000 frequencies.py:112(_get_freq_str)
    60000    0.008    0.000    0.008    0.000 {method 'get' of 'dict' objects}
    40000    0.006    0.000    0.006    0.000 {method 'group' of '_sre.SRE_Match' objects}
    20000    0.004    0.000    0.004    0.000 {method 'lower' of 'str' objects}
    20000    0.002    0.000    0.002    0.000 {method 'upper' of 'str' objects}
    20015    0.002    0.000    0.002    0.000 {len}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrequencyDateOffsetsPerformanceMemory or execution speed performancePeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions