arkouda.util

Module Contents

Functions

attach(name)

attach_all(names)

Attach to all objects registered with the names provide

broadcast_dims(→ Tuple[int, Ellipsis])

Algorithm to determine shape of broadcasted PD array given two array shapes

concatenate(items[, ordered])

convert_bytes(nbytes[, unit])

Convert the number of bytes to KB, MB, or GB.

convert_if_categorical(values)

Convert a Categorical array to Strings for display

enrich_inplace(data, keynames, aggregations, **kwargs)

expand(size, segs, vals)

Expand an array with values placed into the indicated segments.

generic_concat(items[, ordered])

get_callback(x)

identity(x)

invert_permutation(perm)

Find the inverse of a permutation array.

is_float(arry)

Check if the dtype of the given array is float.

is_int(arry)

Check if the dtype of the given array is int.

is_numeric(→ bool)

Check if the dtype of the given array is numeric.

is_registered(→ bool)

Determine if the name provided is associated with a registered Object

map(→ Union[arkouda.pdarrayclass.pdarray, ...)

Map values of an array according to an input mapping.

most_common(g, values)

register(obj, name)

Register an arkouda object with a user-specified name. Backwards compatible

register_all(data)

Register all objects in the provided dictionary

report_mem([pre])

sparse_sum_help(idx1, idx2, val1, val2[, merge, ...])

Helper for summing two sparse matrices together

unregister(→ str)

unregister_all(names)

Unregister all names provided

arkouda.util.attach(name: str)[source]
arkouda.util.attach_all(names: list)[source]

Attach to all objects registered with the names provide

Parameters:

names (list) – List of names to attach to

Return type:

dict

arkouda.util.broadcast_dims(sa: Sequence[int], sb: Sequence[int]) Tuple[int, Ellipsis][source]

Algorithm to determine shape of broadcasted PD array given two array shapes

see: https://data-apis.org/array-api/latest/API_specification/broadcasting.html#algorithm

arkouda.util.concatenate(items, ordered=True)[source]
arkouda.util.convert_bytes(nbytes, unit='B')[source]

Convert the number of bytes to KB, MB, or GB.

Parameters:

unit (str, default = "B") – Unit to return. One of {‘B’, ‘KB’, ‘MB’, ‘GB’}.

Return type:

int

arkouda.util.convert_if_categorical(values)[source]

Convert a Categorical array to Strings for display

arkouda.util.enrich_inplace(data, keynames, aggregations, **kwargs)[source]
arkouda.util.expand(size, segs, vals)[source]

Expand an array with values placed into the indicated segments.

Parameters:
  • size (ak.pdarray) – The size of the array to be expanded

  • segs (ak.pdarray) – The indices where the values should be placed

  • vals (ak.pdarray) – The values to be placed in each segment

Returns:

The expanded array.

Return type:

pdarray

Notes

This function (with different order of arguments) is now in arkouda proper as ak.broadcast. It is retained here for backwards compatibility.

arkouda.util.generic_concat(items, ordered=True)[source]
arkouda.util.get_callback(x)[source]
arkouda.util.identity(x)[source]
arkouda.util.invert_permutation(perm)[source]

Find the inverse of a permutation array.

Parameters:

perm (ak.pdarray) – The permutation array.

Returns:

The inverse of the permutation array.

Return type:

ak.array

arkouda.util.is_float(arry: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical)[source]

Check if the dtype of the given array is float.

Parameters:

arry ((pdarray, Strings, Categorical)) – The input pdarray, Strings, or Categorical object.

Returns:

  • bool – True if the dtype of pda is of type float, False otherwise.

  • Example – >>> import arkouda as ak >>> ak.connect() >>> data = ak.array([1.0, 2, 3, 4, np.nan]) >>> is_float(data) True

    >>> data2 = ak.arange(5)
    >>> is_float(data2)
    False
    

arkouda.util.is_int(arry: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical)[source]

Check if the dtype of the given array is int.

Parameters:
  • ((pdarray (arry) – The input pdarray, Strings, or Categorical object.

  • Strings – The input pdarray, Strings, or Categorical object.

  • Categorical)) – The input pdarray, Strings, or Categorical object.

Returns:

  • bool – True if the dtype of pda is of type int, False otherwise.

  • Example

  • >>> import arkouda as ak

  • >>> ak.connect()

  • >>> data = ak.array([1.0, 2, 3, 4, np.nan])

  • >>> is_int(data)

  • False

  • >>> data2 = ak.arange(5)

  • >>> is_int(data2)

  • True

arkouda.util.is_numeric(arry: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical) bool[source]

Check if the dtype of the given array is numeric.

Parameters:

arry ((pdarray, Strings, Categorical)) – The input pdarray, Strings, or Categorical object.

Returns:

  • bool – True if the dtype of pda is numeric, False otherwise.

  • Example – >>> import arkouda as ak >>> ak.connect() >>> data = ak.array([1, 2, 3, 4, 5]) >>> is_numeric(data) True

    >>> strings = ak.array(["a", "b", "c"])
    >>> is_numeric(strings)
    False
    

arkouda.util.is_registered(name: str, as_component: bool = False) bool[source]

Determine if the name provided is associated with a registered Object

Parameters:
  • name (str) – The name to check for in the registry

  • as_component (bool) – Default: False When True, the name will be checked to determine if it is registered as a component of a registered object

Return type:

bool

arkouda.util.map(values: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical, mapping: dict | arkouda.Series) arkouda.pdarrayclass.pdarray | arkouda.strings.Strings[source]

Map values of an array according to an input mapping.

Parameters:
Returns:

A new array with the values mapped by the mapping correspondence. When the input Series has Categorical values, the return Series will have Strings values. Otherwise, the return type will match the input type.

Return type:

arkouda.pdarrayclass.pdarray or arkouda.strings.Strings

Raises:

TypeError – Raised if arg is not of type dict or arkouda.Series. Raised if values not of type pdarray, Categorical, or Strings.

Examples

>>> import arkouda as ak
>>> ak.connect()
>>> from arkouda.util import map
>>> a = ak.array([2, 3, 2, 3, 4])
>>> a
array([2 3 2 3 4])
>>> map(a, {4: 25.0, 2: 30.0, 1: 7.0, 3: 5.0})
array([30.00000000000000000 5.00000000000000000 30.00000000000000000
5.00000000000000000 25.00000000000000000])
>>> s = ak.Series(ak.array(["a","b","c","d"]), index = ak.array([4,2,1,3]))
>>> map(a, s)
array(['b', 'b', 'd', 'd', 'a'])
arkouda.util.most_common(g, values)[source]
arkouda.util.register(obj, name)[source]

Register an arkouda object with a user-specified name. Backwards compatible with earlier arkouda versions.

arkouda.util.register_all(data: dict)[source]

Register all objects in the provided dictionary

Parameters:

data (dict) – Maps name to register the object to the object. For example, {“MyArray”: ak.array([0, 1, 2])

Return type:

None

arkouda.util.report_mem(pre='')[source]
arkouda.util.sparse_sum_help(idx1, idx2, val1, val2, merge=True, percent_transfer_limit=100)[source]

Helper for summing two sparse matrices together

Return is equivalent to ak.GroupBy(ak.concatenate([idx1, idx2])).sum(ak.concatenate((val1, val2)))

Parameters:
  • idx1 (pdarray) – indices for the first sparse matrix

  • idx2 (pdarray) – indices for the second sparse matrix

  • val1 (pdarray) – values for the first sparse matrix

  • val2 (pdarray) – values for the second sparse matrix

  • merge (bool) – If true the indices are combined using a merge based workflow, otherwise they are combine using a sort based workflow.

  • percent_transfer_limit (int) – Only used when merge is true. This is the maximum percentage of the data allowed to be moved between locales during the merge workflow. If we would exceed this percentage, we fall back to using the sort based workflow.

Returns:

indices and values for the summed sparse matrix

Return type:

(pdarray, pdarray)

Examples

>>> idx1 = ak.array([0, 1, 3, 4, 7, 9])
>>> idx2 = ak.array([0, 1, 3, 6, 9])
>>> vals1 = idx1
>>> vals2 = ak.array([10, 11, 13, 16, 19])
>>> ak.util.sparse_sum_help(idx1, inds2, vals1, vals2)
(array([0 1 3 4 6 7 9]), array([10 12 16 4 16 7 28]))
>>> ak.GroupBy(ak.concatenate([idx1, idx2])).sum(ak.concatenate((vals1, vals2)))
(array([0 1 3 4 6 7 9]), array([10 12 16 4 16 7 28]))
arkouda.util.unregister(name: str) str[source]
arkouda.util.unregister_all(names: list)[source]

Unregister all names provided

Parameters:

names (list) – List of names used to register objects to be unregistered

Return type:

None