-
-
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
REF: define arithmetic methods non-dynamically #51813
Conversation
pandas/core/ops/methods.py
Outdated
|
||
# Set the result's name after __finalize__ is called because __finalize__ | ||
# would set it back to self.name | ||
out.name = name # pyright: ignore[reportGeneralTypeIssues] |
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.
@Dr-Irv how do i get pyright to stop complaining about this?
/home/runner/work/pandas/pandas/pandas/core/ops/methods.py:785:20 - error: Cannot assign member "name" for type "tuple[Series, Series]"
Member "name" is unknown (reportGeneralTypeIssues)
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 removed the ignore comment locally and run pre-commit run -av --hook-stage manual pyright_reportGeneralTypeIssues
but did not get an error
(could also bump pyright to 1.1.296)
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.
Was thinking this could be a pyright bug, but might be difficult to create a reproducible example. At least when I've seen that kind of error, it's usually been a pyright bug
pandas/core/ops/methods.py
Outdated
right = right._values | ||
|
||
# error: "FrameOps" has no attribute "_iter_column_arrays" | ||
col_arrays = self._iter_column_arrays() # type: ignore[attr-defined] |
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 assume sub-classes implement this method? Would it be worth making this an abstractmethod
to ensure that sub-classes definitely have it (and to make the type checkers happy)?
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.
yah this is only inherited by DataFrame.
might just put this all in Series/DataFrame instead of having a subclass to avoid this typing gymnastics
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.
+1 to have these directly on DataFrame/Series, less indirection too
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.
moved + green
The failing doctest looks like the doctest is wrong. Must just not be getting in the status quo?
|
Hmm is this the same for DataFrame too and/or a recent change? For label b, I would expect this to follow:
For label c, since there's no corresponding values in series |
At the reindex stage it is, but then |
Thanks @jbrockmendel |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Avoid runtime imports, get stuff out of
ops.__init__
, which was the goal 4-5 years ago when ops was first madea directory.Move relevant helper methods from frame/series files . Decided on a new mixin rather than dumping everything directly in DataFrame/Series bc those files are too bug as it is. If others feel strongly i'd be OK putting it all in DataFrame/Series.