SpecialValues#
- class gamspy.SpecialValues[source]#
Bases:
objectUtility class representing GAMS special values and methods to test for their presence.
In GAMS, special values are used to represent missing data, undefined operations, infinities, or structural zeros (EPS). This class defines GAMSPy equivalents for these values. It also provides vectorized static methods to efficiently check for these special values across integers, floats, strings, pandas Series, pandas DataFrames, or array-like objects.
- Attributes:
- NAfloat
GAMS NA (Not Available), unpacked from a specific hexadecimal representation (“fffffffffffffffe”).
- EPSfloat
GAMS EPS (Epsilon), represented as a negative zero (-0.0).
- UNDEFfloat
GAMS UNDEF (Undefined), represented as Not a Number (NaN).
- POSINFfloat
GAMS POSINF (Positive Infinity), represented as float(“inf”).
- NEGINFfloat
GAMS NEGINF (Negative Infinity), represented as float(“-inf”).
Methods
isEps(records)Check if the input records represent a value close to zero with specific considerations for different data types.
isNA(records)Check if values in records represent GAMS NA (Not Available) values.
isNegInf(records)Check if the input records represent negative infinity.
isPosInf(records)Check if the input records represent positive infinity.
isUndef(records)Determine if the given input(s) represent GAMS "undef" values.
Examples
Basic usage of attributes
>>> from gamspy._special_values import SpecialValues >>> SpecialValues.EPS -0.0 >>> SpecialValues.POSINF inf
Testing for special values in data structures
>>> import numpy as np >>> import pandas as pd >>> data = pd.Series([1.5, -0.0, float("inf"), SpecialValues.NA]) >>> SpecialValues.isEps(data) array([False, True, False, False]) >>> SpecialValues.isNA(data) array([False, False, False, True])
- static isEps(records: int | float | str | pd.Series | pd.DataFrame) np.ndarray[source]#
Check if the input records represent a value close to zero with specific considerations for different data types.
- Parameters:
- records: int | float | str | pd.Series | pd.DataFrame | array-like
The input records to be checked for proximity to zero.
- Returns:
- np.ndarray
True if the input records represent a value close to zero according to the specified conditions, False otherwise.
- Raises:
- Exception
If the input (string) records cannot be converted to a float.
- Exception
If the data structure passed in ‘records’ could not be converted to a numpy array (dtype=float) for testing.
- static isNA(records: int | float | str | pd.Series | pd.DataFrame) np.ndarray[source]#
Check if values in records represent GAMS NA (Not Available) values.
- Parameters:
- records: int | float | str | pd.Series | pd.DataFrame | array-like
The input records to be checked for GAMS NA values.
- Returns:
- np.ndarray
True if the values in records represent GAMS NA values; otherwise, False.
- Raises:
- Exception
If the input (string) records cannot be converted to a float.
- Exception
If the data structure passed in ‘records’ could not be converted to a numpy array (dtype=float) for testing.
- static isNegInf(records: int | float | str | pd.Series | pd.DataFrame) np.ndarray | np.bool[source]#
Check if the input records represent negative infinity.
- Parameters:
- records: int | float | str | pd.Series | pd.DataFrame | array-like
The input records to be checked for negative infinity values.
- Returns:
- np.ndarray | np.bool
True if the values in records represent negative infinity values; otherwise, False.
- Raises:
- Exception
If the input (string) records cannot be converted to a float.
- Exception
If the data structure passed in ‘records’ could not be converted to a numpy array (dtype=float) for testing.
- static isPosInf(records: int | float | str | pd.Series | pd.DataFrame) np.ndarray | np.bool[source]#
Check if the input records represent positive infinity.
- Parameters:
- records: int | float | str | pd.Series | pd.DataFrame | array-like
The input records to be checked for positive infinity values.
- Returns:
- np.ndarray | np.bool
True if the values in records represent positive infinity values; otherwise, False.
- Raises:
- Exception
If the input (string) records cannot be converted to a float.
- Exception
If the data structure passed in ‘records’ could not be converted to a numpy array (dtype=float) for testing.
- static isUndef(records: int | float | str | pd.Series | pd.DataFrame) np.ndarray[source]#
Determine if the given input(s) represent GAMS “undef” values.
- Parameters:
- records: int | float | str | pd.Series | pd.DataFrame | array-like
The input records to be checked for GAMS “undef” values.
- Returns:
- np.ndarray
True if the values in records represent GAMS “undef” values; otherwise, False.
- Raises:
- Exception
If the input (string) records cannot be converted to a float.
- Exception
If the data structure passed in ‘records’ could not be converted to a numpy array (dtype=float) for testing.
- EPS = -0.0#
- NA = nan#
- NEGINF = -inf#
- POSINF = inf#
- UNDEF = nan#