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

Commit 67848a0

Browse files
authored
record: Docstrings and examples for features and evaluated
1 parent 4e82403 commit 67848a0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Documentation on writing examples and running doctests
1313
- Doctestable Examples to high-level API.
1414
- Shouldi got an operation to run npm-audit on JavaScript code
15+
- Docstrings and doctestable examples for `record.py` (features and evaluated)
1516
### Changed
1617
- Restructured contributing documentation
1718
- Use randomly generated data for scikit tests

dffml/record.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,27 @@ def key(self) -> str:
182182
def evaluated(self, results: Dict[str, Any], overwrite=False):
183183
"""
184184
Updates features with the result dict
185+
186+
Parameters
187+
----------
188+
results : dict
189+
The results that will be added to the features.
190+
overwrite : boolean
191+
If 'True', the function overwrites the current features with the results provided.
192+
If 'Fasle', the function updates the current features with the results provided.
193+
194+
Examples
195+
--------
196+
>>> example = Record("example", data=dict(features=dict(dead="beef")))
197+
>>> print(example.features())
198+
{'dead': 'beef'}
199+
>>> results = {"new": "feature"}
200+
>>> example.evaluated({"feed": "face"})
201+
>>> print(example.features())
202+
{'dead': 'beef', 'feed': 'face'}
203+
>>> example.evaluated(results, overwrite=True)
204+
>>> print(example.features())
205+
{'new': 'feature'}
185206
"""
186207
if overwrite:
187208
self.data.features = results
@@ -193,6 +214,23 @@ def evaluated(self, results: Dict[str, Any], overwrite=False):
193214
def features(self, subset: List[str] = []) -> Dict[str, Any]:
194215
"""
195216
Returns all features for the record or the subset specified.
217+
218+
Parameters
219+
----------
220+
subset : list
221+
The subset of features that will be returned.
222+
223+
Returns
224+
-------
225+
dict
226+
features.
227+
228+
Examples
229+
--------
230+
>>> example = Record("example", data=dict(features=dict(dead="beef")))
231+
>>>
232+
>>> print(example.features(["dead"]))
233+
{'dead': 'beef'}
196234
"""
197235
if not subset:
198236
return self.data.features

docs/doctest_header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
os.chdir(DOCTEST_TEMPDIR)
1818

1919
from dffml_model_scikit import *
20-
20+
from dffml.record import RecordPrediction, RecordData, Record
2121
from dffml import *
2222
from dffml.base import *
2323
from dffml.df.base import *

0 commit comments

Comments
 (0)