@@ -1327,8 +1327,9 @@ def full_like(other, fill_value, dtype: DTypeLike = None):
1327
1327
Value to fill the new object with before returning it. If
1328
1328
other is a Dataset, may also be a dict-like mapping data
1329
1329
variables to fill values.
1330
- dtype : dtype, optional
1331
- dtype of the new array. If omitted, it defaults to other.dtype.
1330
+ dtype : dtype or dict-like of dtype, optional
1331
+ dtype of the new array. If a dict-like, maps dtypes to
1332
+ variables. If omitted, it defaults to other.dtype.
1332
1333
1333
1334
Returns
1334
1335
-------
@@ -1407,6 +1408,14 @@ def full_like(other, fill_value, dtype: DTypeLike = None):
1407
1408
Data variables:
1408
1409
a (x) int64 1 1 1
1409
1410
b (x) int64 2 2 2
1411
+ >>> xr.full_like(ds, fill_value={"a": 1, "b": 2}, dtype={"a": bool, "b": float})
1412
+ <xarray.Dataset>
1413
+ Dimensions: (x: 3)
1414
+ Coordinates:
1415
+ * x (x) int64 2 4 6
1416
+ Data variables:
1417
+ a (x) bool True True True
1418
+ b (x) float64 2.0 2.0 2.0
1410
1419
1411
1420
See also
1412
1421
--------
@@ -1430,8 +1439,11 @@ def full_like(other, fill_value, dtype: DTypeLike = None):
1430
1439
if not isinstance (fill_value , dict ):
1431
1440
fill_value = {k : fill_value for k in other .data_vars .keys ()}
1432
1441
1442
+ if not isinstance (dtype , dict ):
1443
+ dtype = {k : dtype for k in other .data_vars .keys ()}
1444
+
1433
1445
data_vars = {
1434
- k : _full_like_variable (v , fill_value .get (k , dtypes .NA ), dtype )
1446
+ k : _full_like_variable (v , fill_value .get (k , dtypes .NA ), dtype . get ( k , None ) )
1435
1447
for k , v in other .data_vars .items ()
1436
1448
}
1437
1449
return Dataset (data_vars , coords = other .coords , attrs = other .attrs )
0 commit comments