strip_zeros kwarg no longer available in FloatFormat
See original GitHub issueReproducing code example:
I’ve been using this context manager in some code to control array printing:
import contextlib
import numpy as np
import numpy.core.arrayprint as arrayprint
@contextlib.contextmanager
def printoptions(strip_zeros=False, **kwargs):
"""Allows you to set NumPy array print formatting locally.
Taken from:
http://stackoverflow.com/questions/2891790/pretty-printing-of-numpy-array
"""
origcall = arrayprint.FloatFormat.__call__
def __call__(self, x, strip_zeros=strip_zeros):
return origcall.__call__(self, x, strip_zeros)
arrayprint.FloatFormat.__call__ = __call__
original = np.get_printoptions()
np.set_printoptions(**kwargs)
yield
np.set_printoptions(**original)
arrayprint.FloatFormat.__call__ = origcall
FloatFormat
was removed in NumPy 1.18.0 but prior to that https://github.com/numpy/numpy/pull/9941 removed the strip_zeros
kwarg from FloatFormat.__call__
. This seems to be a backwards incompatible change. It also seems like that kwarg likely did not have a unit test.
Regardless, I’m trying to figure out how to reproduce the behavior of strip_zeros=False
prior to PR #9941.
Error message:
Numpy/Python version information:
In [10]: import sys, numpy; print(numpy.__version__, sys.version)
1.18.1 3.6.10 | packaged by conda-forge | (default, Apr 6 2020, 14:52:36)
[GCC 7.3.0]
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have a stable library that I developed a decade ago and I update it about once a year now to ensure it works with the recent libraries. I’m behind on the update a bit but it is blocking some travis builds and I need to come up with a work around. I’m mostly looking for that, not expecting you all to undo changes.
The discussion in #16869 turned up the source of the issue, see #11924 . I will close this for now as picking up the linked NEP seems like the best way for preventing issues like this in the future.