morpheus.utils.type_utils#
Utility functions for working with types.
Functions
Return the execution mode based on the configuration of the global |
|
|
Return the appropriate execution mode based on the DataFrame type string. |
|
Import and return the appropriate DataFrame package based on the DataFrame type string. |
|
Return the appropriate DataFrame type string based on the execution mode. |
|
Flattens a list of types, removing any union and |
|
Return the appropriate array package (CuPy for GPU, NumPy for CPU) based on the execution mode. |
Return the appropriate DataFrame |
|
Return the appropriate DataFrame package based on |
|
|
Return the appropriate DataFrame package based on a given object (DataFrame, Series, RangeIndex etc...). |
|
Returns the fully qualified name of a class. |
|
Returns the greatest common ancestor of the classes in the class list |
|
Check if a given object (DataFrame, Series, RangeIndex etc...) is a cuDF type. |
|
Check if a given object is a pandas or cudf DataFrame. |
|
Returns True if the type is a |
|
Determines a good label to use for a type. |
- cpp_mode_to_exec_mode()[source]#
Return the execution mode based on the configuration of the global
morpheus.config.CppConfigsingleton.- Returns:
morpheus.config.ExecutionModeThe execution mode.
- df_type_str_to_exec_mode(df_type_str)[source]#
Return the appropriate execution mode based on the DataFrame type string.
- Parameters:
- df_type_str
morpheus.utils.type_aliases.DataFrameModule The DataFrame type string.
- df_type_str
- Returns:
morpheus.config.ExecutionModeThe associated execution mode based on the DataFrame type string.
- df_type_str_to_pkg(df_type_str)[source]#
Import and return the appropriate DataFrame package based on the DataFrame type string.
- Parameters:
- df_type_str
morpheus.utils.type_aliases.DataFrameModule The DataFrame type string.
- df_type_str
- Returns:
types.ModuleTypeThe associated DataFrame package based on the DataFrame type string.
- exec_mode_to_df_type_str(execution_mode)[source]#
Return the appropriate DataFrame type string based on the execution mode.
- Parameters:
- execution_mode
morpheus.config.ExecutionMode The execution mode.
- execution_mode
- Returns:
morpheus.utils.type_aliases.DataFrameModuleThe associated DataFrame type string based on the execution mode.
- flatten_types(type_list)[source]#
Flattens a list of types, removing any union and
typing.Anytypes.
- get_array_pkg(execution_mode=None)[source]#
Return the appropriate array package (CuPy for GPU, NumPy for CPU) based on the execution mode.
When
Nonethe execution mode is determined by the globalmorpheus.config.CppConfigsingleton.- Parameters:
- execution_mode
morpheus.config.ExecutionMode, optional The execution mode, by default
None.
- execution_mode
- Returns:
types.ModuleTypeThe associated array package based on the execution mode.
- get_df_class(
- selector: Literal['cudf', 'pandas'] = None,
- get_df_class(
- selector: ExecutionMode = None,
Return the appropriate DataFrame
selectorwhich can be either anExecutionModeinstance, a DataFrame type string, orNone.When
Nonethe execution mode is determined by the globalmorpheus.config.CppConfigsingleton.This method is best used within code which needs to construct a DataFrame in both CPU and GPU modes. Example usage:
from morpheus.utils.type_utils import get_df_class df_class = get_df_class() df = df_class({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
- Parameters:
- selector
morpheus.utils.type_aliases.DataFrameModule|morpheus.config.ExecutionMode| None, optional The selector to determine the DataFrame class, by default None.
- selector
- Returns:
type[DataFrameType]
- get_df_pkg(
- selector: Literal['cudf', 'pandas'] = None,
- get_df_pkg(
- selector: ExecutionMode = None,
Return the appropriate DataFrame package based on
selectorwhich can be either anExecutionModeinstance, a DataFrame type string, orNone.When
Nonethe execution mode is determined by the globalmorpheus.config.CppConfigsingleton.This method is best used within code which needs to operate in both CPU and GPU modes, where simply importing
cudfwould cause an import error if the user is not using a GPU. Example usage:from morpheus.utils.type_utils import get_df_pkg df_pkg = get_df_pkg() ser = df_pkg.Series([1,2,3])
- Parameters:
- selector
morpheus.utils.type_aliases.DataFrameModule|morpheus.config.ExecutionMode| None, optional The selector to determine the DataFrame package, by default None.
- selector
- Returns:
types.ModuleTypeThe associated DataFrame package based on the selector.
- get_df_pkg_from_obj(obj)[source]#
Return the appropriate DataFrame package based on a given object (DataFrame, Series, RangeIndex etc…).
- Parameters:
- obj
typing.Any The object to check.
- obj
- Returns:
types.ModuleTypeThe associated DataFrame package based on the object.
- greatest_ancestor(*cls_list)[source]#
Returns the greatest common ancestor of the classes in the class list
- is_cudf_type(obj)[source]#
Check if a given object (DataFrame, Series, RangeIndex etc…) is a cuDF type.
- Parameters:
- obj
typing.Any The object to check.
- obj
- Returns:
- is_dataframe(obj)[source]#
Check if a given object is a pandas or cudf DataFrame.
- Parameters:
- obj
typing.Any The object to check.
- obj
- Returns:
- is_union_type(type_)[source]#
Returns True if the type is a
typing.Unionor atypes.UnionType.
- pretty_print_type_name(type_)[source]#
Determines a good label to use for a type. Keeps the strings shorter.