NVIDIA Morpheus (24.10.01)

morpheus.utils.type_utils

Utility functions for working with types.

Functions

cpp_mode_to_exec_mode() Return the execution mode based on the configuration of the global morpheus.config.CppConfig singleton.
df_type_str_to_exec_mode(df_type_str) Return the appropriate execution mode based on the DataFrame type string.
df_type_str_to_pkg(df_type_str) Import and return the appropriate DataFrame package based on the DataFrame type string.
exec_mode_to_df_type_str(execution_mode) Return the appropriate DataFrame type string based on the execution mode.
flatten_types(type_list) Flattens a list of types, removing any union and typing.Any types.
get_array_pkg([execution_mode]) Return the appropriate array package (CuPy for GPU, NumPy for CPU) based on the execution mode.
get_df_class() Return the appropriate DataFrame selector which can be either an ExecutionMode instance, a DataFrame type string, or None.
get_df_pkg() Return the appropriate DataFrame package based on selector which can be either an ExecutionMode instance, a DataFrame type string, or None.
get_df_pkg_from_obj(obj) Return the appropriate DataFrame package based on a given object (DataFrame, Series, RangeIndex etc...).
get_full_qualname(klass) Returns the fully qualified name of a class.
greatest_ancestor(*cls_list) Returns the greatest common ancestor of the classes in the class list
is_cudf_type(obj) Check if a given object (DataFrame, Series, RangeIndex etc...) is a cuDF type.
is_dataframe(obj) Check if a given object is a pandas or cudf DataFrame.
is_union_type(type_) Returns True if the type is a typing.Union or a types.UnionType.
pretty_print_type_name(type_) Determines a good label to use for a type.
unpack_tuple()

unpack_union()

cpp_mode_to_exec_mode()[source]

Return the execution mode based on the configuration of the global morpheus.config.CppConfig singleton.

Returns
morpheus.config.ExecutionMode

The 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_strmorpheus.utils.type_aliases.DataFrameModule

The DataFrame type string.

Returns
morpheus.config.ExecutionMode

The 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_strmorpheus.utils.type_aliases.DataFrameModule

The DataFrame type string.

Returns
types.ModuleType

The 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_modemorpheus.config.ExecutionMode

The execution mode.

Returns
morpheus.utils.type_aliases.DataFrameModule

The associated DataFrame type string based on the execution mode.

flatten_types(type_list)[source]

Flattens a list of types, removing any union and typing.Any types.

get_array_pkg(execution_mode=None)[source]

Return the appropriate array package (CuPy for GPU, NumPy for CPU) based on the execution mode.

When None the execution mode is determined by the global morpheus.config.CppConfig singleton.

Parameters
execution_modemorpheus.config.ExecutionMode, optional

The execution mode, by default None.

Returns
types.ModuleType

The associated array package based on the execution mode.

get_df_class(selector: Literal['cudf', 'pandas'] = None) → type[DataFrameType][source]
get_df_class(selector: morpheus.config.ExecutionMode = None) → type[DataFrameType]

Return the appropriate DataFrame selector which can be either an ExecutionMode instance, a DataFrame type string, or None.

When None the execution mode is determined by the global morpheus.config.CppConfig singleton.

This method is best used within code which needs to construct a DataFrame in both CPU and GPU modes. Example usage:

Copy
Copied!
            

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
selectormorpheus.utils.type_aliases.DataFrameModule | morpheus.config.ExecutionMode | None, optional

The selector to determine the DataFrame class, by default None.

Returns
type[DataFrameType]
get_df_pkg(selector: Literal['cudf', 'pandas'] = None) → module[source]
get_df_pkg(selector: morpheus.config.ExecutionMode = None) → module

Return the appropriate DataFrame package based on selector which can be either an ExecutionMode instance, a DataFrame type string, or None.

When None the execution mode is determined by the global morpheus.config.CppConfig singleton.

This method is best used within code which needs to operate in both CPU and GPU modes, where simply importing cudf would cause an import error if the user is not using a GPU. Example usage:

Copy
Copied!
            

from morpheus.utils.type_utils import get_df_pkg df_pkg = get_df_pkg() ser = df_pkg.Series([1,2,3])

Parameters
selectormorpheus.utils.type_aliases.DataFrameModule | morpheus.config.ExecutionMode | None, optional

The selector to determine the DataFrame package, by default None.

Returns
types.ModuleType

The 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
objtyping.Any

The object to check.

Returns
types.ModuleType

The associated DataFrame package based on the object.

get_full_qualname(klass)[source]

Returns the fully qualified name of a class.

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
objtyping.Any

The object to check.

Returns
bool

True if the object is a cuDF type, False otherwise.

is_dataframe(obj)[source]

Check if a given object is a pandas or cudf DataFrame.

Parameters
objtyping.Any

The object to check.

Returns
bool

True if the object is a DataFrame, False otherwise.

is_union_type(type_)[source]

Returns True if the type is a typing.Union or a types.UnionType.

pretty_print_type_name(type_)[source]

Determines a good label to use for a type. Keeps the strings shorter.

unpack_tuple(cls_1: Type[morpheus.utils.type_utils.T]) → Tuple[Type[morpheus.utils.type_utils.T]][source]
unpack_tuple(cls_1: Type[morpheus.utils.type_utils.T1], cls_2: Type[morpheus.utils.type_utils.T2]) → Tuple[Type[morpheus.utils.type_utils.T1], Type[morpheus.utils.type_utils.T2]]
unpack_tuple(cls_1: Type[morpheus.utils.type_utils.T1], cls_2: Type[morpheus.utils.type_utils.T2], cls_3: Type[morpheus.utils.type_utils.T3]) → Tuple[Type[morpheus.utils.type_utils.T1], Type[morpheus.utils.type_utils.T2], Type[morpheus.utils.type_utils.T3]]
unpack_union(cls_1: Type[morpheus.utils.type_utils.T]) → Type[morpheus.utils.type_utils.T][source]
unpack_union(cls_1: Type[morpheus.utils.type_utils.T1], cls_2: Type[morpheus.utils.type_utils.T2]) → Union[Type[morpheus.utils.type_utils.T1], Type[morpheus.utils.type_utils.T2]]
unpack_union(cls_1: Type[morpheus.utils.type_utils.T1], cls_2: Type[morpheus.utils.type_utils.T2], cls_3: Type[morpheus.utils.type_utils.T3]) → Union[Type[morpheus.utils.type_utils.T1], Type[morpheus.utils.type_utils.T2], Type[morpheus.utils.type_utils.T3]]
Previous morpheus.utils.type_aliases
Next morpheus_dfp
© Copyright 2024, NVIDIA. Last updated on Dec 3, 2024.