File: indexing-11044.patch

package info (click to toggle)
python-xarray 2026.01.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,676 kB
  • sloc: python: 120,278; makefile: 269
file content (58 lines) | stat: -rw-r--r-- 2,460 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From 5c54e8b62ec1b0526daf33bb34bceb3a62d04fc8 Mon Sep 17 00:00:00 2001
From: Antonio Valentino <antonio.valentino@tiscali.it>
Date: Mon, 22 Dec 2025 01:34:19 +0100
Subject: [PATCH] Support nevative step in normalize_indexer

---
 xarray/core/indexing.py       | 7 ++++---
 xarray/tests/test_indexing.py | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

Index: python-xarray-2026.01.0/xarray/core/indexing.py
===================================================================
--- python-xarray-2026.01.0.orig/xarray/core/indexing.py
+++ python-xarray-2026.01.0/xarray/core/indexing.py
@@ -270,7 +270,8 @@ def normalize_slice(sl: slice, size: int
     >>> normalize_slice(slice(0, -1), 10)
     slice(0, 9, 1)
     """
-    return slice(*sl.indices(size))
+    start, stop, step = sl.indices(size)
+    return slice(start, stop if stop >= 0 else None, step)
 
 
 def _expand_slice(slice_: slice, size: int) -> np.ndarray[Any, np.dtype[np.integer]]:
@@ -293,14 +294,14 @@ def slice_slice(old_slice: slice, applie
     index it with another slice to return a new slice equivalent to applying
     the slices sequentially
     """
-    old_slice = normalize_slice(old_slice, size)
+    old_slice = slice(*old_slice.indices(size))
 
     size_after_old_slice = len(range(old_slice.start, old_slice.stop, old_slice.step))
     if size_after_old_slice == 0:
         # nothing left after applying first slice
         return slice(0)
 
-    applied_slice = normalize_slice(applied_slice, size_after_old_slice)
+    applied_slice = slice(*applied_slice.indices(size_after_old_slice))
 
     start = old_slice.start + applied_slice.start * old_slice.step
     if start < 0:
Index: python-xarray-2026.01.0/xarray/tests/test_indexing.py
===================================================================
--- python-xarray-2026.01.0.orig/xarray/tests/test_indexing.py
+++ python-xarray-2026.01.0/xarray/tests/test_indexing.py
@@ -300,10 +300,11 @@ class TestLazyArray:
             (-1, 3, 2),
             (slice(None), 4, slice(0, 4, 1)),
             (slice(1, -3), 7, slice(1, 4, 1)),
+            (slice(None, None, -1), 8, slice(7, None, -1)),
             (np.array([-1, 3, -2]), 5, np.array([4, 3, 3])),
         ),
     )
-    def normalize_indexer(self, indexer, size, expected):
+    def test_normalize_indexer(self, indexer, size, expected):
         actual = indexing.normalize_indexer(indexer, size)
 
         if isinstance(expected, np.ndarray):