from dascore.units import maybe_convert_percent_to_fraction, get_quantity
# Convert a single percentage to fraction
result = maybe_convert_percent_to_fraction(get_quantity("50%"))
assert result == [0.5]
# Convert a list with percentages
result = maybe_convert_percent_to_fraction(
[get_quantity("25%"), get_quantity("75%")]
)
assert result == [0.25, 0.75]
# Non-percentage values are unchanged
result = maybe_convert_percent_to_fraction([get_quantity("10 m"), 5])
assert result[0] == get_quantity("10 m")
assert result[1] == 5
# Mixed values
result = maybe_convert_percent_to_fraction(
[get_quantity("100%"), 0.5, get_quantity("2 Hz")]
)
assert result[0] == 1.0
assert result[1] == 0.5
assert result[2] == get_quantity("2 Hz")maybe_convert_percent_to_fraction
maybe_convert_percent_to_fraction(
obj ,
)
Iterate an object and convert any percentages to fractions.
Parameters
| Parameter | Description |
|---|---|
| obj | The input object. Can be a single value or an iterable. |
Returns
list A list where any percentage quantities are converted to their fractional equivalents (e.g., 50% becomes 0.5).