@@ -158,6 +158,24 @@ def _infer_coords_and_dims(
158
158
return new_coords , dims
159
159
160
160
161
+ def _check_data_shape (data , coords , dims ):
162
+ if data is dtypes .NA :
163
+ data = np .nan
164
+ if coords is not None and utils .is_scalar (data , include_0d = False ):
165
+ if utils .is_dict_like (coords ):
166
+ if dims is None :
167
+ return data
168
+ else :
169
+ data_shape = tuple (
170
+ as_variable (coords [k ], k ).size if k in coords .keys () else 1
171
+ for k in dims
172
+ )
173
+ else :
174
+ data_shape = tuple (as_variable (coord , "foo" ).size for coord in coords )
175
+ data = np .full (data_shape , data )
176
+ return data
177
+
178
+
161
179
class _LocIndexer :
162
180
def __init__ (self , data_array : "DataArray" ):
163
181
self .data_array = data_array
@@ -234,7 +252,7 @@ class DataArray(AbstractArray, DataWithCoords):
234
252
235
253
def __init__ (
236
254
self ,
237
- data : Any ,
255
+ data : Any = dtypes . NA ,
238
256
coords : Union [Sequence [Tuple ], Mapping [Hashable , Any ], None ] = None ,
239
257
dims : Union [Hashable , Sequence [Hashable ], None ] = None ,
240
258
name : Hashable = None ,
@@ -323,6 +341,7 @@ def __init__(
323
341
if encoding is None :
324
342
encoding = getattr (data , "encoding" , None )
325
343
344
+ data = _check_data_shape (data , coords , dims )
326
345
data = as_compatible_data (data )
327
346
coords , dims = _infer_coords_and_dims (data .shape , coords , dims )
328
347
variable = Variable (dims , data , attrs , encoding , fastpath = True )
@@ -700,30 +719,17 @@ def reset_coords(
700
719
drop : bool, optional
701
720
If True, remove coordinates instead of converting them into
702
721
variables.
703
- inplace : bool, optional
704
- If True, modify this object in place. Otherwise, create a new
705
- object.
706
722
707
723
Returns
708
724
-------
709
- Dataset, or DataArray if ``drop == True``, or None if
710
- ``inplace == True``
725
+ Dataset, or DataArray if ``drop == True``
711
726
"""
712
- inplace = _check_inplace (inplace )
713
- if inplace and not drop :
714
- raise ValueError (
715
- "cannot reset coordinates in-place on a "
716
- "DataArray without ``drop == True``"
717
- )
727
+ _check_inplace (inplace )
718
728
if names is None :
719
729
names = set (self .coords ) - set (self .dims )
720
730
dataset = self .coords .to_dataset ().reset_coords (names , drop )
721
731
if drop :
722
- if inplace :
723
- self ._coords = dataset ._variables
724
- return None
725
- else :
726
- return self ._replace (coords = dataset ._variables )
732
+ return self ._replace (coords = dataset ._variables )
727
733
else :
728
734
if self .name is None :
729
735
raise ValueError (
@@ -1026,32 +1032,6 @@ def sel(
1026
1032
)
1027
1033
return self ._from_temp_dataset (ds )
1028
1034
1029
- def isel_points (self , dim = "points" , ** indexers ) -> "DataArray" :
1030
- """Return a new DataArray whose data is given by pointwise integer
1031
- indexing along the specified dimension(s).
1032
-
1033
- See Also
1034
- --------
1035
- Dataset.isel_points
1036
- """
1037
- ds = self ._to_temp_dataset ().isel_points (dim = dim , ** indexers )
1038
- return self ._from_temp_dataset (ds )
1039
-
1040
- def sel_points (
1041
- self , dim = "points" , method = None , tolerance = None , ** indexers
1042
- ) -> "DataArray" :
1043
- """Return a new DataArray whose dataset is given by pointwise selection
1044
- of index labels along the specified dimension(s).
1045
-
1046
- See Also
1047
- --------
1048
- Dataset.sel_points
1049
- """
1050
- ds = self ._to_temp_dataset ().sel_points (
1051
- dim = dim , method = method , tolerance = tolerance , ** indexers
1052
- )
1053
- return self ._from_temp_dataset (ds )
1054
-
1055
1035
def broadcast_like (
1056
1036
self , other : Union ["DataArray" , Dataset ], exclude : Iterable [Hashable ] = None
1057
1037
) -> "DataArray" :
@@ -1511,9 +1491,6 @@ def set_index(
1511
1491
append : bool, optional
1512
1492
If True, append the supplied index(es) to the existing index(es).
1513
1493
Otherwise replace the existing index(es) (default).
1514
- inplace : bool, optional
1515
- If True, set new index(es) in-place. Otherwise, return a new
1516
- DataArray object.
1517
1494
**indexes_kwargs: optional
1518
1495
The keyword arguments form of ``indexes``.
1519
1496
One of indexes or indexes_kwargs must be provided.
@@ -1522,7 +1499,6 @@ def set_index(
1522
1499
-------
1523
1500
obj : DataArray
1524
1501
Another DataArray, with this data but replaced coordinates.
1525
- Return None if inplace=True.
1526
1502
1527
1503
Example
1528
1504
-------
@@ -1552,14 +1528,10 @@ def set_index(
1552
1528
--------
1553
1529
DataArray.reset_index
1554
1530
"""
1555
- inplace = _check_inplace (inplace )
1531
+ _check_inplace (inplace )
1556
1532
indexes = either_dict_or_kwargs (indexes , indexes_kwargs , "set_index" )
1557
1533
coords , _ = merge_indexes (indexes , self ._coords , set (), append = append )
1558
- if inplace :
1559
- self ._coords = coords
1560
- return None
1561
- else :
1562
- return self ._replace (coords = coords )
1534
+ return self ._replace (coords = coords )
1563
1535
1564
1536
def reset_index (
1565
1537
self ,
@@ -1577,36 +1549,29 @@ def reset_index(
1577
1549
drop : bool, optional
1578
1550
If True, remove the specified indexes and/or multi-index levels
1579
1551
instead of extracting them as new coordinates (default: False).
1580
- inplace : bool, optional
1581
- If True, modify the dataarray in-place. Otherwise, return a new
1582
- DataArray object.
1583
1552
1584
1553
Returns
1585
1554
-------
1586
1555
obj : DataArray
1587
1556
Another dataarray, with this dataarray's data but replaced
1588
- coordinates. If ``inplace == True``, return None.
1557
+ coordinates.
1589
1558
1590
1559
See Also
1591
1560
--------
1592
1561
DataArray.set_index
1593
1562
"""
1594
- inplace = _check_inplace (inplace )
1563
+ _check_inplace (inplace )
1595
1564
coords , _ = split_indexes (
1596
1565
dims_or_levels , self ._coords , set (), self ._level_coords , drop = drop
1597
1566
)
1598
- if inplace :
1599
- self ._coords = coords
1600
- return None
1601
- else :
1602
- return self ._replace (coords = coords )
1567
+ return self ._replace (coords = coords )
1603
1568
1604
1569
def reorder_levels (
1605
1570
self ,
1606
1571
dim_order : Mapping [Hashable , Sequence [int ]] = None ,
1607
1572
inplace : bool = None ,
1608
1573
** dim_order_kwargs : Sequence [int ]
1609
- ) -> Optional [ "DataArray" ] :
1574
+ ) -> "DataArray" :
1610
1575
"""Rearrange index levels using input order.
1611
1576
1612
1577
Parameters
@@ -1615,9 +1580,6 @@ def reorder_levels(
1615
1580
Mapping from names matching dimensions and values given
1616
1581
by lists representing new level orders. Every given dimension
1617
1582
must have a multi-index.
1618
- inplace : bool, optional
1619
- If True, modify the dataarray in-place. Otherwise, return a new
1620
- DataArray object.
1621
1583
**dim_order_kwargs: optional
1622
1584
The keyword arguments form of ``dim_order``.
1623
1585
One of dim_order or dim_order_kwargs must be provided.
@@ -1626,9 +1588,9 @@ def reorder_levels(
1626
1588
-------
1627
1589
obj : DataArray
1628
1590
Another dataarray, with this dataarray's data but replaced
1629
- coordinates. If ``inplace == True``, return None.
1591
+ coordinates.
1630
1592
"""
1631
- inplace = _check_inplace (inplace )
1593
+ _check_inplace (inplace )
1632
1594
dim_order = either_dict_or_kwargs (dim_order , dim_order_kwargs , "reorder_levels" )
1633
1595
replace_coords = {}
1634
1596
for dim , order in dim_order .items ():
@@ -1639,11 +1601,7 @@ def reorder_levels(
1639
1601
replace_coords [dim ] = IndexVariable (coord .dims , index .reorder_levels (order ))
1640
1602
coords = self ._coords .copy ()
1641
1603
coords .update (replace_coords )
1642
- if inplace :
1643
- self ._coords = coords
1644
- return None
1645
- else :
1646
- return self ._replace (coords = coords )
1604
+ return self ._replace (coords = coords )
1647
1605
1648
1606
def stack (
1649
1607
self ,
0 commit comments