summaryrefslogtreecommitdiff
path: root/numpy/lib/arraysetops.py
diff options
context:
space:
mode:
authorMattHarrigan <harrigan.matthew@gmail.com>2016-10-27 19:38:01 -0400
committerMattHarrigan <harrigan.matthew@gmail.com>2016-10-27 20:17:26 -0400
commit9a90abf995d0d8d9e96992a083dc55a41a93254f (patch)
tree7308b4d4765e3edc5636bfd90385da9142db2068 /numpy/lib/arraysetops.py
parentb0e66ad754c2a2efeb8c6f39418e5bb7d3e388c5 (diff)
downloadnumpy-9a90abf995d0d8d9e96992a083dc55a41a93254f.tar.gz
BUG: return subclasses from ediff1d
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r--numpy/lib/arraysetops.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index 889415efe..836f4583f 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -85,28 +85,27 @@ def ediff1d(ary, to_end=None, to_begin=None):
if to_begin is None and to_end is None:
return ary[1:] - ary[:-1]
- # get the length of the diff'd values
- l = len(ary) - 1
- if l < 0:
- # force length to be non negative, match previous API
- # should this be an warning or deprecated?
- l = 0
-
if to_begin is None:
- to_begin = np.array([])
+ l_begin = 0
else:
to_begin = np.asanyarray(to_begin).ravel()
+ l_begin = len(to_begin)
if to_end is None:
- to_end = np.array([])
+ l_end = 0
else:
to_end = np.asanyarray(to_end).ravel()
+ l_end = len(to_end)
# do the calculation in place and copy to_begin and to_end
- result = np.empty(l + len(to_begin) + len(to_end), dtype=ary.dtype)
- result[:len(to_begin)] = to_begin
- result[len(to_begin) + l:] = to_end
- np.subtract(ary[1:], ary[:-1], result[len(to_begin):len(to_begin) + l])
+ l_diff = max(len(ary) - 1, 0)
+ result = np.empty(l_diff + l_begin + l_end, dtype=ary.dtype)
+ result = ary.__array_wrap__(result)
+ if l_begin > 0:
+ result[:l_begin] = to_begin
+ if l_end > 0:
+ result[l_begin + l_diff:] = to_end
+ np.subtract(ary[1:], ary[:-1], result[l_begin:l_begin + l_diff])
return result