Skip to content

getml.project.DataFrames

DataFrames(data=None)

Container which holds all data frames associated with the running project that are currently stored in memory. The container supports slicing and is sort- and filterable.

Source code in getml/project/containers/data_frames.py
34
35
36
37
38
39
40
41
def __init__(self, data=None):
    self._in_memory = list_data_frames()["in_memory"]
    self._on_disk = list_data_frames()["on_disk"]

    if data is None:
        self.data = [load_data_frame(name) for name in self._in_memory]
    else:
        self.data = data

in_memory property

in_memory: List[str]

Returns the names of all data frames currently in memory.

RETURNS DESCRIPTION
List[str]

The names of all data frames currently in memory.

on_disk property

on_disk: List[str]

Returns the names of all data frames stored in the project folder.

delete

delete() -> None

Deletes all data frames in the current project.

Source code in getml/project/containers/data_frames.py
109
110
111
112
113
114
115
def delete(self) -> None:
    """
    Deletes all data frames in the current project.
    """

    for name in self.on_disk:
        DataFrame(name).delete()

filter

filter(conditional: Callable) -> DataFrames

Filters the data frames container.

PARAMETER DESCRIPTION
conditional

A callable that evaluates to a boolean for a given item.

TYPE: Callable

RETURNS DESCRIPTION
DataFrames

A container of filtered data frames.

Example
big_frames = getml.project.data_frames.filter(lambda frame: frame.memory_usage > 1000)
Source code in getml/project/containers/data_frames.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def filter(self, conditional: Callable) -> DataFrames:
    """
    Filters the data frames container.

    Args:
        conditional:
            A callable that evaluates to a boolean for a given item.

    Returns:
            A container of filtered data frames.

    ??? example
        ```python
        big_frames = getml.project.data_frames.filter(lambda frame: frame.memory_usage > 1000)
        ```
    """

    dfs_filtered = [df for df in self.data if conditional(df)]
    return DataFrames(data=dfs_filtered)

load

load() -> None

Loads all data frames stored in the project folder to memory.

Source code in getml/project/containers/data_frames.py
153
154
155
156
157
158
159
160
def load(self) -> None:
    """
    Loads all data frames stored in the project folder to memory.
    """

    for df in self.on_disk:
        if df not in self.in_memory:
            self.data.append(load_data_frame(df))

retrieve

retrieve()

Retrieve a dict of all data frames in memory.

Source code in getml/project/containers/data_frames.py
173
174
175
176
177
178
def retrieve(self):
    """
    Retrieve a dict of all data frames in memory.
    """

    return {df.name: df for df in self.data}

save

save() -> None

Saves all data frames currently in memory to disk.

Source code in getml/project/containers/data_frames.py
182
183
184
185
186
187
188
def save(self) -> None:
    """
    Saves all data frames currently in memory to disk.
    """

    for df in self.data:
        df.save()

sort

sort(key: Callable, descending: bool = False) -> DataFrames

Sorts the data frames container.

PARAMETER DESCRIPTION
key

A callable that evaluates to a sort key for a given item.

TYPE: Callable

descending

Whether to sort in descending order.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
DataFrames

A container of sorted data frames.

Example
by_num_rows = getml.project.data_frames.sort(lambda frame: frame.nrows())
Source code in getml/project/containers/data_frames.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def sort(self, key: Callable, descending: bool = False) -> DataFrames:
    """
    Sorts the data frames container.

    Args:
        key:
            A callable that evaluates to a sort key for a given item.

        descending:
            Whether to sort in descending order.

    Returns:
            A container of sorted data frames.

    ??? example
        ```python
        by_num_rows = getml.project.data_frames.sort(lambda frame: frame.nrows())
        ```
    """

    dfs_sorted = sorted(self.data, key=key, reverse=descending)
    return DataFrames(data=dfs_sorted)

unload

unload() -> None

Unloads all data frames in the current project from memory.

Source code in getml/project/containers/data_frames.py
217
218
219
220
221
222
223
def unload(self) -> None:
    """
    Unloads all data frames in the current project from memory.
    """

    for name in self.on_disk:
        DataFrame(name).unload()