-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add MetricWriter class #107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the direction this is taking! Could you add some examples of how to use this in the __doc__
and check the docs compile correctly and look good too?
fgpyo/util/metric.py
Outdated
""" | ||
|
||
delimiter: str = "\t" | ||
comment: str = "#" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we anticipate multiple comment prefixes?
comment: str = "#" | |
comment_prefixes: set[str] = {"#"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is unlikely to occur in practice and makes the interface clunkier.
Could you provide an example of a file format that would have multiple prefixes? I can't think of one off the top of my head.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UCSC BED files come to mind, but they also lack a header with named fields entirely. This is one of those API decisions that's hard to go back on since it will be a breaking change in the future, but not now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding the API correctly, this wouldn't only activate for mixed comment prefixes in the same file, but allow for setting multiple comment prefixes across files too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments
fgpyo/util/metric.py
Outdated
""" | ||
|
||
delimiter: str = "\t" | ||
comment: str = "#" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
837ebba
to
e712dfe
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## ms_metric-writer-assertions #107 +/- ##
==============================================================
Coverage ? 88.56%
==============================================================
Files ? 16
Lines ? 1775
Branches ? 378
==============================================================
Hits ? 1572
Misses ? 134
Partials ? 69 ☔ View full report in Codecov by Sentry. |
@@ -466,3 +481,240 @@ def asdict(metric: Metric) -> Dict[str, Any]: | |||
"The provided metric is not an instance of a `dataclass` or `attr.s`-decorated Metric " | |||
f"class: {metric.__class__}" | |||
) | |||
|
|||
|
|||
class MetricWriter(Generic[MetricType], AbstractContextManager): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO docs
(possibly in one more PR after the API is finalized. These are all landing in the feature branch #123 , updates -including docs - can be added to that branch before a final merge into main)
c6615d9
to
43f2f3e
Compare
|
||
Raises: | ||
ValueError: If the provided file does not include a header. | ||
ValueError: If the header of the provided file does not match the provided Metric. | ||
ValueError: If the header of the provided file does not match the provided Metric (or list | ||
of ordered fieldnames, if provided). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- or -> and
- where does
ordered_fieldnames
get checked?
* All fieldnames specified in `include_fields` must be fields on `metric_class`. If this | ||
argument is specified, fields will be returned in the order they appear in the list. | ||
* All fieldnames specified in `exclude_fields` must be fields on `metric_class`. (This is | ||
technically unnecessary, but is a safeguard against passing an incorrect list.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how strongly do we feel about this safeguard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump
0fd747b
to
beee947
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few outstanding comments, as well as I think we want to make write
accept one or more metrics
"""Close the underlying file handle.""" | ||
self._fout.close() | ||
|
||
def write(self, metric: Metric) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def write(self, metric: Metric) -> None: | |
def write(self, *metric: Metric) -> None: |
why not make this varargs
? Can the return be a MetricType
? For both, see:
Line 243 in cd554be
def write(cls, path: Path, *values: MetricType) -> None: |
|
||
self._writer.writerow(row) | ||
|
||
def writeall(self, metrics: Iterable[Metric]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed if we change write
?
* All fieldnames specified in `include_fields` must be fields on `metric_class`. If this | ||
argument is specified, fields will be returned in the order they appear in the list. | ||
* All fieldnames specified in `exclude_fields` must be fields on `metric_class`. (This is | ||
technically unnecessary, but is a safeguard against passing an incorrect list.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump
This PR introduces several of the assertion methods used when constructing the `MetricWriter`. (See #107 for how they are used in practice).
wip wip wip refactor: reorder refactor: types fix: PR suggestions fix: typeerror fix: format values chore: typeguard refactor: make assertions private fix: Union and Optional to support 3.8,3.9 doc: update dataclass/Metric references fix: use Type to support 3.8 fix: use List to support 3.8
8a6db00
to
5ad5dfa
Compare
This PR introduces several of the assertion methods used when constructing the `MetricWriter`. (See #107 for how they are used in practice).
Closes #88. I've adapted the `DataclassWriter` from https://github.com/msto/dataclass_io/ to work with Metrics.
This PR introduces several of the assertion methods used when constructing the `MetricWriter`. (See #107 for how they are used in practice).
Closes #88. I've adapted the `DataclassWriter` from https://github.com/msto/dataclass_io/ to work with Metrics.
Closes #88.
I've adapted the
DataclassWriter
from https://github.com/msto/dataclass_io/ to work with Metrics.