arkouda.history

History retrieval utilities for Arkouda command execution.

This module provides tools for retrieving the history of commands executed in Python REPL shells or Jupyter/IPython notebooks. It defines abstract and concrete retrievers to access interactive command history for reproducibility, debugging, or audit purposes.

Classes

HistoryRetriever

Abstract base class defining the retrieve method and a helper for filtering commands.

ShellHistoryRetriever

Retrieves command history from a Python REPL shell using readline.

NotebookHistoryRetriever

Retrieves command history from a Jupyter notebook or IPython shell via IPython’s history database.

Usage

Used internally by arkouda.generate_history() to provide a user-friendly interface for querying and filtering past commands based on optional string filters and count limits.

Examples

>>> from arkouda.history import ShellHistoryRetriever, NotebookHistoryRetriever

# REPL mode >>> h = ShellHistoryRetriever() >>> h.retrieve(command_filter=”ak.”, num_commands=5) # doctest: +SKIP [‘ak.array([1,2,3])’, ‘ak.sum(…)’, …]

# Notebook mode >>> h = NotebookHistoryRetriever() >>> h.retrieve(num_commands=3) # doctest: +SKIP [‘ak.connect()’, ‘df = ak.DataFrame(…)’, ‘ak.argsort(…)’]

See also

arkouda.generate_history

High-level function for retrieving command history.

Classes

HistoryRetriever

Abstract base class that defines the retrieve method signature.

NotebookHistoryRetriever

Implement the retrieve method to get command history from a Jupyter notebook or IPython shell.

ShellHistoryRetriever

Implement the retrieve method to get command history from the Python REPL shell.

Module Contents

class arkouda.history.HistoryRetriever[source]

Abstract base class that defines the retrieve method signature.

Implements _filter_arkouda_command.

abstractmethod retrieve(command_filter: str | None = None, num_commands: int | None = None) List[str][source]

Generate list of commands executed.

Generate list of commands executed within a Python REPL shell, Jupyter notebook, or IPython notebook, with an optional command filter and number of commands to return.

Parameters:
  • num_commands (int) – The number of commands from history to retrieve

  • command_filter (str) – String containing characters used to select a subset of command history.

  • noqa (Returns #)

  • -------

  • List[str] – A list of commands from the Python shell, Jupyter notebook, or IPython notebook

class arkouda.history.NotebookHistoryRetriever(profile: str = 'default', hist_file: str = '', **traits: Any)[source]

Bases: IPython.core.history.HistoryAccessor, HistoryRetriever

Implement the retrieve method to get command history from a Jupyter notebook or IPython shell.

retrieve(command_filter: str | None = None, num_commands: int | None = None) List[str][source]

Generate list of commands executed.

Generate list of commands executed within a Jupyter notebook or IPython shell, with an optional command filter and number of commands to return.

Parameters:
  • num_commands (int) – The number of commands from history to retrieve

  • command_filter (str) – String containing characters used to select a subset of command history.

Returns:

A list of commands from the Python shell, Jupyter notebook, or IPython notebook

Return type:

List[str]

Examples

>>> import arkouda as ak
>>> from arkouda.history import NotebookHistoryRetriever
>>> h = NotebookHistoryRetriever()
>>> 1+2
>>> 4*6
>>> 2**3
>>> h.retrieve(num_commands=3)
['1+2', '4*6', '2**3']
class arkouda.history.ShellHistoryRetriever[source]

Bases: HistoryRetriever

Implement the retrieve method to get command history from the Python REPL shell.

retrieve(command_filter: str | None = None, num_commands: int | None = None) List[str][source]

Generate list of commands executed.

Generate list of commands executed within the a Python REPL shell, with an optional command filter and number of commands to return.

Parameters:
  • num_commands (int) – The number of commands from history to retrieve

  • command_filter (str) – String containing characters used to select a subset of command history.

Returns:

A list of commands from the Python shell, Jupyter notebook, or IPython notebook

Return type:

List[str]

Examples

>>> import arkouda as ak
>>> from arkouda.history import ShellHistoryRetriever
>>> import readline
>>> h = ShellHistoryRetriever()
>>> readline.clear_history()
>>> 1 + 2
3
>>> h.retrieve()
[' 1 + 2', 'h.retrieve()']