Skip to content
This repository

Fix for issue #385. #388

wants to merge 3 commits into from

5 participants

Julien Woillez Don't Add Me To Your Organization a.k.a The Travis Bot Ondřej Čertík Charles Harris Nathaniel J. Smith
Julien Woillez

No description provided.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 2f28574 into 63cd8f3).

Ondřej Čertík

@jwoillez, thanks for the patch. Can you please add a test for this issue as well? That fails before your patch and works after your patch is applied.

Julien Woillez

@certik, hopefully, this is the right location for such a test.
Should tests for np.str_ and np.unicode_ also be added?

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged be46fc7 into 63cd8f3).

Julien Woillez

Passes on python 2, fails on python 3. Unfortunately, I don't have access to numpy on python 3 yet.

Ondřej Čertík

Just install python 3.2 from, numpy can then be installed using "python3 install", and it will just work.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 30a899b into 63cd8f3).

Julien Woillez

And now it fails for python2.5 (2.6 and 2.7 are OK) because bytes objects don't exist there. And for python3 because the formatting gives different results.

I will have to give all this some more thoughts. Maybe my fix is not the best fix.

Charles Harris charris closed this
Charles Harris

Going to ping the travis bot. support for 2.5 & 2.4 dropped, so that should help.

Charles Harris charris reopened this
Charles Harris

The problem is that void arrays print differently in python3, as a list of byte values rather than an ascii string. This needs a decision and fix for the str function of void arrays. I think the list might be prettier, but perhaps folks expect void to be treated as an ascii string, which is what python2 does.

Nathaniel J. Smith
Charles Harris

I'm tending towards byte strings, especially for repr since passing lists for array creation with dtype=void doesn't work correctly.

Julien Woillez

Related to this printing issue, I also noticed that, with python3 & latest numpy, we get the following:

Python 3.3.0 (default, Nov 23 2012, 10:26:01) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
>>> numpy.void(b"abc")
 [97 98 99]
>>> numpy.void(b"abc").dtype
>>> numpy.array2string(numpy.void(b"abc"))
'array([97, 98, 99], dtype=int8)'

numpy.array2string does not seem to interpret this numpy.void properly.

What should the expected behavior be?

Charles Harris

I think it should be a byte string.

Charles Harris

This appears fixed by #4401, so closing. The test failure would remain. Thinking about it, I'm no longer convinced that printing a byte string is preferable to the python3 version...

Charles Harris charris closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
9 numpy/core/src/multiarray/scalartypes.c.src
@@ -422,6 +422,15 @@ gentype_format(PyObject *self, PyObject *args)
422 422 obj = PyComplex_FromDoubles(val[0], val[1]);
423 423 Py_DECREF(dtype);
424 424 }
  425 + else if (PyArray_IsScalar(self, Void)) {
  426 + PyObject *arr = NULL;
  427 +
  428 + arr = PyArray_FromScalar(self, NULL);
  429 + if (arr != NULL) {
  430 + obj = PyObject_Str((PyObject *)arr);
  431 + Py_DECREF(arr);
  432 + }
  433 + }
425 434 else {
426 435 obj = self;
427 436 Py_INCREF(obj);
3  numpy/core/tests/
@@ -214,7 +214,8 @@ def test_scalar_format():
214 214 ('{0:g}', 1.5, np.float16),
215 215 ('{0:g}', 1.5, np.float32),
216 216 ('{0:g}', 1.5, np.float64),
217   - ('{0:g}', 1.5, np.longdouble)]
  217 + ('{0:g}', 1.5, np.longdouble),
  218 + ('{0}', b'A', np.void)]
218 219 # Python 2.6 doesn't implement complex.__format__
219 220 if sys.version_info[:2] > (2, 6):
220 221 tests += [('{0:g}', 1.5+0.5j, np.complex64),

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.