Skip to content

DEP: Deprecate ndarray.tostring() #15867

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

Merged
merged 2 commits into from
Apr 1, 2020
Merged

Conversation

eric-wieser
Copy link
Member

The corresponding array.array.tostring() in the standard library has been deprecated in favor of tobytes since Python 3.1 (python/cpython@1ce3eb5).

@rgommers
Copy link
Member

I guess it's time indeed.....

Could you do the same for MaskedArray to keep it consistent?

Would be good to mention on the mailing list, not sure if anyone still relies on it.

@eric-wieser
Copy link
Member Author

Could you do the same for MaskedArray to keep it consistent?

Done in the commit I posted just before you sent that

Would be good to mention on the mailing list, not sure if anyone still relies on it.

Not sure it's even worth it. Unless they're trying to support numpy from 1.19 all the way back to 1.8, the fix is trivial. Even if they do somehow care about such an old version, the cost of not fixing it is simply a warning.

@eric-wieser eric-wieser added the component: numpy.ma masked arrays label Mar 30, 2020
@rgommers
Copy link
Member

Even just as a heads up, we should always mention deprecations on the list. There's lots of projects where this could fail their CI as soon as we either merge or release this.

@eric-wieser
Copy link
Member Author

Done in http://numpy-discussion.10968.n7.nabble.com/Deprecating-ndarray-tostring-td48010.html, also made the necessary changes in scipy and matplotlib myself.

saimn added a commit to saimn/astropy that referenced this pull request Mar 30, 2020
ndarray.tostring will be deprecated in Numpy 1.19
numpy/numpy#15867
Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

LGTM, a quick deprecation test would be better though, since I guess the tostring function(s) are actually be fully non-covered now.

@eric-wieser
Copy link
Member Author

Looks like I forgot to commit the one I wrote

The corresponding `array.array.tostring()` in the standard library has been deprecated in favor of `tobytes` since Python 3.1 (python/cpython@1ce3eb5).
Despite its name, it returns `bytes` not `str`\ s.

.. deprecated:: 1.19.0
"""))
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to include the parameters, return and example to this docstring ? I see other deprecated functions in the code base where this information is present.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd argue in this case there's no point, as the functions are completely identical.

Copy link
Member

Choose a reason for hiding this comment

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

This will still have a slight impact on users continuing to use the deprecated tostring and calling help on tostring instead of tobytes (probably just making them run an addition help on tobytes).

Copy link
Member

Choose a reason for hiding this comment

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

Not sure, but then it is identical and not having a full documentation means that you cannot overread the "deprecated" note, so I think I am happy with it.

Tested the ma and scalars manually, so OK with this (the C-code needs the test the most). Will probably just merge later (and leave release notes formatting, if wished, for release time).

@eric-wieser eric-wieser requested a review from seberg March 31, 2020 10:09
``numpy.ndarray.tostring()`` is deprecated in favor of ``tobytes()``
--------------------------------------------------------------------
`~numpy.ndarray.tobytes` has existed since the 1.9 release, but until this release `~numpy.ndarray.tostring` emitted no warning.
The change to emit a warning brings NumPy in line with the builtin `array.array` methods of the same name.
Copy link
Member

Choose a reason for hiding this comment

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

should be reflowed to 80 columns

@mattip mattip merged commit ad5d58c into numpy:master Apr 1, 2020
@mattip
Copy link
Member

mattip commented Apr 1, 2020

Thanks @eric-wieser

jameshiebert added a commit to pacificclimate/netcdf4-python that referenced this pull request Jul 3, 2020
numpy has deprecated the use of array.array.tostring() in favor of
tobytes
numpy/numpy#15867
This patch replaces all (6) such uses in this package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants