Skip to content

DataRailsContext

To use this class

from datarails.contexts import DataRailsContext

Bases: _BaseContext

DataRailsContext provides an interface to interact with its data.

Source code in datarails/contexts.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class DataRailsContext(_BaseContext):
    """DataRailsContext provides an interface to interact with its data."""

    def __str__(self) -> str:
        """Returns a string representation of the context."""
        return f"DataRailsContext({self.list_contents()})"

    def get(self, name: str) -> Union[Any, None]:
        """
        Gets a value from the context based on its name.

        Args:
            name (str): The name of the value to get.

        Returns:
            Union[Any, None]: The value associated with the name, or None if it doesn't exist.
        """
        return self._get(name)

    def put(self, name: str, value: Any) -> None:
        """
        Puts a value into the context with a specified name.

        Args:
            name (str): The name to associate with the value.
            value (Any): The value to put into the context.
        """
        self._put(name, value)

    def pop(self, name: str) -> DataFrame:
        """
        Pops a value from the context based on its name.

        Args:
            name (str): The name of the value to pop.

        Returns:
            DataFrame: The DataFrame associated with the name.
        """
        return self._pop(name)

    def delete(self, name: str) -> None:
        """
        Deletes a value from the context based on its name.

        Args:
            name (str): The name of the value to delete.
        """
        self._delete(name)

__str__()

Returns a string representation of the context.

Source code in datarails/contexts.py
32
33
34
def __str__(self) -> str:
    """Returns a string representation of the context."""
    return f"DataRailsContext({self.list_contents()})"

delete(name)

Deletes a value from the context based on its name.

Parameters:

Name Type Description Default
name str

The name of the value to delete.

required
Source code in datarails/contexts.py
70
71
72
73
74
75
76
77
def delete(self, name: str) -> None:
    """
    Deletes a value from the context based on its name.

    Args:
        name (str): The name of the value to delete.
    """
    self._delete(name)

get(name)

Gets a value from the context based on its name.

Parameters:

Name Type Description Default
name str

The name of the value to get.

required

Returns:

Type Description
Union[Any, None]

Union[Any, None]: The value associated with the name, or None if it doesn't exist.

Source code in datarails/contexts.py
36
37
38
39
40
41
42
43
44
45
46
def get(self, name: str) -> Union[Any, None]:
    """
    Gets a value from the context based on its name.

    Args:
        name (str): The name of the value to get.

    Returns:
        Union[Any, None]: The value associated with the name, or None if it doesn't exist.
    """
    return self._get(name)

pop(name)

Pops a value from the context based on its name.

Parameters:

Name Type Description Default
name str

The name of the value to pop.

required

Returns:

Name Type Description
DataFrame DataFrame

The DataFrame associated with the name.

Source code in datarails/contexts.py
58
59
60
61
62
63
64
65
66
67
68
def pop(self, name: str) -> DataFrame:
    """
    Pops a value from the context based on its name.

    Args:
        name (str): The name of the value to pop.

    Returns:
        DataFrame: The DataFrame associated with the name.
    """
    return self._pop(name)

put(name, value)

Puts a value into the context with a specified name.

Parameters:

Name Type Description Default
name str

The name to associate with the value.

required
value Any

The value to put into the context.

required
Source code in datarails/contexts.py
48
49
50
51
52
53
54
55
56
def put(self, name: str, value: Any) -> None:
    """
    Puts a value into the context with a specified name.

    Args:
        name (str): The name to associate with the value.
        value (Any): The value to put into the context.
    """
    self._put(name, value)