-
-
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
Convert core/indexes/base.py to f-strings #29903
Conversation
8fac6fd
to
d1132f4
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.
Thanks @topper-123 generally lgtm.
pandas/core/indexes/base.py
Outdated
@@ -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__ |
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.
we're now using type() instead of __class__
, see #29775 (comment)
pandas/core/indexes/base.py
Outdated
@@ -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" |
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
pandas/core/indexes/base.py
Outdated
"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. " |
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
pandas/core/indexes/base.py
Outdated
@@ -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 " |
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.
we're now using repr() instead of !r, see #29870 (comment)
pandas/core/indexes/base.py
Outdated
"{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" |
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
pandas/core/indexes/base.py
Outdated
@@ -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}") |
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
pandas/core/indexes/base.py
Outdated
"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}" |
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
@topper-123 need to xref #29547 so @MomIsBestFriend can maintain to-do list |
I've renamed self.class to type(self). I'm not sure I agree with a policy of strictly requiring |
I agree. !r is more concise and would be my choice, but we should be consistent. |
1761408
to
9dfeeed
Compare
@topper-123 looks like a merge conflict - can you merge master?
Not a strong opinion but I do find |
9dfeeed
to
38d9d69
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.
@topper-123 lgtm
…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) ...
No description provided.