-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: Clean DirNameMixin._deprecated #28957
Conversation
e6f67dc
to
37d02e7
Compare
pandas/core/base.py
Outdated
@@ -50,6 +50,8 @@ | |||
class PandasObject(DirNamesMixin): | |||
"""baseclass for various pandas objects""" | |||
|
|||
_deprecations = DirNamesMixin._deprecations | frozenset() # type: FrozenSet[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.
Is the rhs of the union doing anything here? I assume you are just stubbing out for future readers but in that case the annotation is unnecessary.
Probably cleanest to just leave as is for now and can be overridden in future as required
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.
Yeah, it's for the readers. I don't think this pattern of copying frozensets is seen very much, so thought it helps a bit to just have it stubbed out.
"flags", | ||
"strides", | ||
] | ||
) # type: FrozenSet[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.
You might not need this annotation; I think mypy should be able to infer
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.
Tried again, and mypy complains without the annotation. My guess is that it cannot be sure that the added set should only contain strings.
PandasObject._deprecations | ||
| IndexOpsMixin._deprecations | ||
| frozenset(["asobject", "contains", "dtype_str", "get_values", "set_value"]) | ||
) # type: FrozenSet[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.
Same comment here
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 added the type hints after complaints from mypy. I agree it's strange it doesn't infer and I'll see if something can be done to make it infer.
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 think should be able to infer as long as you construct with values. Empty construction complains because it is not known then what types of value the object should hold.
Not sure if FrozenSet would act differently but that’s how builtins work
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.
Same here. A frozenset that only contains strings, could conceivably have non-strings, and I think that's what mypy complains about.
37d02e7
to
f62fdf1
Compare
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.
lgtm @WillAyd
Thanks @topper-123 |
This moves the content of
DirNameMixin._deprecations
to more appropriate locations, typicallyIndexOpsMixIn._deprecations
, as that is a common subclass ofIndex
andSeries
. The names inDirNameMixin._deprecations
belonged to those two classes, so having the deprecated names located all the way up inDirNameMixin
made them be available in all classes that subclassDirNameMixin
, which was unfortunate.By having
DirNameMixin._deprecations
start with an empty set, it will be easier to useDirNameMixin
andPandasObject
where/when needed, without inheriting undesired names in_deprecated
.This PR also moves
"tolist"
toIndexOpsMixIn._deprecations
, becausetolist
is defined in that class.