3535from  zarr .core .buffer  import  (
3636    BufferPrototype ,
3737    NDArrayLike ,
38+     NDArrayLikeOrScalar ,
3839    NDBuffer ,
3940    default_buffer_prototype ,
4041)
@@ -1256,7 +1257,7 @@ async def _get_selection(
12561257        prototype : BufferPrototype ,
12571258        out : NDBuffer  |  None  =  None ,
12581259        fields : Fields  |  None  =  None ,
1259-     ) ->  NDArrayLike :
1260+     ) ->  NDArrayLikeOrScalar :
12601261        # check fields are sensible 
12611262        out_dtype  =  check_fields (fields , self .dtype )
12621263
@@ -1298,14 +1299,16 @@ async def _get_selection(
12981299                out_buffer ,
12991300                drop_axes = indexer .drop_axes ,
13001301            )
1302+         if  isinstance (indexer , BasicIndexer ) and  indexer .shape  ==  ():
1303+             return  out_buffer .as_scalar ()
13011304        return  out_buffer .as_ndarray_like ()
13021305
13031306    async  def  getitem (
13041307        self ,
13051308        selection : BasicSelection ,
13061309        * ,
13071310        prototype : BufferPrototype  |  None  =  None ,
1308-     ) ->  NDArrayLike :
1311+     ) ->  NDArrayLikeOrScalar :
13091312        """ 
13101313        Asynchronous function that retrieves a subset of the array's data based on the provided selection. 
13111314
@@ -1318,7 +1321,7 @@ async def getitem(
13181321
13191322        Returns 
13201323        ------- 
1321-         NDArrayLike  
1324+         NDArrayLikeOrScalar  
13221325            The retrieved subset of the array's data. 
13231326
13241327        Examples 
@@ -2268,14 +2271,15 @@ def __array__(
22682271            msg  =  "`copy=False` is not supported. This method always creates a copy." 
22692272            raise  ValueError (msg )
22702273
2271-         arr_np  =  self [...]
2274+         arr  =  self [...]
2275+         arr_np : NDArrayLike  =  np .array (arr , dtype = dtype )
22722276
22732277        if  dtype  is  not   None :
22742278            arr_np  =  arr_np .astype (dtype )
22752279
22762280        return  arr_np 
22772281
2278-     def  __getitem__ (self , selection : Selection ) ->  NDArrayLike :
2282+     def  __getitem__ (self , selection : Selection ) ->  NDArrayLikeOrScalar :
22792283        """Retrieve data for an item or region of the array. 
22802284
22812285        Parameters 
@@ -2286,8 +2290,8 @@ def __getitem__(self, selection: Selection) -> NDArrayLike:
22862290
22872291        Returns 
22882292        ------- 
2289-         NDArrayLike  
2290-              An array-like containing the data for the requested region. 
2293+         NDArrayLikeOrScalar  
2294+              An array-like or scalar  containing the data for the requested region. 
22912295
22922296        Examples 
22932297        -------- 
@@ -2533,7 +2537,7 @@ def get_basic_selection(
25332537        out : NDBuffer  |  None  =  None ,
25342538        prototype : BufferPrototype  |  None  =  None ,
25352539        fields : Fields  |  None  =  None ,
2536-     ) ->  NDArrayLike :
2540+     ) ->  NDArrayLikeOrScalar :
25372541        """Retrieve data for an item or region of the array. 
25382542
25392543        Parameters 
@@ -2551,8 +2555,8 @@ def get_basic_selection(
25512555
25522556        Returns 
25532557        ------- 
2554-         NDArrayLike  
2555-             An array-like containing the data for the requested region. 
2558+         NDArrayLikeOrScalar  
2559+             An array-like or scalar  containing the data for the requested region. 
25562560
25572561        Examples 
25582562        -------- 
@@ -2753,7 +2757,7 @@ def get_orthogonal_selection(
27532757        out : NDBuffer  |  None  =  None ,
27542758        fields : Fields  |  None  =  None ,
27552759        prototype : BufferPrototype  |  None  =  None ,
2756-     ) ->  NDArrayLike :
2760+     ) ->  NDArrayLikeOrScalar :
27572761        """Retrieve data by making a selection for each dimension of the array. For 
27582762        example, if an array has 2 dimensions, allows selecting specific rows and/or 
27592763        columns. The selection for each dimension can be either an integer (indexing a 
@@ -2775,8 +2779,8 @@ def get_orthogonal_selection(
27752779
27762780        Returns 
27772781        ------- 
2778-         NDArrayLike  
2779-             An array-like containing the data for the requested selection. 
2782+         NDArrayLikeOrScalar  
2783+             An array-like or scalar  containing the data for the requested selection. 
27802784
27812785        Examples 
27822786        -------- 
@@ -2989,7 +2993,7 @@ def get_mask_selection(
29892993        out : NDBuffer  |  None  =  None ,
29902994        fields : Fields  |  None  =  None ,
29912995        prototype : BufferPrototype  |  None  =  None ,
2992-     ) ->  NDArrayLike :
2996+     ) ->  NDArrayLikeOrScalar :
29932997        """Retrieve a selection of individual items, by providing a Boolean array of the 
29942998        same shape as the array against which the selection is being made, where True 
29952999        values indicate a selected item. 
@@ -3009,8 +3013,8 @@ def get_mask_selection(
30093013
30103014        Returns 
30113015        ------- 
3012-         NDArrayLike  
3013-             An array-like containing the data for the requested selection. 
3016+         NDArrayLikeOrScalar  
3017+             An array-like or scalar  containing the data for the requested selection. 
30143018
30153019        Examples 
30163020        -------- 
@@ -3151,7 +3155,7 @@ def get_coordinate_selection(
31513155        out : NDBuffer  |  None  =  None ,
31523156        fields : Fields  |  None  =  None ,
31533157        prototype : BufferPrototype  |  None  =  None ,
3154-     ) ->  NDArrayLike :
3158+     ) ->  NDArrayLikeOrScalar :
31553159        """Retrieve a selection of individual items, by providing the indices 
31563160        (coordinates) for each selected item. 
31573161
@@ -3169,8 +3173,8 @@ def get_coordinate_selection(
31693173
31703174        Returns 
31713175        ------- 
3172-         NDArrayLike  
3173-             An array-like containing the data for the requested coordinate selection. 
3176+         NDArrayLikeOrScalar  
3177+             An array-like or scalar  containing the data for the requested coordinate selection. 
31743178
31753179        Examples 
31763180        -------- 
@@ -3339,7 +3343,7 @@ def get_block_selection(
33393343        out : NDBuffer  |  None  =  None ,
33403344        fields : Fields  |  None  =  None ,
33413345        prototype : BufferPrototype  |  None  =  None ,
3342-     ) ->  NDArrayLike :
3346+     ) ->  NDArrayLikeOrScalar :
33433347        """Retrieve a selection of individual items, by providing the indices 
33443348        (coordinates) for each selected item. 
33453349
@@ -3357,8 +3361,8 @@ def get_block_selection(
33573361
33583362        Returns 
33593363        ------- 
3360-         NDArrayLike  
3361-             An array-like containing the data for the requested block selection. 
3364+         NDArrayLikeOrScalar  
3365+             An array-like or scalar  containing the data for the requested block selection. 
33623366
33633367        Examples 
33643368        -------- 
0 commit comments