Skip to content
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

Fix compatibility with Numpy 1.16.x #1989

Merged
merged 2 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ v0.15.0 (unreleased)
v0.14.3 (unreleased)
--------------------

* Fixed compatibility with Numpy 1.16.x. [#1989]

* Improve tab-completion of attribute names in Data to not include
non-relevant items. [#1971]

Expand Down
5 changes: 3 additions & 2 deletions glue/utils/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def unique(array):
"""
# numpy.unique doesn't handle mixed-types on python3,
# so we use pandas
U, I = pd.factorize(array, sort=True)
return I, U
array = np.asarray(array)
I, U = pd.factorize(array, sort=True)
return U.astype(array.dtype), I


def shape_to_string(shape):
Expand Down
14 changes: 14 additions & 0 deletions glue/utils/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ def test_unique(before, ref_after, ref_indices):
np.testing.assert_array_equal(indices, ref_indices)


def test_unique_dtype():

# Regression test to make sure that when working with strings, we don't
# get an object array back from the unique function

array = np.array(['a', 'b', 'c'])
U, I = unique(array)
assert U.dtype.kind in 'SU'

li = ['a', 'b', 'c']
U, I = unique(li)
assert U.dtype.kind in 'SU'


def test_shape_to_string():
assert shape_to_string((1, 4, 3)) == "(1, 4, 3)"

Expand Down