@@ -375,13 +375,39 @@ def dequantify(self, format=None):
375
375
Parameters
376
376
----------
377
377
format : str, optional
378
- The format used for the string representations.
378
+ The format specification (as accepted by pint) used for the string
379
+ representations.
379
380
380
381
Returns
381
382
-------
382
383
dequantified : DataArray
383
384
DataArray whose array data is unitless, and of the type
384
385
that was previously wrapped by `pint.Quantity`.
386
+
387
+ See Also
388
+ --------
389
+ https://pint.readthedocs.io/en/stable/tutorial.html#string-formatting
390
+
391
+ Examples
392
+ --------
393
+ >>> da = xr.DataArray([0, 1], dims="x")
394
+ >>> q = da.pint.quantify("m")
395
+ >>> q
396
+ <xarray.DataArray (x: 2)>
397
+ <Quantity([0 1], 'meter')>
398
+ Dimensions without coordinates: x
399
+ >>> q.pint.dequantify(format="P")
400
+ <xarray.DataArray (x: 2)>
401
+ array([0, 1])
402
+ Dimensions without coordinates: x
403
+ Attributes:
404
+ units: meter
405
+ >>> q.pint.dequantify(format="~P")
406
+ <xarray.DataArray (x: 2)>
407
+ array([0, 1])
408
+ Dimensions without coordinates: x
409
+ Attributes:
410
+ units: m
385
411
"""
386
412
units = conversion .extract_unit_attributes (self .da )
387
413
units .update (conversion .extract_units (self .da ))
@@ -1027,13 +1053,58 @@ def dequantify(self, format=None):
1027
1053
Parameters
1028
1054
----------
1029
1055
format : str, optional
1030
- The format used for the string representations.
1056
+ The format specification (as accepted by pint) used for the string
1057
+ representations.
1031
1058
1032
1059
Returns
1033
1060
-------
1034
1061
dequantified : Dataset
1035
1062
Dataset whose data variables are unitless, and of the type
1036
1063
that was previously wrapped by ``pint.Quantity``.
1064
+
1065
+ See Also
1066
+ --------
1067
+ https://pint.readthedocs.io/en/stable/tutorial.html#string-formatting
1068
+
1069
+ Examples
1070
+ --------
1071
+ >>> ds = xr.Dataset({"a": ("x", [0, 1]), "b": ("y", [2, 3, 4])})
1072
+ >>> q = ds.pint.quantify({"a": "m", "b": "s"})
1073
+ >>> q
1074
+ <xarray.Dataset>
1075
+ Dimensions: (x: 2, y: 3)
1076
+ Dimensions without coordinates: x, y
1077
+ Data variables:
1078
+ a (x) int64 [m] 0 1
1079
+ b (y) int64 [s] 2 3 4
1080
+
1081
+ >>> d = q.pint.dequantify(format="P")
1082
+ >>> d.a
1083
+ <xarray.DataArray 'a' (x: 2)>
1084
+ array([0, 1])
1085
+ Dimensions without coordinates: x
1086
+ Attributes:
1087
+ units: meter
1088
+ >>> d.b
1089
+ <xarray.DataArray 'b' (y: 3)>
1090
+ array([2, 3, 4])
1091
+ Dimensions without coordinates: y
1092
+ Attributes:
1093
+ units: second
1094
+
1095
+ >>> d = q.pint.dequantify(format="~P")
1096
+ >>> d.a
1097
+ <xarray.DataArray 'a' (x: 2)>
1098
+ array([0, 1])
1099
+ Dimensions without coordinates: x
1100
+ Attributes:
1101
+ units: m
1102
+ >>> d.b
1103
+ <xarray.DataArray 'b' (y: 3)>
1104
+ array([2, 3, 4])
1105
+ Dimensions without coordinates: y
1106
+ Attributes:
1107
+ units: s
1037
1108
"""
1038
1109
units = conversion .extract_unit_attributes (self .ds )
1039
1110
units .update (conversion .extract_units (self .ds ))
0 commit comments