Skip to content

Commit 77d4920

Browse files
authored
Make the new marshmallow module experimental (#28)
This means we are not yet committing to a stable API between minor or patch releases. We also add missing quantities to the module documentation and sort `__all__`.
2 parents b2aa061 + c62c4cb commit 77d4920

File tree

5 files changed

+48
-19
lines changed

5 files changed

+48
-19
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ This is the initial release, extracted from the [SDK v1.0.0rc601](https://github
99
- Added support for `__round__` (`round(quantity)`), `__pos__` (`+quantity`) and `__mod__` (`quantity % quantity`) operators.
1010
- Add `ReactivePower` quantity.
1111
- Add `ApparentPower` quantity.
12-
- Add marshmallow module available when adding `[marshmallow]` to the requirements.
12+
- Add an **experimental** marshmallow module available when adding `[marshmallow]` to the requirements.
1313
* Add a QuantitySchema supporting string/float based serialization and deserialization of quantities.

src/frequenz/quantities/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
2525
This library provides the following types:
2626
27+
- [ApparentPower][frequenz.quantities.ApparentPower]: A quantity representing apparent
28+
power.
2729
- [Current][frequenz.quantities.Current]: A quantity representing an electric current.
2830
- [Energy][frequenz.quantities.Energy]: A quantity representing energy.
2931
- [Frequency][frequenz.quantities.Frequency]: A quantity representing frequency.
3032
- [Percentage][frequenz.quantities.Percentage]: A quantity representing a percentage.
3133
- [Power][frequenz.quantities.Power]: A quantity representing power.
34+
- [ReactivePower][frequenz.quantities.ReactivePower]: A quantity representing reactive
35+
power.
3236
- [Temperature][frequenz.quantities.Temperature]: A quantity representing temperature.
3337
- [Voltage][frequenz.quantities.Voltage]: A quantity representing electric voltage.
3438
35-
Additionally, for each of those types, there is a corresponding marshmallow
36-
field that can be used to serialize and deserialize the quantities using the
37-
[QuantitySchema][frequenz.quantities.marshmallow.QuantitySchema] schema.
38-
3939
There is also the unitless [Quantity][frequenz.quantities.Quantity] class. All
4040
quantities are subclasses of this class and it can be used as a base to create new
4141
quantities. Using the `Quantity` class directly is discouraged, as it doesn't provide
@@ -78,6 +78,12 @@
7878
except TypeError as e:
7979
print(f"Error: {e}") # Error: unsupported operand type(s) for +: 'Power' and 'Voltage'
8080
```
81+
82+
This library also provides an [**experimental** module with marshmallow fields and
83+
a base schema][frequenz.quantities.experimental.marshmallow] to serialize and
84+
deserialize quantities using the marshmallow library. To use it, you need to make sure
85+
to install this package with the `marshmallow` optional dependencies (e.g.
86+
`pip install frequenz-quantities[marshmallow]`).
8187
"""
8288

8389

@@ -93,14 +99,14 @@
9399
from ._voltage import Voltage
94100

95101
__all__ = [
102+
"ApparentPower",
96103
"Current",
97104
"Energy",
98105
"Frequency",
99106
"Percentage",
100107
"Power",
101108
"Quantity",
102109
"ReactivePower",
103-
"ApparentPower",
104110
"Temperature",
105111
"Voltage",
106112
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# License: All rights reserved
2+
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Experimental features for quantities.
5+
6+
Danger:
7+
This package contains experimental features for which the API is not yet stable.
8+
9+
Any module or class in this package may be removed or changed in a future release,
10+
even in minor or patch releases.
11+
"""

src/frequenz/quantities/marshmallow.py renamed to src/frequenz/quantities/experimental/marshmallow.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
# License: All rights reserved
22
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
33

4-
"""Custom marshmallow fields and schema."""
4+
"""Custom marshmallow fields and schema.
5+
6+
This module provides custom marshmallow fields for quantities and
7+
a [QuantitySchema][frequenz.quantities.experimental.marshmallow.QuantitySchema] class to
8+
be used as base schema for dataclasses containing quantities.
9+
10+
Danger:
11+
This module contains experimental features for which the API is not yet stable.
12+
13+
Any module or class in this package may be removed or changed in a future release,
14+
even in minor or patch releases.
15+
"""
516

617
from typing import Any, Type
718

819
from marshmallow import Schema, ValidationError, fields
920

10-
from ._apparent_power import ApparentPower
11-
from ._current import Current
12-
from ._energy import Energy
13-
from ._frequency import Frequency
14-
from ._percentage import Percentage
15-
from ._power import Power
16-
from ._quantity import Quantity
17-
from ._reactive_power import ReactivePower
18-
from ._temperature import Temperature
19-
from ._voltage import Voltage
21+
from .._apparent_power import ApparentPower
22+
from .._current import Current
23+
from .._energy import Energy
24+
from .._frequency import Frequency
25+
from .._percentage import Percentage
26+
from .._power import Power
27+
from .._quantity import Quantity
28+
from .._reactive_power import ReactivePower
29+
from .._temperature import Temperature
30+
from .._voltage import Voltage
2031

2132

2233
class _QuantityField(fields.Field):
@@ -194,7 +205,8 @@ class QuantitySchema(Schema):
194205
from dataclasses import dataclass, field
195206
from marshmallow_dataclass import class_schema
196207
from marshmallow.validate import Range
197-
from frequenz.quantities import Percentage, QuantitySchema
208+
from frequenz.quantities import Percentage
209+
from frequenz.quantities.experimental.marshmallow import QuantitySchema
198210
from typing import cast
199211
200212
@dataclass
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Temperature,
1919
Voltage,
2020
)
21-
from frequenz.quantities.marshmallow import QuantitySchema
21+
from frequenz.quantities.experimental.marshmallow import QuantitySchema
2222

2323

2424
@dataclass

0 commit comments

Comments
 (0)