From 200608403286bc3df6f7fdd1c97eaa3d3ef71f05 Mon Sep 17 00:00:00 2001 From: sfc-gh-mvashishtha Date: Tue, 30 Jul 2024 16:03:34 -0700 Subject: [PATCH] FIX-#7134: Use a separate docstring class for BasePandasDataset. Signed-off-by: sfc-gh-mvashishtha --- modin/tests/config/docs_module/__init__.py | 4 ++-- modin/tests/config/docs_module/classes.py | 8 ++++++++ modin/tests/config/test_envvars.py | 8 ++++++++ modin/utils.py | 13 ++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/modin/tests/config/docs_module/__init__.py b/modin/tests/config/docs_module/__init__.py index aa21549f1bd..5f617d683ba 100644 --- a/modin/tests/config/docs_module/__init__.py +++ b/modin/tests/config/docs_module/__init__.py @@ -11,7 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific language # governing permissions and limitations under the License. -from .classes import DataFrame, Series +from .classes import BasePandasDataset, DataFrame, Series from .functions import read_csv -__all__ = ["DataFrame", "Series", "read_csv"] +__all__ = ["BasePandasDataset", "DataFrame", "Series", "read_csv"] diff --git a/modin/tests/config/docs_module/classes.py b/modin/tests/config/docs_module/classes.py index 8dc152e23cd..235c99bdf0f 100644 --- a/modin/tests/config/docs_module/classes.py +++ b/modin/tests/config/docs_module/classes.py @@ -22,3 +22,11 @@ class Series: def isna(self): """This is a test of the documentation module for Series.""" return + + +class BasePandasDataset: + """This is a test of the documentation module for BasePandasDataSet.""" + + def apply(): + """This is a test of the documentation module for BasePandasDataSet.apply.""" + return diff --git a/modin/tests/config/test_envvars.py b/modin/tests/config/test_envvars.py index 384bd5f199a..d057ecb0299 100644 --- a/modin/tests/config/test_envvars.py +++ b/modin/tests/config/test_envvars.py @@ -20,6 +20,7 @@ import modin.pandas as pd from modin.config.envvars import _check_vars from modin.config.pubsub import _UNSET, ExactStr +from modin.pandas.base import BasePandasDataset def reset_vars(*vars: tuple[cfg.Parameter]): @@ -89,6 +90,12 @@ def test_overrides(self): cfg.DocModule.put("modin.tests.config.docs_module") # Test for override + assert BasePandasDataset.__doc__ == ( + "This is a test of the documentation module for BasePandasDataSet." + ) + assert BasePandasDataset.apply.__doc__ == ( + "This is a test of the documentation module for BasePandasDataSet.apply." + ) assert ( pd.DataFrame.apply.__doc__ == "This is a test of the documentation module for DataFrame." @@ -96,6 +103,7 @@ def test_overrides(self): # Test for pandas doc when method is not defined on the plugin module assert pandas.DataFrame.isna.__doc__ in pd.DataFrame.isna.__doc__ assert pandas.DataFrame.isnull.__doc__ in pd.DataFrame.isnull.__doc__ + assert BasePandasDataset.astype.__doc__ in pd.DataFrame.astype.__doc__ # Test for override assert ( pd.Series.isna.__doc__ diff --git a/modin/utils.py b/modin/utils.py index 34071be132b..8623732671b 100644 --- a/modin/utils.py +++ b/modin/utils.py @@ -462,7 +462,18 @@ def _inherit_docstrings_in_place( if doc_module != DocModule.default and "pandas" in str( getattr(parent, "__module__", "") ): - parent = getattr(imported_doc_module, getattr(parent, "__name__", ""), parent) + parent_name = ( + # DocModule should use the class BasePandasDataset to override the + # docstrings of BasePandasDataset, even if BasePandasDataset + # normally inherits docstrings from a different `parent`. + "BasePandasDataset" + if getattr(cls_or_func, "__name__", "") == "BasePandasDataset" + # For other classes, override docstrings with the class that has the + # same name as the `parent` class, e.g. DataFrame inherits + # docstrings from doc_module.DataFrame. + else getattr(parent, "__name__", "") + ) + parent = getattr(imported_doc_module, parent_name, parent) if parent != default_parent: # Reset API link in case the docs are overridden. apilink = None