Quantity Ranges

class nettlesome.quantities.QuantityRange(**data)

Base class for ranges that can be assigned to Predicates.

__hash__ = None
__str__()

Return str(self).

Return type

str

consistent_dimensionality(other)

Test if other has a quantity parameter consistent with self.

Return type

bool

contradicts(other)

Check if self’s interval excludes all of other’s interval.

Return type

bool

expression_comparison()

Convert text to a comparison with a quantity.

Return type

str

Returns

string representation of a comparison with a quantity, which can include units due to the pint library.

implies(other)

Check if self’s interval includes all of other’s interval.

Return type

bool

property interval: Union[sympy.sets.sets.FiniteSet, sympy.sets.sets.Interval, sympy.sets.sets.Union]

Get the range that the Comparison may refer to.

Return type

Union[FiniteSet, Interval, Union]

property lower_bound

Get lower bound of the range that the Comparison may refer to.

abstract property magnitude: Union[decimal.Decimal, int, float]

Get amount of max or minimum of the quantity range, without a unit.

Return type

Union[Decimal, int, float]

means(other)

Compare for same meaning.

Return type

bool

reverse_meaning()

Change self.sign in place to reverse the range of numbers covered.

>>> quantity_range = UnitRange(quantity="100 meters", sign=">")
>>> str(quantity_range)
'greater than 100 meter'
>>> quantity_range.reverse_meaning()
>>> quantity_range.sign
'<='
>>> str(quantity_range)
'no more than 100 meter'
Return type

None

class nettlesome.quantities.UnitRange(**data)

A range defined relative to a pint Quantity.

__hash__ = None
consistent_dimensionality(other)

Compare dimensionality of Quantities for self and other.

For instance, two units representing distance divided by time have the same dimensionality, even if one uses feet while the other uses meters.

Parameters

other (QuantityRange) – another QuantityRange with a quantity to compare

Return type

bool

Returns

whether the two dimensionalities are the same

contradicts(other)

Check if self’s quantity range has no overlap with other’s.

Return type

bool

property domain: sympy.sets.sets.Set

Get the domain of the quantity range.

Return type

Set

get_unit_converted_interval(other)

Get other’s interval if it was denominated in self’s units.

Return type

Union[Interval, FiniteSet, Union]

implies(other)

Check if self’s quantity range is a subset of other’s.

Parameters

other (Any) – another QuantityRange to compare

Return type

bool

Returns

whether other provides no information about the quantity that isn’t already provided by self

property magnitude: Union[int, float]

Get magnitude of pint Quantity.

Return type

Union[int, float]

means(other)

Whether self and other represent the same quantity range.

Return type

bool

property pint_quantity: pint.quantity.Quantity

Get the Quantity as a Pint object.

Return type

Quantity

classmethod validate_quantity(quantity)

Validate that quantity is a pint Quantity.

Return type

str

class nettlesome.quantities.IntRange(**data)

A range defined relative to an integer or float.

__hash__ = None
property domain: sympy.sets.sets.Set

Set domain as natural numbers.

Return type

Set

property magnitude: Union[int, float]

Return quantity attribute.

Return type

Union[int, float]

class nettlesome.quantities.DecimalRange(**data)

A range defined relative to an integer or float.

__hash__ = None
property domain: sympy.sets.sets.Set

Set domain as natural numbers.

Return type

Set

property magnitude: decimal.Decimal

Return quantity attribute.

Return type

Decimal

class nettlesome.quantities.DateRange(**data)

A range defined relative to a date.

__hash__ = None
property domain: sympy.sets.sets.Set

Set domain as natural numbers.

Return type

Set

property magnitude: Union[int, float]

Map dates to integers while preserving the order of the dates.

Return type

Union[int, float]