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: remove kwargs in Index.format #35122

Merged
merged 7 commits into from
Jul 14, 2020

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Jul 4, 2020

Removes kwargs in Index.format and subclasses. Also changes Index._format_with_header to have parameter na_rep not have a default value (in order to not have default value set in two locations).

Related to #35118.

@topper-123 topper-123 force-pushed the cln_index.format branch 2 times, most recently from 51cbd77 to 31c4eb7 Compare July 4, 2020 14:37
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Looks pretty good - a few comments

na_rep=None,
formatter=None,
):
) -> list:
Copy link
Member

Choose a reason for hiding this comment

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

Can you use List from typing and add a subscript?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has return type List[Union[str, Tuple[str]]]. It returns List[Tuple[str]] if adjoin=False, else List[str].

I'm not a fan of union return types, it can trip mypy up in random places. I would prefer to use Literal types and typing.cast, but that is only available in python 3.8. Hope that's ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sparsify is actually of type Union[bool, None, Literal[lib.no_default]], which can't be represented until python 3.8. I'll just leave it as is.

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 use the union or maybe even overload based off of your comment (@simonjayhawkins has used overload successfully in a few places already); makes for much better type checking than a generic list

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, we don't use a bare list as typing anywhere else, I would change this (and use a Union)

@@ -1231,13 +1231,17 @@ def _format_native_types(self, na_rep="nan", **kwargs):

def format(
self,
name=None,
Copy link
Member

Choose a reason for hiding this comment

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

Any chance of annotating these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

@WillAyd WillAyd added Clean Typing type annotations, mypy/pyright type checking labels Jul 6, 2020
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.

looks good x @WillAyd comments.

@pep8speaks
Copy link

pep8speaks commented Jul 7, 2020

Hello @topper-123! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-07-14 20:50:39 UTC

if sparsify not in [True, 1]:
# GH3547 use value of sparsify as sentinel if it's "Falsey"
assert isinstance(sparsify, bool) or sparsify is lib.no_default
if sparsify in [False, lib.no_default]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clarifying possible values here.

@jreback jreback added this to the 1.1 milestone Jul 8, 2020
@topper-123
Copy link
Contributor Author

Updated. @WillAyd?

@topper-123
Copy link
Contributor Author

Ping.

@topper-123
Copy link
Contributor Author

I missed that, I've updated again.

@jreback jreback merged commit b0468aa into pandas-dev:master Jul 14, 2020
@jreback
Copy link
Contributor

jreback commented Jul 14, 2020

thanks @topper-123

fangchenli pushed a commit to fangchenli/pandas that referenced this pull request Jul 16, 2020
@topper-123 topper-123 deleted the cln_index.format branch August 8, 2020 08:30
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.

4 participants