-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
MNT: Remove set_string_function
#26611
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
Conversation
Needs a release note. You also missed spots the C function still shows up:
Maybe also add a note or comment to
That's not true is it? You can use
|
I think there's no need to dig into it so let's say that we can override With In [104]: a = np.array([[1,2,3]])
In [105]: a
Out[105]: array([[1, 2, 3]])
In [106]: np.set_string_function(lambda x: "hello")
In [107]: a
Out[107]: hello |
Yeah, I think |
Done! |
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.
LGTM. @seberg @mattip are you ok with having a stubbed-out C API function like this?
In a GitHub search I see no uses outside of copies of numpy and re-exports and listings of the numpy C API.
I do see one downstream project trying to work around us removing the ability to completely override the print formatting for the entire array: They ended up deciding to set That said, maybe printoptions could grow an option to override printing the entire array? |
Since we began deprecating this in 2.0, I think we need to wait for 2.2 to remove it, no? |
The C-level function was never deprecated but the python-level function was removed from the public API in NumPy 2.0, skipping the deprecation. It seems odd to me to have the Python function gone from the public API but to insist on a long deprecation period for the C-level function that is used much less often. |
FWIW, the deprecation warning should have been implemented to include the C-side, but the normal deprecation policy is 2 (or maybe even 3 in this case) releases (1 year). |
It looks like it was deprecated first, then quickly removed before the deprecation was in a release (the comment says it was deprecated in numpy 2.0). I think it was included in the general API cleanup, @mtsokol might remember the details about why it was included for removal so quickly after being deprecated. I don't remember thinking too carefully about this one during review. |
I am confused: This PR would be the one to remove it, no? Giving us a very brief deprecation period on the Python function. I am happy to ignore the C version, and had we done it in 2.0, I would have been happy to just do it probably. |
I think we just made a decision during one of the meetings to put this function in the "remove" group for 2.0 and removed it: #24306 (See So
Sure, then there would be a new option |
Aha, so the point is that it was effectively already removed in 2.0 because it only exists as a private function. |
@ngoldbaum I added np.set_string_function(lambda x: "FOO", repr=True) |
One thing we forgot yesterday: This needs a release note for the C-API change at least. EDIT: Sorry, I see it's there, would be nice to put the C-API part into |
Sorry for taking a little while to merge this one. Let's bring this in and thanks for finishing up the work on this deprecation/removal @mtsokol! |
I can see the use of adding it, but hadn't realized it was added in this PR. If we add |
Sure! Let me tweak the release note separately. |
DOC: Extend release notes for #26611
Thanks for adding this functionality back with Just wanted to note that at least one other project that relies on this feature: lovely-numpy, and I personally also have a hackier version, so it's great that it's being left in . Very useful to be able to quickly see array information in one glance :) |
Hi @ngoldbaum,
This PR removes
set_string_function
and makesPyArray_SetStringFunction
throw a "was removed" exception when called.__str__
innumpy.ndarray
class can be still altered withset_printoptions
.__repr__
can't be modified by a user with the Python or C API.