Skip to content

Commit c5d8c87

Browse files
committed
improve docstrings
1 parent f484736 commit c5d8c87

2 files changed

Lines changed: 45 additions & 18 deletions

File tree

src/zarr/codecs/cast_value.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,35 @@ class CastValue(ArrayArrayCodec):
142142
Value-converts array elements to a new data type during encoding,
143143
and back to the original data type during decoding.
144144
145-
Requires the ``cast-value-rs`` package for the actual casting logic.
145+
Requires the `cast-value-rs` package for the actual casting logic.
146146
147147
Parameters
148148
----------
149-
data_type : str
150-
Target zarr v3 data type name (e.g. "uint8", "float32").
149+
data_type : str or ZDType
150+
Target zarr v3 data type. Strings are looked up by spec name
151+
(e.g. "uint8", "float32"); a `ZDType` instance is used as-is.
151152
rounding : RoundingMode
152-
How to round when exact representation is impossible. Default is "nearest-even".
153+
How to round when exact representation is impossible. Default is
154+
"nearest-even".
153155
out_of_range : OutOfRangeMode or None
154-
What to do when a value is outside the target's range.
155-
None means error. "clamp" clips to range. "wrap" uses modular arithmetic
156-
(only valid for integer types).
157-
scalar_map : dict or None
158-
Explicit mapping from input scalars to output scalars.
156+
What to do when a value is outside the target's range. `None` means
157+
error; "clamp" clips to range; "wrap" uses modular arithmetic
158+
(only valid for integer types). Default is `None`.
159+
scalar_map : ScalarMap, ScalarMapJSON, or None
160+
Explicit mapping from input scalars to output scalars. Default is
161+
`None`.
162+
163+
Attributes
164+
----------
165+
dtype : ZDType
166+
Resolved target data type (a `ZDType` instance, regardless of
167+
whether the constructor received a string or a `ZDType`).
168+
rounding : RoundingMode
169+
The rounding mode, as supplied to the constructor.
170+
out_of_range : OutOfRangeMode or None
171+
The out-of-range behaviour, as supplied to the constructor.
172+
scalar_map : ScalarMap or None
173+
Parsed scalar map (always normalized to `ScalarMap` form).
159174
160175
References
161176
----------

src/zarr/codecs/scale_offset.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,20 +283,32 @@ def _decode(
283283
class ScaleOffset(ArrayArrayCodec):
284284
"""Scale-offset array-to-array codec.
285285
286-
Encodes values with ``out = (in - offset) * scale`` and decodes with
287-
``out = (in / scale) + offset``, using the input array's data type semantics.
286+
Encodes values with `out = (in - offset) * scale` and decodes with
287+
`out = (in / scale) + offset`, using the input array's data type semantics.
288288
Intermediate or final values that are not representable in that dtype are reported
289289
as errors (integer overflow, unsigned underflow, non-exact integer division).
290290
291-
See https://github.com/zarr-developers/zarr-extensions/tree/main/codecs/scale_offset
292-
for the codec specification.
293-
294291
Parameters
295292
----------
296-
offset : float
297-
Value subtracted during encoding. Default is 0.
298-
scale : float
299-
Value multiplied during encoding (after offset subtraction). Default is 1.
293+
offset : int, float, or str
294+
Value subtracted during encoding. Strings preserve the exact JSON
295+
representation when round-tripping metadata. Default is 0.
296+
scale : int, float, or str
297+
Value multiplied during encoding (after offset subtraction). Strings
298+
preserve the exact JSON representation when round-tripping metadata.
299+
Default is 1.
300+
301+
Attributes
302+
----------
303+
offset : int, float, or str
304+
The offset value, as supplied to the constructor.
305+
scale : int, float, or str
306+
The scale value, as supplied to the constructor.
307+
308+
References
309+
----------
310+
311+
- The `scale_offset` codec spec: https://github.com/zarr-developers/zarr-extensions/tree/main/codecs/scale_offset
300312
"""
301313

302314
is_fixed_size = True

0 commit comments

Comments
 (0)