arkouda.testing

Functions

assert_almost_equal(→ None)

Check that the left and right objects are approximately equal.

assert_almost_equivalent(→ None)

Check that two objects are approximately equal.

assert_arkouda_array_equal(→ None)

Check that 'ak.pdarray' or 'ak.Strings', 'ak.Categorical', or 'ak.SegArray' is equivalent.

assert_arkouda_array_equivalent(→ None)

Check that two Arkouda-compatible arrays are equal.

assert_arkouda_pdarray_equal(→ None)

Check that the two 'ak.pdarray's are equivalent.

assert_arkouda_segarray_equal(→ None)

Check that the two 'ak.SegArray's are equivalent.

assert_arkouda_strings_equal(→ None)

Check that 'ak.Strings' is equivalent.

assert_attr_equal(→ None)

Check attributes are equal. Both objects must have attribute.

assert_categorical_equal(→ None)

Test that Categoricals are equivalent.

assert_class_equal(→ None)

Check classes are equal.

assert_contains_all(→ None)

Assert that a dictionary contains all the elements of an iterable.

assert_copy(→ None)

Check that the elements are equal, but not the same object.

assert_dict_equal(→ None)

Assert that two dictionaries are equal.

assert_equal(→ None)

Wrapper for tm.assert_*_equal to dispatch to the appropriate test function.

assert_equivalent(→ None)

Dispatch to the appropriate assertion function depending on object types.

assert_frame_equal(→ None)

Check that left and right DataFrame are equal.

assert_frame_equivalent(→ None)

Check that two DataFrames are equal.

assert_index_equal(→ None)

Check that left and right Index are equal.

assert_index_equivalent(→ None)

Check that two Index objects are equal.

assert_is_sorted(→ None)

Assert that the sequence is sorted.

assert_series_equal(→ None)

Check that left and right Series are equal.

assert_series_equivalent(→ None)

Check that two Series are equal.

Package Contents

arkouda.testing.assert_almost_equal(left, right, rtol: float = 1e-05, atol: float = 1e-08, **kwargs) None[source]

Check that the left and right objects are approximately equal.

By approximately equal, we refer to objects that are numbers or that contain numbers which may be equivalent to specific levels of precision.

Parameters:
  • left (object)

  • right (object)

  • rtol (float, default 1e-5) – Relative tolerance.

  • atol (float, default 1e-8) – Absolute tolerance.

Warning

This function cannot be used on pdarray of size > ak.client.maxTransferBytes because it converts pdarrays to numpy arrays and calls np.allclose.

arkouda.testing.assert_almost_equivalent(left, right, rtol: float = 1e-05, atol: float = 1e-08) None[source]

Check that two objects are approximately equal.

By approximately equal, we refer to objects that are numbers or that contain numbers which may be equivalent to specific levels of precision.

If the objects are pandas or numpy objects, they are converted to Arkouda objects. Then assert_almost_equal is applied to the result.

Parameters:
  • left (object) – First object to compare.

  • right (object) – Second object to compare.

  • rtol (float) – Relative tolerance. Default is 1e-5.

  • atol (float) – Absolute tolerance. Default is 1e-8.

Raises:

TypeError – If either input is not a supported numeric-like type.

Warning

This function cannot be used on pdarrays of size > ak.client.maxTransferBytes because it converts pdarrays to numpy arrays and calls np.allclose.

Examples

>>> import arkouda as ak
>>> from arkouda.testing import assert_almost_equivalent
>>> assert_almost_equivalent(0.123456, 0.123457, rtol=1e-4)
arkouda.testing.assert_arkouda_array_equal(left: arkouda.pdarray | arkouda.Strings | arkouda.Categorical | arkouda.SegArray, right: arkouda.pdarray | arkouda.Strings | arkouda.Categorical | arkouda.SegArray, check_dtype: bool = True, err_msg=None, check_same=None, obj: str = 'pdarray', index_values=None) None[source]

Check that ‘ak.pdarray’ or ‘ak.Strings’, ‘ak.Categorical’, or ‘ak.SegArray’ is equivalent.

Parameters:
  • left (pdarray or Strings or Categorical or SegArray) – The two arrays to be compared.

  • right (pdarray or Strings or Categorical or SegArray) – The two arrays to be compared.

  • check_dtype (bool, default True) – Check dtype if both a and b are ak.pdarray.

  • err_msg (str, default None) – If provided, used as assertion message.

  • check_same (None|'copy'|'same', default None) – Ensure left and right refer/do not refer to the same memory area.

  • obj (str, default 'numpy array') – Specify object name being compared, internally used to show appropriate assertion message.

  • index_values (Index | arkouda.pdarray, default None) – optional index (shared by both left and right), used in output.

arkouda.testing.assert_arkouda_array_equivalent(left: arkouda.pdarray | arkouda.Strings | arkouda.Categorical | arkouda.SegArray | numpy.ndarray | pandas.Categorical, right: arkouda.pdarray | arkouda.Strings | arkouda.Categorical | arkouda.SegArray | numpy.ndarray | pandas.Categorical, check_dtype: bool = True, err_msg=None, check_same=None, obj: str = 'pdarray', index_values=None) None[source]

Check that two Arkouda-compatible arrays are equal.

Supported types include numpy arrays, pandas Categorical, and Arkouda arrays.

Parameters:
  • left (pdarray, Strings, Categorical, SegArray, np.ndarray, or pd.Categorical) – First array to compare.

  • right (pdarray, Strings, Categorical, SegArray, np.ndarray, or pd.Categorical) – Second array to compare.

  • check_dtype (bool) – Whether to verify that dtypes match. Default is True.

  • err_msg (str or None) – Optional message to display on failure.

  • check_same (None or {"copy", "same"}) – Whether to ensure identity or separation in memory. Default is None.

  • obj (str) – Object label for error messages. Default is “pdarray”.

  • index_values (Index or pdarray, optional) – Shared index used in error output. Default is None.

Raises:

TypeError – If either input is not a supported array type.

Examples

>>> import arkouda as ak
>>> from arkouda import Strings
>>> from arkouda.testing import assert_arkouda_array_equivalent
>>> a = ak.array([1, 2, 3])
>>> b = ak.array([1, 2, 3])
>>> assert_arkouda_array_equivalent(a, b)
>>> s1 = ak.array(['x', 'y'])
>>> s2 = ak.array(['x', 'y'])
>>> assert_arkouda_array_equivalent(s1, s2)
arkouda.testing.assert_arkouda_pdarray_equal(left: arkouda.pdarray, right: arkouda.pdarray, check_dtype: bool = True, err_msg=None, check_same=None, obj: str = 'pdarray', index_values=None) None[source]

Check that the two ‘ak.pdarray’s are equivalent.

Parameters:
  • left (arkouda.pdarray) – The two arrays to be compared.

  • right (arkouda.pdarray) – The two arrays to be compared.

  • check_dtype (bool, default True) – Check dtype if both a and b are ak.pdarray.

  • err_msg (str, default None) – If provided, used as assertion message.

  • check_same (None|'copy'|'same', default None) – Ensure left and right refer/do not refer to the same memory area.

  • obj (str, default 'pdarray') – Specify object name being compared, internally used to show appropriate assertion message.

  • index_values (Index | arkouda.pdarray, default None) – optional index (shared by both left and right), used in output.

arkouda.testing.assert_arkouda_segarray_equal(left: arkouda.SegArray, right: arkouda.SegArray, check_dtype: bool = True, err_msg=None, check_same=None, obj: str = 'segarray') None[source]

Check that the two ‘ak.SegArray’s are equivalent.

Parameters:
  • left (arkouda.numpy.SegArray) – The two segarrays to be compared.

  • right (arkouda.numpy.SegArray) – The two segarrays to be compared.

  • check_dtype (bool, default True) – Check dtype if both a and b are ak.pdarray.

  • err_msg (str, default None) – If provided, used as assertion message.

  • check_same (None|'copy'|'same', default None) – Ensure left and right refer/do not refer to the same memory area.

  • obj (str, default 'pdarray') – Specify object name being compared, internally used to show appropriate assertion message.

arkouda.testing.assert_arkouda_strings_equal(left, right, err_msg=None, check_same=None, obj: str = 'Strings', index_values=None) None[source]

Check that ‘ak.Strings’ is equivalent.

Parameters:
  • left (arkouda.numpy.Strings) – The two Strings to be compared.

  • right (arkouda.numpy.Strings) – The two Strings to be compared.

  • err_msg (str, default None) – If provided, used as assertion message.

  • check_same (None|'copy'|'same', default None) – Ensure left and right refer/do not refer to the same memory area.

  • obj (str, default 'Strings') – Specify object name being compared, internally used to show appropriate assertion message.

  • index_values (Index | arkouda.pdarray, default None) – optional index (shared by both left and right), used in output.

arkouda.testing.assert_attr_equal(attr: str, left, right, obj: str = 'Attributes') None[source]

Check attributes are equal. Both objects must have attribute.

Parameters:
  • attr (str) – Attribute name being compared.

  • left (object)

  • right (object)

  • obj (str, default 'Attributes') – Specify object name being compared, internally used to show appropriate assertion message

arkouda.testing.assert_categorical_equal(left, right, check_dtype: bool = True, check_category_order: bool = True, obj: str = 'Categorical') None[source]

Test that Categoricals are equivalent.

Parameters:
  • left (Categorical)

  • right (Categorical)

  • check_dtype (bool, default True) – Check that integer dtype of the codes are the same.

  • check_category_order (bool, default True) – Whether the order of the categories should be compared, which implies identical integer codes. If False, only the resulting values are compared. The ordered attribute is checked regardless.

  • obj (str, default 'Categorical') – Specify object name being compared, internally used to show appropriate assertion message.

arkouda.testing.assert_class_equal(left, right, exact: bool = True, obj: str = 'Input') None[source]

Check classes are equal.

arkouda.testing.assert_contains_all(iterable, dic) None[source]

Assert that a dictionary contains all the elements of an iterable. :param iterable: :type iterable: iterable :param dic: :type dic: dict

arkouda.testing.assert_copy(iter1, iter2, **eql_kwargs) None[source]

Check that the elements are equal, but not the same object. (Does not check that items in sequences are also not the same object.)

Parameters:
  • iter1 (iterable) – Iterables that produce elements comparable with assert_almost_equal.

  • iter2 (iterable) – Iterables that produce elements comparable with assert_almost_equal.

arkouda.testing.assert_dict_equal(left, right, compare_keys: bool = True) None[source]

Assert that two dictionaries are equal. Values must be arkouda objects. :param left: The dictionaries to be compared. :type left: dict :param right: The dictionaries to be compared. :type right: dict :param compare_keys: Whether to compare the keys.

If False, only the values are compared.

arkouda.testing.assert_equal(left, right, **kwargs) None[source]

Wrapper for tm.assert_*_equal to dispatch to the appropriate test function.

Parameters:
arkouda.testing.assert_equivalent(left, right, **kwargs) None[source]

Dispatch to the appropriate assertion function depending on object types.

Parameters:
  • left (Any) – First object to compare. Type determines which assertion function is used.

  • right (Any) – Second object to compare.

  • **kwargs (dict) – Keyword arguments passed to the specific assertion function.

Raises:

AssertionError – If values are not equivalent.

Examples

>>> import arkouda as ak
>>> import pandas as pd
>>> from arkouda.testing import assert_equivalent
>>> ak_series = ak.Series([1, 2, 3])
>>> pd_series = pd.Series([1, 2, 3])
>>> assert_equivalent(ak_series, pd_series)
arkouda.testing.assert_frame_equal(left: arkouda.DataFrame, right: arkouda.DataFrame, check_dtype: bool = True, check_index_type: bool = True, check_column_type: bool = True, check_frame_type: bool = True, check_names: bool = True, check_exact: bool = True, check_categorical: bool = True, check_like: bool = False, rtol: float = 1e-05, atol: float = 1e-08, obj: str = 'DataFrame') None[source]

Check that left and right DataFrame are equal.

This function is intended to compare two DataFrames and output any differences. It is mostly intended for use in unit tests. Additional parameters allow varying the strictness of the equality checks performed.

Parameters:
  • left (DataFrame) – First DataFrame to compare.

  • right (DataFrame) – Second DataFrame to compare.

  • check_dtype (bool, default True) – Whether to check the DataFrame dtype is identical.

  • check_index_type (bool, default = True) – Whether to check the Index class, dtype and inferred_type are identical.

  • check_column_type (bool or {'equiv'}, default 'equiv') – Whether to check the columns class, dtype and inferred_type are identical. Is passed as the exact argument of assert_index_equal().

  • check_frame_type (bool, default True) – Whether to check the DataFrame class is identical.

  • check_names (bool, default True) – Whether to check that the names attribute for both the index and column attributes of the DataFrame is identical.

  • check_exact (bool, default False) – Whether to compare number exactly.

  • check_categorical (bool, default True) – Whether to compare internal Categorical exactly.

  • check_like (bool, default False) – If True, ignore the order of index & columns. Note: index labels must match their respective rows (same as in columns) - same labels must be with the same data.

  • rtol (float, default 1e-5) – Relative tolerance. Only used when check_exact is False.

  • atol (float, default 1e-8) – Absolute tolerance. Only used when check_exact is False.

  • obj (str, default 'DataFrame') – Specify object name being compared, internally used to show appropriate assertion message.

See also

assert_series_equal

Equivalent method for asserting Series equality.

Examples

>>> import arkouda as ak

This example shows comparing two DataFrames that are equal but with columns of differing dtypes.

>>> from arkouda.testing import assert_frame_equal
>>> df1 = ak.DataFrame({'a': [1, 2], 'b': [3, 4]})
>>> df2 = ak.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})

df1 equals itself. >>> assert_frame_equal(df1, df1)

df1 differs from df2 as column ‘b’ is of a different type. >>> assert_frame_equal(df1, df2) # doctest: +SKIP Traceback (most recent call last): … AssertionError: Attributes of DataFrame.iloc[:, 1] (column name=”b”) are different

Attribute “dtype” are different [left]: int64 [right]: float64

Ignore differing dtypes in columns with check_dtype.

>>> assert_frame_equal(df1, df2, check_dtype=False)
arkouda.testing.assert_frame_equivalent(left: arkouda.DataFrame | pandas.DataFrame, right: arkouda.DataFrame | pandas.DataFrame, check_dtype: bool = True, check_index_type: bool = True, check_column_type: bool = True, check_frame_type: bool = True, check_names: bool = True, check_exact: bool = True, check_categorical: bool = True, check_like: bool = False, rtol: float = 1e-05, atol: float = 1e-08, obj: str = 'DataFrame') None[source]

Check that two DataFrames are equal.

This function compares two DataFrames and raises an assertion if they differ. It is intended primarily for use in unit tests. pandas DataFrames are converted to Arkouda equivalents before comparison.

Parameters:
  • left (DataFrame or pd.DataFrame) – First DataFrame to compare.

  • right (DataFrame or pd.DataFrame) – Second DataFrame to compare.

  • check_dtype (bool) – Whether to check that dtypes are identical. Default is True.

  • check_index_type (bool) – Whether to check that index class, dtype, and inferred type are identical. Default is True.

  • check_column_type (bool) – Whether to check that column class, dtype, and inferred type are identical. Default is True.

  • check_frame_type (bool) – Whether to check that the DataFrame class is identical. Default is True.

  • check_names (bool) – Whether to check that the index and column names are identical. Default is True.

  • check_exact (bool) – Whether to compare values exactly. Default is True.

  • check_categorical (bool) – Whether to compare internal categoricals exactly. Default is True.

  • check_like (bool) – Whether to ignore the order of index and columns. Labels must still match their data. / Default is False.

  • rtol (float) – Relative tolerance used when check_exact is False. Default is 1e-5.

  • atol (float) – Absolute tolerance used when check_exact is False. Default is 1e-8.

  • obj (str) – Object name used in error messages. Default is “DataFrame”.

Raises:

TypeError – If either input is not a DataFrame or pd.DataFrame.

Examples

>>> import arkouda as ak
>>> import pandas as pd
>>> from arkouda.testing import assert_frame_equivalent
>>> df1 = ak.DataFrame({'a': [1, 2], 'b': [3, 4]})
>>> df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})

Fails because dtypes are different: >>> assert_frame_equivalent(df1, df2) # doctest: +SKIP

arkouda.testing.assert_index_equal(left: arkouda.Index, right: arkouda.Index, exact: bool = True, check_names: bool = True, check_exact: bool = True, check_categorical: bool = True, check_order: bool = True, rtol: float = 1e-05, atol: float = 1e-08, obj: str = 'Index') None[source]

Check that left and right Index are equal.

Parameters:
  • left (Index)

  • right (Index)

  • exact (True) – Whether to check the Index class, dtype and inferred_type are identical.

  • check_names (bool, default True) – Whether to check the names attribute.

  • check_exact (bool, default True) – Whether to compare number exactly.

  • check_categorical (bool, default True) – Whether to compare internal Categorical exactly.

  • check_order (bool, default True) – Whether to compare the order of index entries as well as their values. If True, both indexes must contain the same elements, in the same order. If False, both indexes must contain the same elements, but in any order.

  • rtol (float, default 1e-5) – Relative tolerance. Only used when check_exact is False.

  • atol (float, default 1e-8) – Absolute tolerance. Only used when check_exact is False.

  • obj (str, default 'Index') – Specify object name being compared, internally used to show appropriate assertion message.

Examples

>>> import arkouda as ak
>>> from arkouda import testing as tm
>>> a = ak.Index([1, 2, 3])
>>> b = ak.Index([1, 2, 3])
>>> tm.assert_index_equal(a, b)
arkouda.testing.assert_index_equivalent(left: arkouda.Index | pandas.Index, right: arkouda.Index | pandas.Index, exact: bool = True, check_names: bool = True, check_exact: bool = True, check_categorical: bool = True, check_order: bool = True, rtol: float = 1e-05, atol: float = 1e-08, obj: str = 'Index') None[source]

Check that two Index objects are equal.

If the objects are pandas Index, they are converted to Arkouda Index. Then assert_index_equal is applied to the result.

Parameters:
  • left (Index or pd.Index) – First Index to compare.

  • right (Index or pd.Index) – Second Index to compare.

  • exact (bool) – Whether to check that class, dtype, and inferred type are identical. Default is True.

  • check_names (bool) – Whether to check the names attribute. Default is True.

  • check_exact (bool) – Whether to compare values exactly. Default is True.

  • check_categorical (bool) – Whether to compare internal Categoricals exactly. Default is True.

  • check_order (bool) – Whether to require identical order in index values. Default is True.

  • rtol (float) – Relative tolerance used when check_exact is False. Default is 1e-5.

  • atol (float) – Absolute tolerance used when check_exact is False. Default is 1e-8.

  • obj (str) – Object name used in error messages. Default is “Index”.

Raises:

TypeError – If either input is not an Index or pd.Index.

Examples

>>> import arkouda as ak
>>> from arkouda import testing as tm
>>> import pandas as pd
>>> a = ak.Index([1, 2, 3])
>>> b = pd.Index([1, 2, 3])
>>> tm.assert_index_equivalent(a, b)
arkouda.testing.assert_is_sorted(seq) None[source]

Assert that the sequence is sorted.

arkouda.testing.assert_series_equal(left, right, check_dtype: bool = True, check_index_type: bool = True, check_series_type: bool = True, check_names: bool = True, check_exact: bool = False, check_categorical: bool = True, check_category_order: bool = True, rtol: float = 1e-05, atol: float = 1e-08, obj: str = 'Series', *, check_index: bool = True, check_like: bool = False) None[source]

Check that left and right Series are equal.

Parameters:
  • left (Series)

  • right (Series)

  • check_dtype (bool, default True) – Whether to check the Series dtype is identical.

  • check_index_type (bool, default True) – Whether to check the Index class, dtype and inferred_type are identical.

  • check_series_type (bool, default True) – Whether to check the Series class is identical.

  • check_names (bool, default True) – Whether to check the Series and Index names attribute.

  • check_exact (bool, default False) – Whether to compare number exactly.

  • check_categorical (bool, default True) – Whether to compare internal Categorical exactly.

  • check_category_order (bool, default True) – Whether to compare category order of internal Categoricals.

  • rtol (float, default 1e-5) – Relative tolerance. Only used when check_exact is False.

  • atol (float, default 1e-8) – Absolute tolerance. Only used when check_exact is False.

  • obj (str, default 'Series') – Specify object name being compared, internally used to show appropriate assertion message.

  • check_index (bool, default True) – Whether to check index equivalence. If False, then compare only values.

  • check_like (bool, default False) – If True, ignore the order of the index. Must be False if check_index is False. Note: same labels must be with the same data.

Examples

>>> import arkouda as ak
>>> from arkouda import testing as tm
>>> a = ak.Series([1, 2, 3, 4])
>>> b = ak.Series([1, 2, 3, 4])
>>> tm.assert_series_equal(a, b)
arkouda.testing.assert_series_equivalent(left: arkouda.Series | pandas.Series, right: arkouda.Series | pandas.Series, check_dtype: bool = True, check_index_type: bool = True, check_series_type: bool = True, check_names: bool = True, check_exact: bool = False, check_categorical: bool = True, check_category_order: bool = True, rtol: float = 1e-05, atol: float = 1e-08, obj: str = 'Series', *, check_index: bool = True, check_like: bool = False) None[source]

Check that two Series are equal.

This function compares two Series and raises an assertion if they differ. pandas Series are converted to Arkouda equivalents before comparison. The comparison can be customized using the provided keyword arguments.

Parameters:
  • left (Series or pd.Series) – First Series to compare.

  • right (Series or pd.Series) – Second Series to compare.

  • check_dtype (bool) – Whether to check that dtypes are identical. Default is True.

  • check_index_type (bool) – Whether to check that index class, dtype, and inferred type are identical. Default is True.

  • check_series_type (bool) – Whether to check that the Series class is identical. Default is True.

  • check_names (bool) – Whether to check that the Series and Index name attributes are identical. Default is True.

  • check_exact (bool) – Whether to compare numbers exactly. Default is False.

  • check_categorical (bool) – Whether to compare internal Categoricals exactly. Default is True.

  • check_category_order (bool) – Whether to compare category order in internal Categoricals. Default is True.

  • rtol (float) – Relative tolerance used when check_exact is False. Default is 1e-5.

  • atol (float) – Absolute tolerance used when check_exact is False. Default is 1e-8.

  • obj (str) – Object name used in error messages. Default is “Series”.

  • check_index (bool) – Whether to check index equivalence. If False, only values are compared. Default is True.

  • check_like (bool) – If True, ignore the order of the index. Must be False if check_index is False. Note: identical labels must still correspond to the same data. Default is False.

Raises:

TypeError – If either input is not a Series or pd.Series.

Examples

>>> import arkouda as ak
>>> from arkouda import testing as tm
>>> import pandas as pd
>>> a = ak.Series([1, 2, 3, 4])
>>> b = pd.Series([1, 2, 3, 4])
>>> tm.assert_series_equivalent(a, b)