arkouda.accessor¶
Accessor utilities for Arkouda Series-like objects.
This module defines infrastructure for namespace-based accessors (e.g., .str, .dt) on Arkouda Series, mimicking the behavior of pandas-style accessors. It supports extension methods for string and datetime-like values, enabling operations to be performed in a clean, grouped syntax.
Exports¶
- __all__ = [
“CachedAccessor”, “DatetimeAccessor”, “Properties”, “StringAccessor”, “date_operators”, “string_operators”,
]
Components¶
- CachedAccessorclass
Descriptor that lazily initializes and caches accessor objects, such as .str or .dt.
- DatetimeAccessorclass
Implements datetime-like operations (e.g., floor, ceil, round) via the .dt accessor.
- StringAccessorclass
Implements string-like operations (e.g., contains, startswith, endswith) via the .str accessor.
- Propertiesbase class
Base class that provides _make_op for dynamically attaching operations to accessors.
- date_operatorsfunction
Class decorator that adds datetime operations to DatetimeAccessor.
- string_operatorsfunction
Class decorator that adds string operations to StringAccessor.
Usage¶
>>> import arkouda as ak
>>> from arkouda import Series
>>> s = Series(["apple", "banana", "apricot"])
>>> s.str.startswith("a")
0 True
1 False
2 True
dtype: bool
>>> from arkouda import Datetime
>>> t = Series(Datetime(ak.array([1_000_000_000_000])))
>>> t.dt.floor("D")
0 1970-01-01
dtype: datetime64[ns]
Notes
These accessors are automatically attached to compatible Series objects. Users should not instantiate accessors directly — use .str and .dt instead.
Classes¶
Custom property-like object. |
|
Accessor for datetime-like operations on Arkouda Series. |
|
Base class for accessor implementations in Arkouda. |
|
Accessor for string operations on Arkouda Series. |
Functions¶
|
Add common datetime operation methods to a DatetimeAccessor class. |
|
Add common string operation methods to a StringAccessor class. |
Module Contents¶
- class arkouda.accessor.CachedAccessor(name: str, accessor)[source]¶
Custom property-like object.
A descriptor for caching accessors.
- Parameters:
name (str) – Namespace that will be accessed under, e.g.
df.foo
.accessor (cls) – Class with the extension methods.
Notes
For accessor, The class’s __init__ method assumes that one of
Series
,DataFrame
orIndex
as the single argumentdata
.
- class arkouda.accessor.DatetimeAccessor(series)[source]¶
Bases:
Properties
Accessor for datetime-like operations on Arkouda Series.
Provides datetime methods such as .floor(), .ceil(), and .round(), mirroring the .dt accessor in pandas.
This accessor is automatically attached to Series objects that wrap arkouda.Datetime values. It should not be instantiated directly.
- Parameters:
series (arkouda.pandas.Series) – The Series object containing Datetime values.
- Raises:
AttributeError – If the underlying Series values are not of type arkouda.Datetime.
Examples
>>> import arkouda as ak >>> from arkouda import Datetime, Series >>> s = Series(Datetime(ak.array([1_000_000_000_000]))) >>> s.dt.floor("D") 0 1970-01-01 dtype: datetime64[ns]
- series¶
- class arkouda.accessor.Properties[source]¶
Base class for accessor implementations in Arkouda.
Provides the _make_op class method to dynamically generate accessor methods that wrap underlying Strings or Datetime operations and return new Series.
Notes
This class is subclassed by StringAccessor and DatetimeAccessor, and is not intended to be used directly.
Examples
Subclasses should define _make_op(“operation_name”), which will generate a method that applies series.values.operation_name(…) and returns a new Series.
- class arkouda.accessor.StringAccessor(series)[source]¶
Bases:
Properties
Accessor for string operations on Arkouda Series.
Provides string-like methods such as .contains(), .startswith(), and .endswith() via the .str accessor, similar to pandas.
This accessor is automatically attached to Series objects that wrap arkouda.Strings or arkouda.Categorical values. It should not be instantiated directly.
- Parameters:
series (arkouda.pandas.Series) – The Series object containing Strings or Categorical values.
- Raises:
AttributeError – If the underlying Series values are not Strings or Categorical.
Examples
>>> import arkouda as ak >>> from arkouda import Series >>> s = Series(["apple", "banana", "apricot"]) >>> s.str.startswith("a") 0 True 1 False 2 True dtype: bool
- series¶
- arkouda.accessor.date_operators(cls)[source]¶
Add common datetime operation methods to a DatetimeAccessor class.
This class decorator dynamically attaches datetime operations (floor, ceil, round) to the given class using the _make_op helper.
- Parameters:
cls (type) – The accessor class to decorate.
- Returns:
The accessor class with datetime methods added.
- Return type:
type
Notes
Used internally to implement the .dt accessor API.
- arkouda.accessor.string_operators(cls)[source]¶
Add common string operation methods to a StringAccessor class.
This class decorator dynamically attaches string operations (contains, startswith, endswith) to the given class using the _make_op helper.
- Parameters:
cls (type) – The accessor class to decorate.
- Returns:
The accessor class with string methods added.
- Return type:
type
Notes
Used internally to implement the .str accessor API.