Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERF: Speeds up creation of Period, PeriodArray, with Offset freq #23589

Merged
merged 3 commits into from
Nov 9, 2018

Commits on Nov 9, 2018

  1. PERF: Speeds up creation of Period, PeriodArray, with Offset freq

    master:
    
    ```python
    In [2]: freq = pd.tseries.offsets.Day()
       ...:
       ...: %timeit pd.Period("2001", freq=freq)
    
    294 µs ± 5.53 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
    
    In [3]: %timeit pd.Period._maybe_convert_freq(freq)
       ...:
    64.7 µs ± 382 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    ```
    
    branch:
    
    ```python
    In [2]: freq = pd.tseries.offsets.Day()
       ...:
       ...: %timeit pd.Period("2001", freq=freq)
    
    158 µs ± 2.87 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    
    In [3]: %timeit pd.Period._maybe_convert_freq(freq)
    193 ns ± 4.3 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
    ```
    
    While looking at the profile plot in snakeviz, it seems like a lot of time in
    Period._maybe_convert_freq was spent importing modules. `_maybe_convert_freq`
    calls `offsets.to_offset`, which imports a Python function inside the method.
    
    Does Cython not handle this well?
    TomAugspurger committed Nov 9, 2018
    Configuration menu
    Copy the full SHA
    fa3fc63 View commit details
    Browse the repository at this point in the history
  2. move to to_offset

    TomAugspurger committed Nov 9, 2018
    Configuration menu
    Copy the full SHA
    8daba2c View commit details
    Browse the repository at this point in the history
  3. fixup

    TomAugspurger committed Nov 9, 2018
    Configuration menu
    Copy the full SHA
    795a7d1 View commit details
    Browse the repository at this point in the history