-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
DEPS: Update reprs with numpy NEP51 scalar repr #54268
Conversation
@@ -5250,7 +5250,8 @@ def _raise_scalar_data_error(cls, data): | |||
# in order to keep mypy happy | |||
raise TypeError( | |||
f"{cls.__name__}(...) must be called with a collection of some " | |||
f"kind, {repr(data)} was passed" | |||
f"kind, {repr(data) if not isinstance(data, np.generic) else str(data)} " |
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.
does str work unconditionally?
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 according to the linked PR seems so
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.
the can we simplify this?
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.
Oh sorry, str works unconditionally for numpy scalars but repr
vs str
would make this display differently for other scalars e.g. python strings
pandas/core/arrays/masked.py
Outdated
@@ -160,6 +161,9 @@ def _empty(cls, shape: Shape, dtype: ExtensionDtype): | |||
) | |||
return result | |||
|
|||
def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]: | |||
return super()._formatter(boxed=True) |
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 ignoring the boxed keyword?
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 since I think we'll need to always return str given the NEP 51 change. Actually probably just simpler to return str
here
name = type(self).__name__ | ||
repr_str = f"{name}({repr(left)}, {repr(right)}, closed={repr(self.closed)})" | ||
repr_str = f"{name}({disp(left)}, {disp(right)}, closed={repr(self.closed)})" |
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.
maybe the thing to do is unpack numpy scalars at an earlier stage?
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.
But we should still store numpy scalars for left/right on Interval right?
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 was thinking store native scalars
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.
Hmm might make sense, not sure if there's any larger ramifications of that chance. Might be better to experiment in a follow up?
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.
sure
This will get the CI back to green? |
Yup. I guess we can merge to get back to green and follow up if needed. |
xref numpy/numpy#22449