Skip to content

Commit

Permalink
deprecate load_data_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
KowerKoint committed Dec 20, 2024
1 parent b1f0463 commit d302976
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions docs/for_pandas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ This is useful when dataframe has nullable columns because pandas auto-conversio
Easy to Load DataFrame
----------------------

The :func:`~gokart.task.TaskOnKart.load_data_frame` method is used to load input ``pandas.DataFrame``.
The :func:`~gokart.task.TaskOnKart.load` method is used to load input ``pandas.DataFrame``.

.. code:: python
def requires(self):
return MakeDataFrameTask()
def run(self):
df = self.load_data_frame(required_columns={'colA', 'colB'}, drop_columns=True)
df = self.load()
This allows us to omit ``reset_index`` and ``drop`` when loading. If there is a missing column in an example above, ``AssertionError`` will be raised. This feature is useful for pipelines based on pandas.

Please refer to :func:`~gokart.task.TaskOnKart.load_data_frame`.
Please refer to :func:`~gokart.task.TaskOnKart.load`.


Fail on empty DataFrame
Expand Down
3 changes: 3 additions & 0 deletions docs/task_on_kart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ TaskOnKart.load_data_frame

Please refer to :doc:`for_pandas`.

.. warning::
This function is deprecated. Please use :func:`~gokart.task.TaskOnKart.load` instead.


TaskOnKart.fail_on_empty_dump
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions gokart/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from importlib import import_module
from logging import getLogger
from typing import Any, Callable, Dict, Generator, Generic, Iterable, List, Optional, Set, TypeVar, Union, overload
from typing_extensions import deprecated

import luigi
import pandas as pd
Expand Down Expand Up @@ -311,6 +312,9 @@ def _load(targets):

return _load(self._get_input_targets(target))

@deprecated("""This function is deprecated. use `load` instead.
If you want to specify `required_columns` and `drop_columns`, please extract the columns after loading. ex: `load()[['colA', 'colB']]`
""")
def load_data_frame(
self, target: Union[None, str, TargetOnKart] = None, required_columns: Optional[Set[str]] = None, drop_columns: bool = False
) -> pd.DataFrame:
Expand Down

0 comments on commit d302976

Please sign in to comment.