8000 .format does not play well with a 0-D NumPy array · Issue #7978 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

.format does not play well with a 0-D NumPy array #7978

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

Closed
MechCoder opened this issue Aug 26, 2016 · 3 comments · Fixed by #9883
Closed

.format does not play well with a 0-D NumPy array #7978

MechCoder opened this issue Aug 26, 2016 · 3 comments · Fixed by #9883

Comments

@MechCoder
Copy link
Contributor

Hi,

# This works
a = "%0.3g" % np.array(2)
a
'2'
# This does not
a = "{0:0.3g}".format(np.array(2))
TypeError: non-empty format string passed to object.__format__

Is this a bug?

@fmaussion
Copy link

Just ran into this as well. This is quite bad, isn't it?

@MechCoder
Copy link
Contributor Author

Not as bad as using a 0-D NumPy array in the first place :P

But yeah, this should be fixed.

@fmaussion
Copy link

0D arrays are a standard output in xarray:

In [1]: import xarray as xr

In [2]: '{:.2g}'.format(xr.DataArray([1, 2, 3]).mean())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-e521944932df> in <module>()
----> 1 '{:.2g}'.format(xr.DataArray([1, 2, 3]).mean())

TypeError: non-empty format string passed to object.__format__

(CC @shoyer just fyi)

eric-wieser added a commit to eric-wieser/numpy that referenced this issue Oct 18, 2017
This fixes numpygh-7978

The behavior for other sized arrays is left unchanged, pending discussion in numpygh-5543
theodoregoetz pushed a commit to theodoregoetz/numpy that referenced this issue Oct 23, 2017
This fixes numpygh-7978

The behavior for other sized arrays is left unchanged, pending discussion in numpygh-5543
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0