Skip to content

Commit

Permalink
FIX-#7263: Empty docstrings should not be inherited (#7264)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev committed May 16, 2024
1 parent ccc6188 commit 7e40812
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ def wait(self):
DaskWrapper.wait(self.list_of_blocks)


@_inherit_docstrings(PandasOnDaskDataframeVirtualPartition.__init__)
@_inherit_docstrings(PandasOnDaskDataframeVirtualPartition)
class PandasOnDaskDataframeColumnPartition(PandasOnDaskDataframeVirtualPartition):
axis = 0


@_inherit_docstrings(PandasOnDaskDataframeVirtualPartition.__init__)
@_inherit_docstrings(PandasOnDaskDataframeVirtualPartition)
class PandasOnDaskDataframeRowPartition(PandasOnDaskDataframeVirtualPartition):
axis = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class PandasOnPythonDataframeAxisPartition(PandasDataframeAxisPartition):
partition_type = PandasOnPythonDataframePartition


@_inherit_docstrings(PandasOnPythonDataframeAxisPartition.__init__)
@_inherit_docstrings(PandasOnPythonDataframeAxisPartition)
class PandasOnPythonDataframeColumnPartition(PandasOnPythonDataframeAxisPartition):
axis = 0


@_inherit_docstrings(PandasOnPythonDataframeAxisPartition.__init__)
@_inherit_docstrings(PandasOnPythonDataframeAxisPartition)
class PandasOnPythonDataframeRowPartition(PandasOnPythonDataframeAxisPartition):
axis = 1
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ def wait(self):
RayWrapper.wait(futures)


@_inherit_docstrings(PandasOnRayDataframeVirtualPartition.__init__)
@_inherit_docstrings(PandasOnRayDataframeVirtualPartition)
class PandasOnRayDataframeColumnPartition(PandasOnRayDataframeVirtualPartition):
axis = 0


@_inherit_docstrings(PandasOnRayDataframeVirtualPartition.__init__)
@_inherit_docstrings(PandasOnRayDataframeVirtualPartition)
class PandasOnRayDataframeRowPartition(PandasOnRayDataframeVirtualPartition):
axis = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ def wait(self):
UnidistWrapper.wait(futures)


@_inherit_docstrings(PandasOnUnidistDataframeVirtualPartition.__init__)
@_inherit_docstrings(PandasOnUnidistDataframeVirtualPartition)
class PandasOnUnidistDataframeColumnPartition(PandasOnUnidistDataframeVirtualPartition):
axis = 0


@_inherit_docstrings(PandasOnUnidistDataframeVirtualPartition.__init__)
@_inherit_docstrings(PandasOnUnidistDataframeVirtualPartition)
class PandasOnUnidistDataframeRowPartition(PandasOnUnidistDataframeVirtualPartition):
axis = 1

Expand Down
12 changes: 7 additions & 5 deletions modin/core/storage_formats/base/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ def merge_asof(
tolerance=None,
allow_exact_matches: bool = True,
direction: str = "backward",
):
): # noqa: GL08
# Pandas fallbacks for tricky cases:
if (
# No idea how this works or why it does what it does; and in fact
Expand Down Expand Up @@ -3621,7 +3621,9 @@ def groupby_fillna(
drop=drop,
)

def groupby_diff(self, by, axis, groupby_kwargs, agg_args, agg_kwargs, drop=False):
def groupby_diff(
self, by, axis, groupby_kwargs, agg_args, agg_kwargs, drop=False
): # noqa: GL08
return self.groupby_agg(
by=by,
agg_func="diff",
Expand All @@ -3634,7 +3636,7 @@ def groupby_diff(self, by, axis, groupby_kwargs, agg_args, agg_kwargs, drop=Fals

def groupby_pct_change(
self, by, axis, groupby_kwargs, agg_args, agg_kwargs, drop=False
):
): # noqa: GL08
return self.groupby_agg(
by=by,
agg_func="pct_change",
Expand Down Expand Up @@ -3942,7 +3944,7 @@ def groupby_ohlc(
agg_args,
agg_kwargs,
is_df,
):
): # noqa: GL08
if not is_df:
return self.groupby_agg(
by=by,
Expand Down Expand Up @@ -4606,7 +4608,7 @@ def shift(
freq,
axis,
fill_value,
):
): # noqa: GL08
return DataFrameDefault.register(pandas.DataFrame.shift)(
self, periods, freq, axis, fill_value
)
Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def __init__(self, name: str, accessor) -> None:
self._name = name
self._accessor = accessor

def __get__(self, obj, cls):
def __get__(self, obj, cls): # noqa: GL08
if obj is None:
return self._accessor
accessor_obj = self._accessor(obj)
Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ def between_time(
)
)

def _deprecate_downcast(self, downcast, method_name: str):
def _deprecate_downcast(self, downcast, method_name: str): # noqa: GL08
if downcast is not lib.no_default:
warnings.warn(
f"The 'downcast' keyword in {method_name} is deprecated and "
Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ def quantile(
_AXIS_ORDERS = ["index", "columns"]
_get_index_resolvers = pandas.DataFrame._get_index_resolvers

def _get_axis_resolvers(self, axis: str) -> dict:
def _get_axis_resolvers(self, axis: str) -> dict: # noqa: GL08
# forked from pandas because we only want to update the index if there's more
# than one level of the index.
# index or columns
Expand Down
12 changes: 6 additions & 6 deletions modin/pandas/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@


@_inherit_docstrings(pandas.core.groupby.DataFrameGroupBy)
class DataFrameGroupBy(ClassLogger):
class DataFrameGroupBy(ClassLogger): # noqa: GL08
_pandas_class = pandas.core.groupby.DataFrameGroupBy
_return_tuple_when_iterating = False
_df: Union[DataFrame, Series]
Expand Down Expand Up @@ -209,7 +209,7 @@ def default_handler(*args, **kwargs):
return attr

@property
def ngroups(self):
def ngroups(self): # noqa: GL08
return len(self)

def skew(self, axis=lib.no_default, skipna=True, numeric_only=False, **kwargs):
Expand Down Expand Up @@ -608,7 +608,7 @@ def filter(self, func, dropna=True, *args, **kwargs):
lambda df: df.filter(func, dropna=dropna, *args, **kwargs)
)

def _deprecate_axis(self, axis: int, name: str) -> None:
def _deprecate_axis(self, axis: int, name: str) -> None: # noqa: GL08
if axis == 1:
warnings.warn(
f"{type(self).__name__}.{name} with axis=1 is deprecated and "
Expand Down Expand Up @@ -1061,7 +1061,7 @@ def get_group(self, name, obj=None):
)
)

def __len__(self):
def __len__(self): # noqa: GL08
return len(self.indices)

def all(self, skipna=True):
Expand Down Expand Up @@ -1728,7 +1728,7 @@ def groupby_on_multiple_columns(df, *args, **kwargs):


@_inherit_docstrings(pandas.core.groupby.SeriesGroupBy)
class SeriesGroupBy(DataFrameGroupBy):
class SeriesGroupBy(DataFrameGroupBy): # noqa: GL08
_pandas_class = pandas.core.groupby.SeriesGroupBy

@property
Expand Down Expand Up @@ -1810,7 +1810,7 @@ def value_counts(
ascending: bool = False,
bins=None,
dropna: bool = True,
):
): # noqa: GL08
return self._default_to_pandas(
lambda ser: ser.value_counts(
normalize=normalize,
Expand Down
12 changes: 6 additions & 6 deletions modin/pandas/series_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def isnumeric(self):
def isdecimal(self):
return self._Series(query_compiler=self._query_compiler.str_isdecimal())

def __getitem__(self, key):
def __getitem__(self, key): # noqa: GL08
return self._Series(query_compiler=self._query_compiler.str___getitem__(key))

def _default_to_pandas(self, op, *args, **kwargs):
Expand All @@ -577,7 +577,7 @@ def _default_to_pandas(self, op, *args, **kwargs):


@_inherit_docstrings(pandas.core.indexes.accessors.CombinedDatetimelikeProperties)
class DatetimeProperties(ClassLogger):
class DatetimeProperties(ClassLogger): # noqa: GL08
_series: Series
_query_compiler: BaseQueryCompiler

Expand Down Expand Up @@ -700,15 +700,15 @@ def tz(self) -> "tzinfo | None":
return dtype.tz

@property
def freq(self):
def freq(self): # noqa: GL08
return self._query_compiler.dt_freq().to_pandas().squeeze()

@property
def unit(self):
def unit(self): # noqa: GL08
# use `iloc[0]` to return scalar
return self._Series(query_compiler=self._query_compiler.dt_unit()).iloc[0]

def as_unit(self, *args, **kwargs):
def as_unit(self, *args, **kwargs): # noqa: GL08
return self._Series(
query_compiler=self._query_compiler.dt_as_unit(*args, **kwargs)
)
Expand Down Expand Up @@ -810,7 +810,7 @@ def isocalendar(self):
return DataFrame(query_compiler=self._query_compiler.dt_isocalendar())

@property
def qyear(self):
def qyear(self): # noqa: GL08
return self._Series(query_compiler=self._query_compiler.dt_qyear())

@property
Expand Down
4 changes: 4 additions & 0 deletions modin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ def _replace_doc(
target_doc = target_obj.__doc__ or ""
overwrite = overwrite or not target_doc
doc = source_doc if overwrite else target_doc
if doc == "":
# Empty docstrings do not need to be inherited
return

if parent_cls and not attr_name:
if isinstance(target_obj, property):
Expand Down Expand Up @@ -434,6 +437,7 @@ def _documentable_obj(obj: object) -> bool:
"""Check if `obj` docstring could be patched."""
return bool(
callable(obj)
and not inspect.isclass(obj)
or (isinstance(obj, property) and obj.fget)
or (isinstance(obj, functools.cached_property))
or (isinstance(obj, (staticmethod, classmethod)) and obj.__func__)
Expand Down
4 changes: 3 additions & 1 deletion scripts/doc_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def check_optional_args(doc: Validator) -> list:
list
List of tuples with Modin error code and its description.
"""
if not doc.doc_parameters:
# `not doc.raw_doc and doc.clean_doc` - means that docstring was
# automatically generated by numpydoc with help of `pydoc.getdoc`.
if not doc.doc_parameters or (not doc.raw_doc and doc.clean_doc):
return []
optional_args = get_optional_args(doc)
if not optional_args:
Expand Down

0 comments on commit 7e40812

Please sign in to comment.