CLN/MAINT: Clean and annotate stata reader and writers
State: closed

- [X] passes `black pandas`
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`



Labels:
name: IO Stata
description: read_stata, to_stata
name: Typing
description: type annotations, mypy/pyright type checking

Comments:
Hello @bashtage! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:









There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2020-01-24 10:35:54 UTC
Thanks @simonjayhawkins .  I've hit a roadblock with the errors below. Is there anything that can be done about them?

```
pandas/io/stata.py:244: error: Unsupported operand types for * ("int" and "Series")
pandas/io/stata.py:244: error: Unsupported operand types for + ("int" and "Series")
pandas/io/stata.py:289: error: Incompatible return value type (got "datetime", expected "Series")
pandas/io/stata.py:289: error: Unsupported operand types for + ("datetime" and "Series")
pandas/io/stata.py:320: error: Unsupported operand types for // ("Series" and "int")
pandas/io/stata.py:321: error: Incompatible types in assignment (expression has type "int", variable has type "Series")
pandas/io/stata.py:321: error: Unsupported operand types for % ("Series" and "int")
pandas/io/stata.py:322: error: Argument 1 to "convert_year_days_safe" has incompatible type "int"; expected "Series"
pandas/io/stata.py:324: error: Unsupported operand types for // ("Series" and "int")
pandas/io/stata.py:325: error: Unsupported operand types for % ("Series" and "int")
pandas/io/stata.py:326: error: Argument 1 to "convert_year_month_safe" has incompatible type "int"; expected "Series"
pandas/io/stata.py:326: error: Argument 2 to "convert_year_month_safe" has incompatible type "int"; expected "Series"
pandas/io/stata.py:328: error: Unsupported operand types for // ("Series" and "int")
pandas/io/stata.py:329: error: Incompatible types in assignment (expression has type "int", variable has type "Series")
pandas/io/stata.py:329: error: Unsupported operand types for % ("Series" and "int")
pandas/io/stata.py:330: error: Argument 1 to "convert_year_month_safe" has incompatible type "int"; expected "Series"
pandas/io/stata.py:332: error: Unsupported operand types for // ("Series" and "int")
pandas/io/stata.py:333: error: Unsupported operand types for % ("Series" and "int")
pandas/io/stata.py:334: error: Argument 1 to "convert_year_month_safe" has incompatible type "int"; expected "Series"
pandas/io/stata.py:334: error: Argument 2 to "convert_year_month_safe" has incompatible type "int"; expected "Series"
pandas/io/stata.py:336: error: Incompatible types in assignment (expression has type "Series", variable has type "int")
pandas/io/stata.py:338: error: Argument 1 to "convert_year_month_safe" has incompatible type "int"; expected "Series"
pandas/io/stata.py:370: error: Unsupported left operand type for - ("Series")
pandas/io/stata.py:371: error: "bool" has no attribute "values"
pandas/io/stata.py:374: error: "DatetimeIndex" has no attribute "year"
pandas/io/stata.py:374: error: "DatetimeIndex" has no attribute "month"
```


> Thanks @simonjayhawkins . I've hit a roadblock with the errors below. Is there anything that can be done about them?

I'll pull this locally and have a look in a bit.

Any idea how the final block can be typed?  Or should I just remove the typing information from this function?
> Any idea how the final block can be typed? Or should I just remove the typing information from this function?

cc @simonjayhawkins @WillAyd 
I think the mypy issues are a result of the arithmetic ops for pandas objects being defined at runtime and not statically. I opened #31160 to track

As far as this PR is concerned I would remove annotations from those functions or `type: ignore` failing lines, depending on which is easier for you
All green now. I requested a rereview to see if this can get across the line. 
@jreback Green. I squashed to two distinct commits, one for the typing and one for the final bare pytest raises. 
thanks @bashtage very nice!
> @jreback Green. I squashed to two distinct commits, one for the typing and one for the final bare pytest raises.

great, though when we merge it gets squashed to one :-> (but history is preserved on this PR)