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

Convert core/indexes/base.py to f-strings #29903

Merged
merged 3 commits into from
Dec 1, 2019

Conversation

topper-123
Copy link
Contributor

No description provided.

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @topper-123 generally lgtm.

@@ -814,8 +813,10 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
)
else:
if allow_fill and fill_value is not None:
msg = "Unable to fill values because {0} cannot contain NA"
raise ValueError(msg.format(self.__class__.__name__))
cls_name = self.__class__.__name__
Copy link
Member

Choose a reason for hiding this comment

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

we're now using type() instead of __class__, see #29775 (comment)

@@ -1287,7 +1288,7 @@ def _set_names(self, values, level=None):
for name in values:
if not is_hashable(name):
raise TypeError(
"{}.name must be a hashable type".format(self.__class__.__name__)
f"{self.__class__.__name__}.name must be a hashable type"
Copy link
Member

Choose a reason for hiding this comment

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

same

"Use a.empty, a.bool(), a.item(), a.any() or a.all().".format(
self.__class__.__name__
)
f"The truth value of a {self.__class__.__name__} is ambiguous. "
Copy link
Member

Choose a reason for hiding this comment

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

same

@@ -2939,8 +2934,8 @@ def _get_fill_indexer_searchsorted(self, target, method, limit=None):
"""
if limit is not None:
raise ValueError(
"limit argument for %r method only well-defined "
"if index and target are monotonic" % method
f"limit argument for {method!r} method only well-defined "
Copy link
Member

Choose a reason for hiding this comment

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

we're now using repr() instead of !r, see #29870 (comment)

"{0}(...) must be called with a collection of some "
"kind, {1} was passed".format(cls.__name__, repr(data))
f"{cls.__name__}(...) must be called with a collection of some "
f"kind, {data!r} was passed"
Copy link
Member

Choose a reason for hiding this comment

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

same

@@ -4113,7 +4105,7 @@ def contains(self, key) -> bool:
return key in self

def __hash__(self):
raise TypeError("unhashable type: %r" % type(self).__name__)
raise TypeError(f"unhashable type: {type(self).__name__!r}")
Copy link
Member

Choose a reason for hiding this comment

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

same

"Cannot get %s slice bound for non-unique "
"label: %r" % (side, original_label)
f"Cannot get {side} slice bound for non-unique "
f"label: {original_label!r}"
Copy link
Member

Choose a reason for hiding this comment

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

same

@simonjayhawkins simonjayhawkins added the Code Style Code style, linting, code_checks label Nov 27, 2019
@simonjayhawkins simonjayhawkins added this to the 1.0 milestone Nov 27, 2019
@simonjayhawkins
Copy link
Member

@topper-123 need to xref #29547 so @MomIsBestFriend can maintain to-do list

@topper-123
Copy link
Contributor Author

I've renamed self.class to type(self).

I'm not sure I agree with a policy of strictly requiring repr in f-string. f-strings and str.format have their own formatting mini-language with lots of other options than just !r, and !r is not an unusual modifer itself.

@simonjayhawkins
Copy link
Member

simonjayhawkins commented Nov 27, 2019

I'm not sure I agree with a policy of strictly requiring repr in f-string. f-strings and str.format have their own formatting mini-language with lots of other options than just !r, and !r is not an unusual modifer itself.

I agree. !r is more concise and would be my choice, but we should be consistent.

@WillAyd
Copy link
Member

WillAyd commented Nov 29, 2019

@topper-123 looks like a merge conflict - can you merge master?

I'm not sure I agree with a policy of strictly requiring repr in f-string. f-strings and str.format have their own formatting mini-language with lots of other options than just !r, and !r is not an unusual modifer itself.

Not a strong opinion but I do find {repr(some_var)} clearer than {some_var!r}. I always know what repr does don't always remember the format language specs. Ditto for {str(some_var)} versus {some_var!s}

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@jreback jreback merged commit f5c102f into pandas-dev:master Dec 1, 2019
keechongtan added a commit to keechongtan/pandas that referenced this pull request Dec 2, 2019
…ndexing-1row-df

* upstream/master: (49 commits)
  repr() (pandas-dev#29959)
  DOC : Typo fix in userguide/Styling (pandas-dev#29956)
  CLN: small things in pytables (pandas-dev#29958)
  API/DEPR: Change default skipna behaviour + deprecate numeric_only in Categorical.min and max (pandas-dev#27929)
  DEPR: DTI/TDI/PI constructor arguments (pandas-dev#29930)
  CLN: fix pytables passing too many kwargs (pandas-dev#29951)
  Typing (pandas-dev#29947)
  repr() (pandas-dev#29948)
  repr() (pandas-dev#29950)
  Added space at the end of the sentence (pandas-dev#29949)
  ENH: add NA scalar for missing value indicator, use in StringArray. (pandas-dev#29597)
  CLN: BlockManager.apply (pandas-dev#29825)
  TST: add test for rolling max/min/mean with DatetimeIndex over different frequencies (pandas-dev#29932)
  CLN: explicit signature for to_hdf (pandas-dev#29939)
  CLN: make kwargs explicit for pytables read_ methods (pandas-dev#29935)
  Convert core/indexes/base.py to f-strings (pandas-dev#29903)
  DEPR: dropna multiple axes, fillna int for td64, from_codes with floats, Series.nonzero (pandas-dev#29875)
  CLN: make kwargs explicit in pytables constructors (pandas-dev#29936)
  DEPR: tz_convert in the Timestamp constructor raises (pandas-dev#29929)
  STY: F-strings and repr (pandas-dev#29938)
  ...
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants