PERF: PeriodIndex speed up
State: closed

 - [x] closes #https://github.com/pandas-dev/pandas/issues/14822
 - [x] tests added / passed
 - [x] passes ``git diff upstream/master | flake8 --diff``
 - [x] whatsnew entry


Labels:
name: Performance
description: Memory or execution speed performance
name: Period
description: Period data type

Comments:
great! pls add a whatsnew note. and if you can post the asv results would be great.
```
    before     after       ratio
  [3ccb5013] [13aa1309]
+    4.48ms     6.10ms      1.36  period.period_standard_indexing.time_shape
-  659.85μs   572.45μs      0.87  period.period_standard_indexing.time_intersection
-  258.36μs   166.30μs      0.64  period.period_standard_indexing.time_series_loc
-  135.68μs    48.90μs      0.36  period.period_standard_indexing.time_get_loc
-    3.95ms    31.21μs      0.01  period.period_standard_indexing.time_shallow_copy
```

This is before the Shape change. 

Current branch is v fast:
```python
In [5]: index = pd.PeriodIndex(start=2000, periods=20000, freq='B')

In [7]: %timeit -n 1 -r 1 index.shape
1 loop, best of 1: 12.2 µs per loop
```

Re-running ASV now (doesn't seem easy to do a quick dev run...)
@MaximilianR that's fine. maybe needs np.random.seed to be set (to make it consitent). but no big deal.
lgtm. ping on green.
```
======================================================================
FAIL: test_getitem_ndim2 (pandas.tseries.tests.test_period.TestPeriodIndex)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27_64\envs\pandas\lib\site-packages\pandas\tseries\tests\test_period.py", line 2110, in test_getitem_ndim2
    self.assertEqual(result.shape, (len(idx), ))
AssertionError: Tuples differ: (3L, 1L) != (3,)
First tuple contains 1 additional elements.
First extra element 1:
1L
- (3L, 1L)
+ (3,)
------------------
```
I'll look
Any idea why this is here? Creating another axis on an index?

```
   2104     def test_getitem_ndim2(self):
   2105         idx = period_range('2007-01', periods=3, freq='M')
   2106
   2107         result = idx[:, None]
   2108         # MPL kludge, internally has incorrect shape
   2109         tm.assertIsInstance(result, PeriodIndex)
-> 2110         self.assertEqual(result.shape, (len(idx), ))
```
Weird but different things happen with other indexes:

```python

In [7]: pd.DatetimeIndex(start='2000', periods=10, freq='B')
Out[7]:
DatetimeIndex(['2000-01-03', '2000-01-04', '2000-01-05', '2000-01-06',
               '2000-01-07', '2000-01-10', '2000-01-11', '2000-01-12',
               '2000-01-13', '2000-01-14'],
              dtype='datetime64[ns]', freq='B')

In [8]: pd.DatetimeIndex(start='2000', periods=10, freq='B')[:, None].shape
Out[8]: (10, 1)

In [9]: pd.DatetimeIndex(start='2000', periods=10, freq='B')[:, None]
Out[9]:
array([['2000-01-03T00:00:00.000000000'],
       ['2000-01-04T00:00:00.000000000'],
       ['2000-01-05T00:00:00.000000000'],
       ['2000-01-06T00:00:00.000000000'],
       ['2000-01-07T00:00:00.000000000'],
       ['2000-01-10T00:00:00.000000000'],
       ['2000-01-11T00:00:00.000000000'],
       ['2000-01-12T00:00:00.000000000'],
       ['2000-01-13T00:00:00.000000000'],
       ['2000-01-14T00:00:00.000000000']], dtype='datetime64[ns]')

In [10]: pd.DatetimeIndex(start='2000', periods=10, freq='B').shape
Out[10]: (10,)
```
this is a bit bogus, but I suspect this is in there for some matplotib compat (we pass periods to it I think for it to display some things).
It's only changing the output of `.shape` - nothing else. This is from master:

```python
In [3]: pd.PeriodIndex(start='2000', periods=10, freq='B')[:, None].shape
Out[3]: (10,)

In [4]: pd.PeriodIndex(start='2000', periods=10, freq='B')[:, None].values.shape
Out[4]: (10,)

In [5]: pd.PeriodIndex(start='2000', periods=10, freq='B')[:, None]._values.shape
Out[5]: (10, 1)
```

I can hack change `.shape` to only look at the first dimension, or if nothing else fails are you OK taking that test out?
ok taking the test out, if all plotting things pass (iow everything else is ok).

## [Current coverage](https://codecov.io/gh/pandas-dev/pandas/pull/14931?src=pr) is 84.64% (diff: 100%)
> Merging [#14931](https://codecov.io/gh/pandas-dev/pandas/pull/14931?src=pr) into [master](https://codecov.io/gh/pandas-dev/pandas/branch/master?src=pr) will decrease coverage by **<.01%**

```diff
@@             master     #14931   diff @@
==========================================
  Files           144        144          
  Lines         51023      51025     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43190      43191     +1   
- Misses         7833       7834     +1   
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [3ab369c...72b14aa](https://codecov.io/gh/pandas-dev/pandas/compare/3ab369ca6da880285fd75e555bc3d3b150067bff...72b14aab87dafb949d9348feaf9cb6d1bde95eff?src=pr)
thanks!