Skip to content
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

Merged
merged 1 commit into from
Oct 16, 2019

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Oct 13, 2019

This moves the content of DirNameMixin._deprecations to more appropriate locations, typically IndexOpsMixIn._deprecations, as that is a common subclass of Index and Series. The names in DirNameMixin._deprecations belonged to those two classes, so having the deprecated names located all the way up in DirNameMixin made them be available in all classes that subclass DirNameMixin, which was unfortunate.

By having DirNameMixin._deprecations start with an empty set, it will be easier to use
DirNameMixin and PandasObject where/when needed, without inheriting undesired names in _deprecated.

This PR also moves "tolist" to IndexOpsMixIn._deprecations, because tolist is defined in that class.

@topper-123 topper-123 changed the title CLN: Clean DirNameMixin CLN: Clean DirNameMixin._deprecated Oct 13, 2019
@@ -50,6 +50,8 @@
class PandasObject(DirNamesMixin):
"""baseclass for various pandas objects"""

_deprecations = DirNamesMixin._deprecations | frozenset() # type: FrozenSet[str]
Copy link
Member

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

Copy link
Contributor Author

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]
Copy link
Member

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

Copy link
Contributor Author

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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.

@jreback jreback added this to the 1.0 milestone Oct 16, 2019
@jreback jreback added the Typing type annotations, mypy/pyright type checking label Oct 16, 2019
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm @WillAyd

@WillAyd WillAyd merged commit b63f829 into pandas-dev:master Oct 16, 2019
@WillAyd
Copy link
Member

WillAyd commented Oct 16, 2019

Thanks @topper-123

@topper-123 topper-123 deleted the clean_DirNameMixin branch October 16, 2019 19:07
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
bongolegend pushed a commit to bongolegend/pandas that referenced this pull request Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants