Issue 1:
version: 1.13.3

Example:

>>> junk, inv = numpy.unique([], return_inverse=True)
>>> print(inv)

array([], dtype=bool)

The documentation says numpy.unique shall return indices; the sudden change of type is surprising at best.

Issue 2:
Hello,

Obviously, this issue is related to #3588. However I give here a more accurate (hopefully) description of the bug and some hints regarding where things go wrong.

Here is a sample code producing the problem:

import numpy
import pickle

a = numpy.ma.array([1.0, 2.0], dtype=object)
pickle.loads(pickle.dumps(a))

TypeError Traceback (most recent call last)
<ipython-input-31-7fbb1ec321e5> in <module>()
3
4 a = numpy.ma.array([1.0, 2.0], dtype=object)
----> 5 pickle.loads(pickle.dumps(a))

/opt/rh/python27/root/usr/lib64/python2.7/pickle.pyc in loads(str)
1380 def loads(str):
1381 file = StringIO(str)
-> 1382 return Unpickler(file).load()
1383
1384 # Doctest

/opt/rh/python27/root/usr/lib64/python2.7/pickle.pyc in load(self)
856 while 1:
857 key = read(1)
--> 858 dispatch[key](self)
859 except _Stop, stopinst:
860 return stopinst.value

/opt/rh/python27/root/usr/lib64/python2.7/pickle.pyc in load_build(self)
1215 setstate = getattr(inst, "__setstate__", None)
1216 if setstate:
-> 1217 setstate(state)
1218 return
1219 slotstate = None

/home/amignon/mypython27/lib/python2.7/site-packages/numpy/ma/core.pyc in __setstate__(self, state)
5867 """
5868 (_, shp, typ, isf, raw, msk, flv) = state
-> 5869 super(MaskedArray, self).__setstate__((shp, typ, isf, raw))
5870 self._mask.__setstate__((shp, make_mask_descr(typ), isf, msk))
5871 self.fill_value = flv

TypeError: object pickle not returning list

Basically, I create a masked array with a dtype=object and an exception is raised when the __setstate__ method from ndarray is called which corresponds to the code in /numpy/core/src/multiarray/methods.c at line 1676.

if (PyDataType_FLAGCHK(typecode, NPY_LIST_PICKLE)) {
if (!PyList_Check(rawdata)) {
PyErr_SetString(PyExc_TypeError,
"object pickle not returning list");
return NULL;
}
}
else {
Py_INCREF(rawdata);

From what I understand the source of the problem occurs in the same file at line 1598 when the flag NPY_LIST_PICKLE is tested in the __reduce__ method of ndarray (array_reduce function):

if (PyDataType_FLAGCHK(PyArray_DESCR(self), NPY_LIST_PICKLE)) {
thestr = _getlist_pkl(self);
}
else {
thestr = PyArray_ToString(self, NPY_ANYORDER);
}

For some reason it is not recognised as having to be pickled as list as expected when it is called from the __getstate__ method of MaskedArray in numpy/ma/core.py at line 5869

def __getstate__(self):
"""Return the internal state of the masked array, for pickling
purposes.
"""
cf = 'CF'[self.flags.fnc]
data_state = super(MaskedArray, self).__reduce__()[2]
return data_state + (getmaskarray(self).tobytes(cf), self._fill_value)

This weird behaviour is confirmed by trying this python code:

import numpy
import pickle

a = numpy.ma.array([1.0, 2.0], dtype=object)
print a.__getstate__()[:-2] # The two last elements correspond to the mask
print super(np.ma.MaskedArray, a).__reduce__()[2] # Used internally in __getstate__

Which gives:

(1, (2,), dtype('O'), False, 'X\xca\x84\x01\x00\x00\x00\x00p\xca\x84\x01\x00\x00\x00\x00')
(1, (2,), dtype('O'), False, [1.0, 2.0])

This is weird since the second line uses the same __reduce__ method from ndarray as in the __getstate__ method of MaskedArray.

I've not been able to go further.

Hoping this helps