PERF: Implement get_freq_code in cython frequencies
State: closed

There's a whole bunch of `tseries.frequencies` and `tseries.offsets` that should be moved into cython to improve `Period` (and `PeriodIndex, and to a lesser extend `Timestamp`) performance.  This PR just starts with the function `get_freq_code`.

To keep the PR small, there are a bunch of things it _doesnt_ do that can further improve things in follow-ups:
 - Nothing is cdef'd or declared in a pxd file
 - `_libs.period` still gets `get_freq_code` from `tseries.frequencies` instead of directly from `tslibs.frequencies`
 - A handful of now-duplicate constants in `tseries.frequencies` are not removed.

```
In [6]: per = pd.Period.now('min')
In [7]: %timeit per.month
```
Before:
```
The slowest run took 15.03 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 1.4 µs per loop
```
After:
```
The slowest run took 25.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 744 ns per loop
```

- [ ] closes #xxxx
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Performance
description: Memory or execution speed performance
name: Internals
description: Related to non-user accessible pandas implementation
name: Frequency
description: DateOffsets
name: Clean

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=h1) Report
> Merging [#17422](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/1981b679b0619de0765c2009684ce4abd886189d?src=pr&el=desc) will **decrease** coverage by `0.02%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #17422      +/-   ##
==========================================
- Coverage   91.15%   91.13%   -0.03%     
==========================================
  Files         163      163              
  Lines       49581    49552      -29     
==========================================
- Hits        45198    45161      -37     
- Misses       4383     4391       +8
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.92% <100%> (-0.01%)` | :arrow_down: |
| #single | `40.24% <100%> (-0.08%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/tseries/frequencies.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvZnJlcXVlbmNpZXMucHk=) | `96.31% <100%> (-0.2%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.43% <0%> (+0.09%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17422?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/17422?src=pr&el=footer). Last update [1981b67...f48c5c3](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=h1) Report
> Merging [#17422](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/1981b679b0619de0765c2009684ce4abd886189d?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #17422      +/-   ##
==========================================
- Coverage   91.15%   91.14%   -0.02%     
==========================================
  Files         163      163              
  Lines       49581    49561      -20     
==========================================
- Hits        45198    45171      -27     
- Misses       4383     4390       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.92% <100%> (-0.01%)` | :arrow_down: |
| #single | `40.23% <100%> (-0.09%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/tseries/frequencies.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvZnJlcXVlbmNpZXMucHk=) | `96.31% <100%> (-0.2%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/io/parquet.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnF1ZXQucHk=) | `65.38% <0%> (-0.37%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `91.98% <0%> (-0.01%)` | :arrow_down: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.29% <0%> (ø)` | :arrow_up: |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `96.9% <0%> (ø)` | :arrow_up: |
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.46% <0%> (ø)` | :arrow_up: |
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `82.69% <0%> (+0.01%)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.52% <0%> (+0.19%)` | :arrow_up: |
| ... and [2 more](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17422?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/17422?src=pr&el=footer). Last update [1981b67...77e2e75](https://codecov.io/gh/pandas-dev/pandas/pull/17422?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

asv is throwing build-time errors.  I've filed an issue there.  For now the timeit results will have to do.
@jorisvandenbossche Any chance you want to play "good cop" here?  I could use some help with asv, see error discussion [here](https://github.com/pandas-dev/pandas/pull/17274#issuecomment-326675088).
@jbrockmendel you need to add asv benchmarks to he code you are pushing 

you are touching highly perf sensistive code and it is very easy to break things
think of these like tests


Just pushed a commit that adds asv checks for Period property lookups.  I can't get asv to run it, would appreciate it if someone else would give it a shot.
> then use cpdef foo(x); don't try to change the existing style in a single PR.

Note that this code was moved from non-cython, so is not changing existing style.  The idea was that where possible, retaining pure-python compatibility would be nice.  But not a big deal, so will change.
Looks like Travis error is an unrelated HTTP timeout.
ok this looks good. just remove that comment and push again to get everything passing. ping on green.
ping.
https://travis-ci.org/pandas-dev/pandas/jobs/272723119 is failing. FYI just because they are in the allowed failing section doesn't mean they actually should fail. this is the build test, which installs like a user, w/o a development build.
Looks like the allowed-fail mentioned earlier is now OK, but the 3.5 OSX is now failing, says it just stalled and received no output for 10 minutes.  The only change since last night's all-green is the entry in the setup.py packages.