@@ -1588,11 +1588,11 @@ def get_fselection_numpy(self, key: list | np.ndarray) -> np.ndarray:
15881588 # loop over chunks coming from slices before and after array indices
15891589 for cprior_tuple in product (* cprior_slices ):
15901590 out_prior_selection , prior_selection , loc_prior_selection = _get_selection (
1591- cprior_tuple , prior_tuple , chunks [:begin ]
1591+ cprior_tuple , prior_tuple , chunks [:begin ], shape
15921592 )
15931593 for cpost_tuple in product (* cpost_slices ):
15941594 out_post_selection , post_selection , loc_post_selection = _get_selection (
1595- cpost_tuple , post_tuple , chunks [end :] if end is not None else []
1595+ cpost_tuple , post_tuple , chunks [end :] if end is not None else [], shape
15961596 )
15971597 locbegin , locend = _get_local_slice (
15981598 prior_selection , post_selection , (chunk_begin , chunk_end )
@@ -1813,6 +1813,9 @@ def __setitem__( # noqa : C901
18131813 _slice = tuple (slice (s , st , stp ) for s , st , stp in zip (start , stop , step , strict = True ))
18141814 # this will work only for positive steps
18151815 intersecting_chunks = [slice_to_chunktuple (s , c ) for s , c in zip (pos_key , chunks , strict = True )]
1816+ intersecting_chunks = [
1817+ (0 ,) if i == () else i for i in intersecting_chunks
1818+ ] # special case of dims with 0 length
18161819 if isinstance (value , int | float | bool ): # overwrite updater function for simple cases (faster)
18171820
18181821 def updater (sel_idx ):
@@ -4799,18 +4802,18 @@ def _get_selection(ctuple, ptuple, chunks, shape, load_full=False):
47994802
48004803 # selection relative to coordinates of out (necessarily out_step = +-1)
48014804 # when added n + 1 elements
4802- # ps.start = pt.start + step * n + k => n = (ps.start - pt.start - sign) // step
4805+ # ps.start = pt.start + step * (n+1) => n = (ps.start - pt.start - sign) // step
48034806 # hence, out_start = n + 1 or shape(out) - 1 - (n + 1) if step < 0
4804- # ps.stop = pt.start + step * out_stop + k
4805- # => out_stop = (ps.stop - pt.start - sign) // step
4807+ # ps.stop = pt.start + step * ( out_stop - 1) + k, k in [step, -1] or [1, step]
4808+ # => out_stop = (ps.stop - pt.start - sign) // step + 1
48064809 out_pselection = ()
48074810 i = 0
48084811 for ps , pt in zip (pselection , ptuple , strict = True ):
48094812 sign_ = pt .step // builtins .abs (pt .step )
48104813 n = (ps .start - pt .start - sign_ ) // pt .step
48114814 out_start = n + 1 if sign_ > 0 else shape [i ] - (n + 1 ) - 1
48124815 # ps.stop always positive except for case where get full array (it is then -1 since desire 0th element)
4813- out_stop = None if ps .stop == - 1 else (ps .stop - pt .start - sign_ ) // pt .step
4816+ out_stop = None if ps .stop == - 1 else (ps .stop - pt .start - sign_ ) // pt .step + 1
48144817 out_pselection += (
48154818 slice (
48164819 out_start ,
0 commit comments