Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR-#7017: Align to_hdf and hist signatures to pandas #7018

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 32 additions & 4 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pickle as pkl
import re
import warnings
from typing import Any, Hashable, Optional, Sequence, Union
from typing import Any, Hashable, Literal, Optional, Sequence, Union

import numpy as np
import pandas
Expand Down Expand Up @@ -3239,13 +3239,41 @@ def to_dict(self, orient="dict", into=dict, index=True):

@expanduser_path_arg("path_or_buf")
def to_hdf(
self, path_or_buf, key, format="table", **kwargs
): # pragma: no cover # noqa: PR01, RT01, D200
self,
path_or_buf,
key: str,
mode: Literal["a", "w", "r+"] = "a",
complevel: int | None = None,
complib: Literal["zlib", "lzo", "bzip2", "blosc"] | None = None,
append: bool = False,
format: Literal["fixed", "table"] | None = None,
index: bool = True,
min_itemsize: int | dict[str, int] | None = None,
nan_rep=None,
dropna: bool | None = None,
data_columns: Literal[True] | list[str] | None = None,
errors: str = "strict",
encoding: str = "UTF-8",
) -> None: # pragma: no cover # noqa: PR01, RT01, D200
"""
Write the contained data to an HDF5 file using HDFStore.
"""
return self._default_to_pandas(
"to_hdf", path_or_buf, key, format=format, **kwargs
"to_hdf",
path_or_buf,
key=key,
mode=mode,
complevel=complevel,
complib=complib,
append=append,
format=format,
index=index,
min_itemsize=min_itemsize,
nan_rep=nan_rep,
dropna=dropna,
data_columns=data_columns,
errors=errors,
encoding=encoding,
)

@expanduser_path_arg("path_or_buf")
Expand Down
42 changes: 26 additions & 16 deletions modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
import numpy as np
import pandas
from pandas._libs import lib
from pandas._typing import CompressionOptions, FilePath, StorageOptions, WriteBuffer
from pandas._typing import (
CompressionOptions,
FilePath,
IndexLabel,
StorageOptions,
WriteBuffer,
)
from pandas.core.common import apply_if_callable, get_cython_func
from pandas.core.computation.eval import _check_engine
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -966,26 +972,28 @@ def gt(self, other, axis="columns", level=None): # noqa: PR01, RT01, D200
)

def hist(
self,
column=None,
data,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unusual, but otherwise the test with pandas will fail.

column: IndexLabel | None = None,
by=None,
grid=True,
xlabelsize=None,
xrot=None,
ylabelsize=None,
yrot=None,
grid: bool = True,
xlabelsize: int | None = None,
xrot: float | None = None,
ylabelsize: int | None = None,
yrot: float | None = None,
ax=None,
sharex=False,
sharey=False,
figsize=None,
layout=None,
bins=10,
**kwds,
sharex: bool = False,
sharey: bool = False,
figsize: tuple[int, int] | None = None,
layout: tuple[int, int] | None = None,
bins: int | Sequence[int] = 10,
backend: str | None = None,
legend: bool = False,
**kwargs,
): # pragma: no cover # noqa: PR01, RT01, D200
"""
Make a histogram of the ``DataFrame``.
"""
return self._default_to_pandas(
return data._default_to_pandas(
pandas.DataFrame.hist,
column=column,
by=by,
Expand All @@ -1000,7 +1008,9 @@ def hist(
figsize=figsize,
layout=layout,
bins=bins,
**kwds,
backend=backend,
legend=legend,
**kwargs,
)

def info(
Expand Down
24 changes: 14 additions & 10 deletions modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np
import pandas
from pandas._libs import lib
from pandas._typing import Axis, IndexKeyFunc
from pandas._typing import Axis, IndexKeyFunc, Sequence
from pandas.api.types import is_integer
from pandas.core.common import apply_if_callable, is_bool_indexer
from pandas.core.dtypes.common import is_dict_like, is_list_like
Expand Down Expand Up @@ -1123,14 +1123,16 @@ def hist(
self,
by=None,
ax=None,
grid=True,
xlabelsize=None,
xrot=None,
ylabelsize=None,
yrot=None,
figsize=None,
bins=10,
**kwds,
grid: bool = True,
xlabelsize: int | None = None,
xrot: float | None = None,
ylabelsize: int | None = None,
yrot: float | None = None,
figsize: tuple[int, int] | None = None,
bins: int | Sequence[int] = 10,
backend: str | None = None,
legend: bool = False,
**kwargs,
): # noqa: PR01, RT01, D200
"""
Draw histogram of the input series using matplotlib.
Expand All @@ -1146,7 +1148,9 @@ def hist(
yrot=yrot,
figsize=figsize,
bins=bins,
**kwds,
backend=backend,
legend=legend,
**kwargs,
)

def idxmax(self, axis=0, skipna=True, *args, **kwargs): # noqa: PR01, RT01, D200
Expand Down
4 changes: 2 additions & 2 deletions modin/pandas/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_dataframe_api_equality():
), "Differences found in API: {}".format(set(modin_dir) - set(pandas_dir))

# These have to be checked manually
allowed_different = ["to_hdf", "hist", "modin"]
allowed_different = ["modin"]

assert_parameters_eq((pandas.DataFrame, pd.DataFrame), modin_dir, allowed_different)

Expand Down Expand Up @@ -275,7 +275,7 @@ def test_series_api_equality():
)

# These have to be checked manually
allowed_different = ["to_hdf", "hist", "modin"]
allowed_different = ["modin"]

assert_parameters_eq((pandas.Series, pd.Series), modin_dir, allowed_different)

Expand Down