use liboffsets to_offset function
State: closed


Labels:
name: Frequency
description: DateOffsets
name: Clean

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21693?src=pr&el=h1) Report
> Merging [#21693](https://codecov.io/gh/pandas-dev/pandas/pull/21693?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/dc45fbafef172e357cb5decdeab22de67160f5b7?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/21693/graphs/tree.svg?token=eZ4WkYLtcO&width=650&src=pr&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/21693?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #21693   +/-   ##
=======================================
  Coverage    91.9%    91.9%           
=======================================
  Files         154      154           
  Lines       49657    49657           
=======================================
  Hits        45638    45638           
  Misses       4019     4019
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.28% <ø> (ø)` | :arrow_up: |
| #single | `41.9% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21693?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21693?src=pr&el=footer). Last update [dc45fba...b2fa7cb](https://codecov.io/gh/pandas-dev/pandas/pull/21693?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks!
While investigating general `Period` slowness, an `asv find` bisection identified this PR as introducing a ~56x slowdown on Windows 10:
```
asv find v0.23.4..24ab22f75a groupby.Datelike.time_sum
[...]
·· For pandas commit dc45fbaf <master~690>:
·· Uninstalling from conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
·· Building dc45fbaf <master~690> for conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
·· Installing dc45fbaf <master~690> into conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
·· Benchmarking conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
··· Running (groupby.Datelike.time_sum--).
··· groupby.Datelike.time_sum                                                                                                                                                   ok
··· =============== ==========
        grouper
    --------------- ----------
      period_range   46.9±8ms
       date_range    3.12±0ms
     date_range_tz   3.91±1ms
    =============== ==========

· Testing ------------O-----------------------------------------------
·· For pandas commit d105ce26 <master~689>:
·· Uninstalling from conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
·· Building d105ce26 <master~689> for conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
·· Installing d105ce26 <master~689> into conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
·· Benchmarking conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
··· Running (groupby.Datelike.time_sum--).
··· groupby.Datelike.time_sum                                                                                                                                                   ok
··· =============== ===========
        grouper
    --------------- -----------
      period_range   2.63±0.3s
       date_range     3.12±0ms
     date_range_tz    3.12±0ms
    =============== ===========

· Greatest regression found: d105ce26 <master~689>
```

My suspicion is the moving of `from pandas.tseries.frequencies import to_offset` from `period.pyx` module scope into `offset.pyx` in function scope is leading to this slowdown on Windows.
Thanks for tracking this down.  A couple questions: is there anything weird about your Windows environment, e.g. running on top of cygwin or something?  Or more generally since I don't use Windows, any other reason why your system might be special?  Long-shot since you're already doing a lot here: can you reproduce these results on non-Windows?

If you re-run the same asv a few times, are the results pretty consistent?  Often asv results can have a lot of noise.
- Nothing unusual from a Windows perspective: relatively clean Windows 10 install with benchmarks run under PowerShell. Only standard antivirus, with benchmarks excluded from AV checks.
- None that come to mind, actually did a fresh install a few months back due to upgrading the SSD and strictly used this machine for remote desktop until recently (so very little installed on it).
- Actually, it also looks like the trend is visible on my Ubuntu 18.04 machine, so seems like it might be a cross-platform issue. Haven't run a bisection yet, but could this evening.

And yes, sadly consistent.