question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

strip_zeros kwarg no longer available in FloatFormat

See original GitHub issue

Reproducing 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
moorepantscommented, Apr 21, 2020

This has been inside NumPy for 3 releases now in that case. I am a bit curious whether this is more something you noticed, or something that actually creates issues for you?

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.

0reactions
rossbarcommented, Jul 14, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found