is_data_size

function of dascore.units source

is_data_size(
    value: Any ,
)-> ‘bool’

Return True if value is a quantity of information (bytes, bits, MB, …).

Pint treats information as dimensionless, so a compatibility check against bytes also passes for percents and bare dimensionless quantities. The base unit is the only reliable discriminator.

Parameters

Parameter Description
value Any value of any type to test if it is a data size quantity.

Examples

import dascore as dc
from dascore.units import is_data_size

assert is_data_size(25 * dc.units.megabytes)
assert is_data_size(dc.get_quantity("1 MiB"))

# Percents, strain and plain numbers are not sizes.
assert not is_data_size(dc.get_quantity("50%"))
assert not is_data_size(25)