Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 0971cbc

Browse files
Byambaa0325pdxjohnny
authored andcommitted
feature: Convert tests to doctests and add example
Signed-off-by: John Andersen <[email protected]>
1 parent 0fa15d9 commit 0971cbc

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Ability to run a subflow as if it were an operation using the
1919
`dffml.dataflow.run` operation.
2020
- Support for operations without inputs.
21+
- Partial doctestable examples to `features.py`
2122
### Fixed
2223
- New model tutorial mentions file paths that should be edited.
2324
- DataFlow is no longer a dataclass to prevent it from being exported

dffml/feature/feature.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,27 @@ class and implement the fetch, parse, and calc methods. These methods are
113113
Once the appropriate data is fetched the parse method is responsible for
114114
storing the parts of that data which will be used to calculate in the
115115
subclass
116+
117+
Examples
118+
--------
119+
120+
Define a feature using load_def:
121+
>>> feature = Feature.load_def("example", "float", 10)
122+
>>> feature.dtype()
123+
float
124+
>>> feature.NAME
125+
"example"
126+
>>> feature.length()
127+
10
128+
129+
Defining a feature directly using DefFeature:
130+
>>> feature = DefFeature("example2", "int", 20)
131+
>>> feature.dtype()
132+
int
133+
>>> feature.NAME
134+
"example2"
135+
>>> feature.length()
136+
20
116137
"""
117138

118139
LOGGER = LOGGER.getChild("Feature")
@@ -147,6 +168,13 @@ def _fromdict(cls, **kwargs):
147168
def dtype(self) -> Type:
148169
"""
149170
Models need to know a Feature's datatype.
171+
172+
Examples
173+
--------
174+
175+
>>> feature = Feature()
176+
>>> feature.dtype()
177+
int
150178
"""
151179
self.LOGGER.warning("%s dtype unimplemented", self)
152180
return int
@@ -155,6 +183,13 @@ def length(self) -> int:
155183
"""
156184
Models need to know a Feature's length, 1 means single value, more than
157185
that is the length of the array calc returns.
186+
187+
Examples
188+
--------
189+
190+
>>> feature = Feature()
191+
>>> feature.length()
192+
1
158193
"""
159194
self.LOGGER.warning("%s length unimplemented", self)
160195
return 1

0 commit comments

Comments
 (0)