-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLN: [WIP] trial pull-request to make sure everything is in order before proceeding (GH14468) #15866
Conversation
make sure linting is in order, see http://pandas-docs.github.io/pandas-docs-travis/contributing.html#python-pep8 further I'd like to see you add If you show me the commands you are running I can add this (to master), just to get things started. |
Codecov Report
@@ Coverage Diff @@
## master #15866 +/- ##
==========================================
- Coverage 90.98% 90.96% -0.02%
==========================================
Files 143 144 +1
Lines 49449 49457 +8
==========================================
- Hits 44993 44991 -2
- Misses 4456 4466 +10
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #15866 +/- ##
==========================================
+ Coverage 90.39% 90.96% +0.57%
==========================================
Files 161 144 -17
Lines 50863 49457 -1406
==========================================
- Hits 45977 44991 -986
+ Misses 4886 4466 -420
Continue to review full report at Codecov.
|
pandas/types/hinting.py
Outdated
@@ -0,0 +1,10 @@ | |||
#!/usr/bin/env python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need this top line, this is not an executable file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. i must've clicked the wrong file template
@brmc ok I rebase and pushed a couple of commits to auto check this on travis (it fails now but the check is in place). The idea is to make this pass cleanly (and check what you have so far). Then can add other things. Note that you will need to rebase this pretty much every time you push (just in case). As the code base does move. |
pandas/core/base.py
Outdated
@@ -1,10 +1,13 @@ | |||
""" | |||
Base and utility classes for pandas objects. | |||
""" | |||
from typing import Any, Callable, Optional, Tuple, Union |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of doing this directly, move this to pandas.types.hinting.py
and import from there. IOW that will be the 1 place that we inherit typing things from.
we can then handle the compat issues when typing
is not installed (on 2.7).
pandas/core/base.py
Outdated
from pandas import compat | ||
from pandas.compat import builtins | ||
import numpy as np | ||
|
||
from pandas.types.hinting import ArrayLike, PythonScalar, Scalar, Buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually ok in doing
from pandas.types.hinting import * # noqa
(you need the noqa because of the * import.
easier to type I think as well.
@brmc love for you to update this if you can. |
@brmc I'm putting a bit of time into this to see if I can get |
@TomAugspurger that sounds good. I'm not nearly as able to invest as much time into this as I originally planned when I started which is probably pretty frustrating for the core team. but yea, i'll help out when I can |
Cool. I'll try to finish off |
CLN: created foundation for complex type annotations (GH14468) This is mostly just a stub file for now until a more clear picture develops What has been noticed so far: * numpy has no clear definition of what array_like means. all of these are valid: - Python scalars - tuples - lists - buffers - scalars in both python and numpy - more? * similar story but not so extreme with dtypes * python and numpy scalar helpers have been defined CLN: annotated IndexOpsMixin (GH14468) CLN: fixed a couple mistakes in IndexOpsMixin (GH14468) CLN: cleaned up some import statements and reverted a file commited by accident (GH14468) CLN: temporary work around for buffer error in python3 (GH14468) CLN: temporary work around for buffer error in python3 part 2 (GH14468) add trivial mypy check Fixup
@@ -114,6 +114,10 @@ if [ "$LINT" ]; then | |||
pip install cpplint | |||
fi | |||
|
|||
if [ "$TYPING" ]; then | |||
pip install mypy-lang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy-lang is now called just mypy. I'll update in my branch.
Ok, some review would be appreciated, especially from anyone who's actually familiar with mypy :) CI / package stuff
General NotesI lost my original file with notes, so this is from memory:
|
can you rebase and update? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -92,14 +116,17 @@ def __unicode__(self): | |||
return object.__repr__(self) | |||
|
|||
def _dir_additions(self): | |||
# type: () -> typing.Set[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what cases would we use str
over Text
(see __unicode__
) in type annotations?
Reading the docs [1] I think what you are doing here is probably correct because str
is python 2/3 implementation specific but I'm not 100% sure.
[1]
https://docs.python.org/3/library/typing.html#typing.Text
FWIW, I think this branch is pretty much abandoned (by me anyway) This
version won't even import, since our pandas ABCs behave differently that
real metaclasses.
Starting with the base classes was probably a mistake. I think the Dropbox
team adding type annotations recommend starting with the leaves of a
library, and working your we into the base.
If anyone wants to pick it up, I've put the cherry-picked the CI related
things to https://github.com/TomAugspurger/pandas/tree/annotations-2 (and I
guess a start of the hashing module, though that'll probably fall behind
relatively quickly)
…On Fri, Jun 16, 2017 at 6:06 PM, teh ***@***.***> wrote:
***@***.**** approved this pull request.
Nice!
------------------------------
In pandas/core/base.py
<#15866 (comment)>:
> @@ -92,14 +116,17 @@ def __unicode__(self):
return object.__repr__(self)
def _dir_additions(self):
+ # type: () -> typing.Set[str]
In what cases would we use str over Text (see __unicode__) in type
annotations?
Reading the docs [1] I think what you are doing here is probably correct
because str is python 2/3 implementation specific but I'm not 100% sure.
[1]
https://docs.python.org/3/library/typing.html#typing.Text
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15866 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIi2-Kg-CbjciOatYC2UHaXZ2XE7dks5sEwpygaJpZM4Mwtae>
.
|
ok let's close then. |
The most uncertain aspect is how to annotate "array-like." numpy doesn't even have a clear definition or recommendation. see the commit message for 60783c7 and numpy/numpy/issues/7370 for more details.
For now
pandas.types.hinting
are essentially just place holders for complex types that need to be defined.Any feed back is appreciated