-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: mostly io, plotting #37059
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
TYP: mostly io, plotting #37059
Conversation
punted on issues in the OP, so this should be ready |
see #28339 (comment) |
Makes sense, thanks. Are you OK with the solution here? |
from the previous discussion, #28339 (comment)
maybe The crux of the issue seems to be python/mypy#7760 (comment)
The code does work. so we shouldn't really need to change it. |
if not is_list_like(axes): | ||
return np.array([axes]) | ||
elif isinstance(axes, (np.ndarray, ABCIndexClass)): | ||
return axes.ravel() | ||
return np.asarray(axes).ravel() |
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.
The issue here is that the types are not refined by ABCIndexClass
?
for a numpy array, this impacts perf.
%timeit np.asarray(axes).ravel()
# 724 ns ± 11.8 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
%timeit axes.ravel()
# 303 ns ± 9.35 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
Is this important?
maybe split the elif into two or ignore till we resolve the ABC issue.
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.
or can we cast to Union[np.ndarray, "Index"]
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.
Index.ravel behavior was just deprecated, so the np.asarray retains the current behavior
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.
Thanks @jbrockmendel lgtm
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
cc @simonjayhawkins can i get your thoughts on two remaining mypy complaints
The excel one is because it doesn't recognize
as returning
Tuple[str, ...]
. I expect if that were resolved it would still complain bc subclasses just pin the tuple as a class attribute instead of a property (easy to make a property, but much more verbose which im not wild about)The stata unused type:ignore becomes used once we remove stata from the setup.cfg exclusion. The only working way I've found to make mypy accept
TYPE_MAP: List[Union[int, str]] = list(range(251)) + list("abcd")
is withwhich i find much less clear than the
# type:ignore
d version.