Skip to content

Add configurable value-remapping mixin #8

@msto

Description

@msto

Summary

The current Metric class has a _empty_field_to_none model validator that automatically converts empty string fields to None during parsing. This behavior is enabled by default for consistency with fgpyo's Metric, but could be improved with a more flexible, opt-in approach.

Context

#6 (comment)

It might be nice to have "" be a ClassVar so that users could override it with their own special "empty token".

The current implementation hardcodes the empty string to None conversion, which doesn't allow for:

  1. Disabling the behavior when not needed
  2. Customizing which values map to None
  3. Supporting multiple input representations (e.g., both "" and "None" -> None)
  4. Handling other sentinel values like "NA" -> np.nan

Suggested Solution

Create a mixin class (e.g., RemapValues) that:

  1. Uses a dict class variable for arbitrary value mappings instead of a single "empty token"
  2. Generalizes to support cases like:
    • multiple string representations of null: {"": None, "None": None}
    • mixed null/NaN handling: {"": None, "NA": np.nan}
  3. (Maybe?) Is opt-in rather than enabled by default on the base Metric class

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions