Skip to content

DataBox

This is a description of the DataBox class. It is intended to be used as a container to store dataframes and allow them to be accessible by name to downstream ETL steps.

To use this class

from datarails.contexts import DataBox

Bases: _BaseContext

DataBox provides an interface to interact with its DataFrame data.

Source code in datarails/contexts.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
class DataBox(_BaseContext):
    """DataBox provides an interface to interact with its DataFrame data."""

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

    def get_df(self, name: str) -> DataFrame:
        """
        Gets a DataFrame from the DataBox based on its name.

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

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

    def put_df(self, name: str, df: DataFrame) -> None:
        """
        Puts a DataFrame into the DataBox with a specified name.

        Args:
            name (str): The name to associate with the DataFrame.
            df (DataFrame): The DataFrame to put into the DataBox.
        """
        self._put(name, df)

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

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

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

    def delete_df(self, name: str) -> None:
        """
        Deletes a DataFrame from the DataBox based on its name.

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

__str__()

Returns a string representation of the DataBox.

Source code in datarails/contexts.py
83
84
85
def __str__(self) -> str:
    """Returns a string representation of the DataBox."""
    return f"DataBox({self.list_contents()})"

delete_df(name)

Deletes a DataFrame from the DataBox based on its name.

Parameters:

Name Type Description Default
name str

The name of the DataFrame to delete.

required
Source code in datarails/contexts.py
121
122
123
124
125
126
127
128
def delete_df(self, name: str) -> None:
    """
    Deletes a DataFrame from the DataBox based on its name.

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

get_df(name)

Gets a DataFrame from the DataBox based on its name.

Parameters:

Name Type Description Default
name str

The name of the DataFrame to get.

required

Returns:

Name Type Description
DataFrame DataFrame

The DataFrame associated with the name.

Source code in datarails/contexts.py
87
88
89
90
91
92
93
94
95
96
97
def get_df(self, name: str) -> DataFrame:
    """
    Gets a DataFrame from the DataBox based on its name.

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

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

pop_df(name)

Pops a DataFrame from the DataBox based on its name.

Parameters:

Name Type Description Default
name str

The name of the DataFrame to pop.

required

Returns:

Name Type Description
DataFrame DataFrame

The DataFrame associated with the name.

Source code in datarails/contexts.py
109
110
111
112
113
114
115
116
117
118
119
def pop_df(self, name: str) -> DataFrame:
    """
    Pops a DataFrame from the DataBox based on its name.

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

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

put_df(name, df)

Puts a DataFrame into the DataBox with a specified name.

Parameters:

Name Type Description Default
name str

The name to associate with the DataFrame.

required
df DataFrame

The DataFrame to put into the DataBox.

required
Source code in datarails/contexts.py
 99
100
101
102
103
104
105
106
107
def put_df(self, name: str, df: DataFrame) -> None:
    """
    Puts a DataFrame into the DataBox with a specified name.

    Args:
        name (str): The name to associate with the DataFrame.
        df (DataFrame): The DataFrame to put into the DataBox.
    """
    self._put(name, df)