From c05019eda16477f4be99f47755362c07e1acb5b8 Mon Sep 17 00:00:00 2001 From: Christian Brodbeck Date: Wed, 6 May 2015 10:49:41 -0400 Subject: BUG: setdiff1d return dtype Fixes #5846 (If called with an empty array as first argument, the returned array had dtype bool instead of the dtype of the input array) --- numpy/lib/arraysetops.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'numpy/lib/arraysetops.py') diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 7776d7e76..3dd97aecf 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -470,11 +470,9 @@ def setdiff1d(ar1, ar2, assume_unique=False): array([1, 2]) """ - if not assume_unique: + if assume_unique: + ar1 = np.asarray(ar1).ravel() + else: ar1 = unique(ar1) ar2 = unique(ar2) - aux = in1d(ar1, ar2, assume_unique=True) - if aux.size == 0: - return aux - else: - return np.asarray(ar1)[aux == 0] + return ar1[in1d(ar1, ar2, assume_unique=True, invert=True)] -- cgit v1.2.1