nitypes.scalar.Scalar
- class nitypes.scalar.Scalar(value: TScalar_co, units: str = '', *, extended_properties: collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None = None, copy_extended_properties: bool = True)
Bases:
Generic[TScalar_co]A scalar data class, which encapsulates scalar data and units information.
Constructing
To construct a scalar data object, use the
Scalarclass:>>> Scalar(False) nitypes.scalar.Scalar(value=False) >>> Scalar(0) nitypes.scalar.Scalar(value=0) >>> Scalar(5.0, 'volts') nitypes.scalar.Scalar(value=5.0, units='volts') >>> Scalar("value", "volts") nitypes.scalar.Scalar(value='value', units='volts')
Comparing Scalar Objects
You can compare scalar objects using standard comparison operators:
<,<=,>,>=,==, and!=. Detailed descriptions of operator behaviors are provided below.Equality Comparison Operators
Equality comparison operators (
==and!=) are always supported and behave as follows:Comparison of scalar objects with compatible types and identical units results in
TrueorFalsebased on the comparison of scalar object values.Comparison of scalar objects with incompatible types (such as numeric and string) results in inequality.
Comparison of scalar objects with different units results in inequality.
Here are a few examples:
>>> Scalar(5.0, 'V') == Scalar(5.0, 'V') # Numeric scalars with identical values and units True >>> Scalar(5.0, 'V') == Scalar(12.3, 'V') # Numeric scalars with identical units False >>> Scalar(5.0, 'V') != Scalar(12.3, 'V') # Numeric scalars with identical units True >>> Scalar("apple") == Scalar("banana") # String scalars False >>> Scalar("apple") == Scalar("Apple") # String scalars - note case sensitivity False >>> Scalar(0.5, 'V') == Scalar(500, 'mV') # Numeric scalars with different units False >>> Scalar(5.0, 'V') == Scalar("5.0", 'V') # Comparison of a numeric and a string scalar False
Order Comparison Operators
Order comparison operators (
<,<=,>, and>=) behave as follows:Comparison of scalar objects with compatible types and identical units results in
TrueorFalsebased on the comparison of scalar object values.Comparison of scalar objects with incompatible types (such as numeric and string) is not permitted and will raise a
TypeErrorexception.Comparison of scalar objects with compatible types and different units is not permitted and will raise a
ValueErrorexception.
Here are a few examples:
>>> Scalar(5.0, 'V') < Scalar(10.0, 'V') # Numeric scalars with identical units True >>> Scalar(5.0, 'V') >= Scalar(10.0, 'V') # Numeric scalars with identical units False >>> Scalar("apple") < Scalar("banana") # String scalars True >>> Scalar("apple") < Scalar("Banana") # String scalars - note case sensitivity False >>> Scalar(5.0, 'V') < Scalar("5.0", 'V') # Comparison of a numeric and a string scalar Traceback (most recent call last): ... TypeError: Comparing Scalar objects of numeric and string types is not permitted. >>> Scalar(0.5, 'V') < Scalar(500, 'mV') # Numeric scalars with different units Traceback (most recent call last): ... ValueError: Comparing Scalar objects with different units is not permitted.
Class Members
- __slots__ = ['_value', '_extended_properties']
- property value: TScalar_co
The scalar value.
- Return type:
- property extended_properties: nitypes.waveform.ExtendedPropertyDictionary
The extended properties for the scalar.
Note
Data stored in the extended properties dictionary may not be encrypted when you send it over the network or write it to a TDMS file.
- Return type:
- __gt__(other: Scalar[TScalar_co], /) bool
Return self > other.
- Parameters:
other (Scalar[TScalar_co])
- Return type:
- __ge__(other: Scalar[TScalar_co], /) bool
Return self >= other.
- Parameters:
other (Scalar[TScalar_co])
- Return type:
- __lt__(other: Scalar[TScalar_co], /) bool
Return self < other.
- Parameters:
other (Scalar[TScalar_co])
- Return type:
- __le__(other: Scalar[TScalar_co], /) bool
Return self <= other.
- Parameters:
other (Scalar[TScalar_co])
- Return type:
- Parameters:
value (TScalar_co)
units (str)
extended_properties (collections.abc.Mapping[str, nitypes.waveform.typing.ExtendedPropertyValue] | None)
copy_extended_properties (bool)