Fix type annotations in pandas.core.indexes.period
State: closed

- [x] closes #26517 
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`


Labels:
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Typing
description: type annotations, mypy/pyright type checking

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

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

```diff
@@            Coverage Diff             @@
##           master   #26518      +/-   ##
==========================================
- Coverage   91.76%   91.75%   -0.01%     
==========================================
  Files         174      174              
  Lines       50673    50673              
==========================================
- Hits        46498    46493       -5     
- Misses       4175     4180       +5
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.26% <100%> (ø)` | :arrow_up: |
| #single | `41.7% <100%> (-0.08%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26518?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.58% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.6% <0%> (-0.11%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26518?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/26518?src=pr&el=footer). Last update [374478c...b311b66](https://codecov.io/gh/pandas-dev/pandas/pull/26518?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/26518?src=pr&el=h1) Report
> Merging [#26518](https://codecov.io/gh/pandas-dev/pandas/pull/26518?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/374478cb149f5ebc2dd2efd2145443670bf9733e?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #26518      +/-   ##
==========================================
+ Coverage   91.76%   91.76%   +<.01%     
==========================================
  Files         174      174              
  Lines       50673    50649      -24     
==========================================
- Hits        46498    46478      -20     
+ Misses       4175     4171       -4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.3% <100%> (+0.04%)` | :arrow_up: |
| #single | `41.67% <100%> (-0.12%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26518?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.58% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/io/excel/\_base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsL19iYXNlLnB5) | `91.81% <0%> (-0.33%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.6% <0%> (-0.11%)` | :arrow_down: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `96.85% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/sparse/scipy\_sparse.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL3NjaXB5X3NwYXJzZS5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.61% <0%> (ø)` | :arrow_up: |
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `95.65% <0%> (+0.01%)` | :arrow_up: |
| [pandas/core/sparse/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL3Nlcmllcy5weQ==) | `93.24% <0%> (+0.06%)` | :arrow_up: |
| ... and [5 more](https://codecov.io/gh/pandas-dev/pandas/pull/26518/diff?src=pr&el=tree-more) | |

------

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

@gfyoung yeah, I wanted to do it in #26404 but it got merged before I can make changes.
@WillAyd mypy should give this error:

    pandas\core\indexes\period.py:171: error: Incompatible types in assignment (expression has type "PeriodArray", base class "DatetimeIndexOpsMixin" defined the type as "None")

Can you double check.
I am not getting that error locally nor is it showing in the build. What version of mypy are you using?
Hmm, let me double check.

On Mon, 27 May 2019, 5:31 am William Ayd, <notifications@github.com> wrote:

> I am not getting that error locally nor is it showing in the build. What
> version of mypy are you using?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/26518?email_source=notifications&email_token=AFMJMLFFPBOUUX7NRDK4PVTPXMQFTA5CNFSM4HPTL2JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWIP6BI#issuecomment-496041733>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AFMJMLESB65Q2CBRERGMP53PXMQFTANCNFSM4HPTL2JA>
> .
>

Might be a misunderstanding on my end I didn’t modify mypy.ini before running. Thought this was a continuation of a prior PR but if not that’s probably it. Can check later

Sent from my iPhone

> On May 26, 2019, at 9:34 AM, Vaibhav Vishal <notifications@github.com> wrote:
> 
> @vaibhavhrt commented on this pull request.
> 
> In pandas/core/indexes/period.py:
> 
> > @@ -80,7 +80,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):
>  
>      Parameters
>      ----------
> -    data : array-like (1-dimensional), optional
> +    data : array-like (1-dimensional) - PeriodArray, optional
> data : array-like (1-dimensional integer np.ndarray or PeriodArray), optional, looks good?
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.

`pandas.core.indexes.period` needs to be removed from mypy.ini. I wanted to
fix this error in a previous PR because `pandas.core.indexes.period` had a
lot of other errors too relating to incompatible types which got
automatically solved while trying to fix types in some other file. Just
this one remained so a new PR was not absolutely necessary, but since that
PR(#26404 I think) got merged before I could fix
`pandas.core.indexes.period` too, so a new PR, sorry for the confusion.

On Mon, May 27, 2019 at 6:35 AM William Ayd <notifications@github.com>
wrote:

> Might be a misunderstanding on my end I didn’t modify mypy.ini before
> running. Thought this was a continuation of a prior PR but if not that’s
> probably it. Can check later
>
> Sent from my iPhone
>
> > On May 26, 2019, at 9:34 AM, Vaibhav Vishal <notifications@github.com>
> wrote:
> >
> > @vaibhavhrt commented on this pull request.
> >
> > In pandas/core/indexes/period.py:
> >
> > > @@ -80,7 +80,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index,
> PeriodDelegateMixin):
> >
> > Parameters
> > ----------
> > - data : array-like (1-dimensional), optional
> > + data : array-like (1-dimensional) - PeriodArray, optional
> > data : array-like (1-dimensional integer np.ndarray or PeriodArray),
> optional, looks good?
> >
> > —
> > You are receiving this because you were mentioned.
> > Reply to this email directly, view it on GitHub, or mute the thread.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/26518?email_source=notifications&email_token=AFMJMLCZ6RZW7XVCR3NESCLPXMXWLA5CNFSM4HPTL2JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWIRHXA#issuecomment-496047068>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AFMJMLAWOYH5N2IC5JMTNZTPXMXWLANCNFSM4HPTL2JA>
> .
>

thanks @vaibhavhrt