From 156b89fdbee0733c34eb9a6c5478a2c12a49b4f4 Mon Sep 17 00:00:00 2001 From: Deepak George Date: Sat, 16 Sep 2023 13:46:06 +0000 Subject: [PATCH 1/8] fix pandas.DataFrame.agg.html documents --- pandas/core/frame.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8fcb91c846826..124c21839afe7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9829,11 +9829,11 @@ def _gotitem( -------- DataFrame.apply : Perform any type of operations. DataFrame.transform : Perform transformation type operations. - pandas.core.groupby.GroupBy : Perform operations over groups. - pandas.core.resample.Resampler : Perform operations over resampled bins. - pandas.core.window.Rolling : Perform operations over rolling window. - pandas.core.window.Expanding : Perform operations over expanding window. - pandas.core.window.ExponentialMovingWindow : Perform operation over exponential + pandas.DataFrame.groupby : Perform operations over groups. + pandas.DataFrame.resample : Perform operations over resampled bins. + pandas.DataFrame.rolling : Perform operations over rolling window. + pandas.DataFrame.expanding : Perform operations over expanding window. + pandas.core.window.ewm.ExponentialMovingWindow : Perform operation over exponential weighted window. """ ) From 828b9c4ea1621d90aa4214c63299ea32f8349707 Mon Sep 17 00:00:00 2001 From: Deepak George Date: Sat, 16 Sep 2023 17:31:53 +0200 Subject: [PATCH 2/8] add set __module__ for pd.DataFrame --- pandas/core/frame.py | 2 ++ pandas/tests/api/test_api.py | 4 ++++ pandas/util/_decorators.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 124c21839afe7..7735edcb8823a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -66,6 +66,7 @@ Substitution, deprecate_nonkeyword_arguments, doc, + set_module, ) from pandas.util._exceptions import find_stack_level from pandas.util._validators import ( @@ -489,6 +490,7 @@ # DataFrame class +@set_module("pandas") class DataFrame(NDFrame, OpsMixin): """ Two-dimensional, size-mutable, potentially heterogeneous tabular data. diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 60bcb97aaa364..f22fe438ae52a 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -381,3 +381,7 @@ def test_pandas_array_alias(): res = pd.arrays.PandasArray assert res is pd.arrays.NumpyExtensionArray + + +def test_set_module(): + assert pd.DataFrame.__module__ == "pandas" \ No newline at end of file diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 4c2122c3fdff1..480cb7f603f77 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -506,3 +506,23 @@ def indent(text: str | None, indents: int = 1) -> str: "future_version_msg", "Substitution", ] + + +def set_module(module): + """Private decorator for overriding __module__ on a function or class. + + Example usage:: + + @set_module('pandas') + def example(): + pass + + assert example.__module__ == 'pandas' + """ + + def decorator(func): + if module is not None: + func.__module__ = module + return func + + return decorator From 69689dedb0e515d1b11c3f337cfd5298af257a1d Mon Sep 17 00:00:00 2001 From: Deepak George Date: Sat, 16 Sep 2023 17:50:05 +0200 Subject: [PATCH 3/8] revert the documentaion change made --- pandas/core/frame.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7735edcb8823a..712c872c6bbdf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9829,15 +9829,11 @@ def _gotitem( """ See Also -------- - DataFrame.apply : Perform any type of operations. - DataFrame.transform : Perform transformation type operations. - pandas.DataFrame.groupby : Perform operations over groups. - pandas.DataFrame.resample : Perform operations over resampled bins. - pandas.DataFrame.rolling : Perform operations over rolling window. - pandas.DataFrame.expanding : Perform operations over expanding window. - pandas.core.window.ewm.ExponentialMovingWindow : Perform operation over exponential - weighted window. - """ + pandas.core.groupby.GroupBy : Perform operations over groups. + pandas.core.resample.Resampler : Perform operations over resampled bins. + pandas.core.window.Rolling : Perform operations over rolling window. + pandas.core.window.Expanding : Perform operations over expanding window. + pandas.core.window.ExponentialMovingWindow : Perform operation over exponential""" ) _agg_examples_doc = dedent( From 43b6429992519bcb8cf3f9d0e08a23165990f7fd Mon Sep 17 00:00:00 2001 From: Deepak George Date: Sat, 16 Sep 2023 17:52:24 +0200 Subject: [PATCH 4/8] fix documentation change --- pandas/core/frame.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 712c872c6bbdf..43233a9727d16 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9829,6 +9829,8 @@ def _gotitem( """ See Also -------- + DataFrame.apply : Perform any type of operations. + DataFrame.transform : Perform transformation type operations. pandas.core.groupby.GroupBy : Perform operations over groups. pandas.core.resample.Resampler : Perform operations over resampled bins. pandas.core.window.Rolling : Perform operations over rolling window. From 77036a50529c14b28410736e736927c9569b847b Mon Sep 17 00:00:00 2001 From: Deepak George Date: Sat, 16 Sep 2023 17:53:44 +0200 Subject: [PATCH 5/8] remove doc change --- pandas/core/frame.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 43233a9727d16..c2a629e44a9b1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9835,7 +9835,9 @@ def _gotitem( pandas.core.resample.Resampler : Perform operations over resampled bins. pandas.core.window.Rolling : Perform operations over rolling window. pandas.core.window.Expanding : Perform operations over expanding window. - pandas.core.window.ExponentialMovingWindow : Perform operation over exponential""" + pandas.core.window.ExponentialMovingWindow : Perform operation over exponential + weighted window. + """ ) _agg_examples_doc = dedent( From a4ace579e5665fae6619585a8c0059a33c013fb1 Mon Sep 17 00:00:00 2001 From: deepak Date: Mon, 18 Sep 2023 15:52:32 +0200 Subject: [PATCH 6/8] pandas.core.frame.DataFrame -> pandas.DataFrame --- doc/source/development/contributing_docstring.rst | 2 +- doc/source/user_guide/enhancingperf.rst | 2 +- doc/source/user_guide/io.rst | 8 ++++---- doc/source/whatsnew/v0.24.0.rst | 2 +- doc/source/whatsnew/v0.25.0.rst | 4 ++-- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/conftest.py | 2 +- pandas/core/indexing.py | 2 +- pandas/io/formats/format.py | 2 +- pandas/io/formats/info.py | 8 ++++---- pandas/tests/groupby/test_grouping.py | 2 +- pandas/tests/io/formats/test_info.py | 6 +++--- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/doc/source/development/contributing_docstring.rst b/doc/source/development/contributing_docstring.rst index 87aecb6936c9c..eecde136a037c 100644 --- a/doc/source/development/contributing_docstring.rst +++ b/doc/source/development/contributing_docstring.rst @@ -940,7 +940,7 @@ Finally, docstrings can also be appended to with the ``doc`` decorator. In this example, we'll create a parent docstring normally (this is like ``pandas.core.generic.NDFrame``. Then we'll have two children (like -``pandas.core.series.Series`` and ``pandas.core.frame.DataFrame``). We'll +``pandas.core.series.Series`` and ``pandas.DataFrame``). We'll substitute the class names in this docstring. .. code-block:: python diff --git a/doc/source/user_guide/enhancingperf.rst b/doc/source/user_guide/enhancingperf.rst index bc2f4420da784..9ac3bc7255299 100644 --- a/doc/source/user_guide/enhancingperf.rst +++ b/doc/source/user_guide/enhancingperf.rst @@ -453,7 +453,7 @@ by evaluate arithmetic and boolean expression all at once for large :class:`~pan :func:`~pandas.eval` is many orders of magnitude slower for smaller expressions or objects than plain Python. A good rule of thumb is to only use :func:`~pandas.eval` when you have a - :class:`~pandas.core.frame.DataFrame` with more than 10,000 rows. + :class:`~pandas.DataFrame` with more than 10,000 rows. Supported syntax ~~~~~~~~~~~~~~~~ diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 6bd181740c78d..e0da92ba6a1f7 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2701,7 +2701,7 @@ in the method ``to_string`` described above. .. note:: Not all of the possible options for ``DataFrame.to_html`` are shown here for - brevity's sake. See :func:`~pandas.core.frame.DataFrame.to_html` for the + brevity's sake. See :func:`~pandas.DataFrame.to_html` for the full set of options. .. note:: @@ -6020,7 +6020,7 @@ Stata format Writing to stata format ''''''''''''''''''''''' -The method :func:`~pandas.core.frame.DataFrame.to_stata` will write a DataFrame +The method :func:`~pandas.DataFrame.to_stata` will write a DataFrame into a .dta file. The format version of this file is always 115 (Stata 12). .. ipython:: python @@ -6060,7 +6060,7 @@ outside of this range, the variable is cast to ``int16``. .. warning:: :class:`~pandas.io.stata.StataWriter` and - :func:`~pandas.core.frame.DataFrame.to_stata` only support fixed width + :func:`~pandas.DataFrame.to_stata` only support fixed width strings containing up to 244 characters, a limitation imposed by the version 115 dta file format. Attempting to write *Stata* dta files with strings longer than 244 characters raises a ``ValueError``. @@ -6299,7 +6299,7 @@ ignored. In [2]: df = pd.DataFrame({'A': np.random.randn(sz), 'B': [1] * sz}) In [3]: df.info() - + RangeIndex: 1000000 entries, 0 to 999999 Data columns (total 2 columns): A 1000000 non-null float64 diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index b013d03b2d68c..244b526628465 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -840,7 +840,7 @@ then all the columns are dummy-encoded, and a :class:`SparseDataFrame` was retur In [2]: df = pd.DataFrame({"A": [1, 2], "B": ['a', 'b'], "C": ['a', 'a']}) In [3]: type(pd.get_dummies(df, sparse=True)) - Out[3]: pandas.core.frame.DataFrame + Out[3]: pandas.DataFrame In [4]: type(pd.get_dummies(df[['B', 'C']], sparse=True)) Out[4]: pandas.core.sparse.frame.SparseDataFrame diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index c0f169aa6251f..597a399914459 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -1117,7 +1117,7 @@ Indexing - Bug in :meth:`DataFrame.loc` and :meth:`Series.loc` where ``KeyError`` was not raised for a ``MultiIndex`` when the key was less than or equal to the number of levels in the :class:`MultiIndex` (:issue:`14885`). - Bug in which :meth:`DataFrame.append` produced an erroneous warning indicating that a ``KeyError`` will be thrown in the future when the data to be appended contains new columns (:issue:`22252`). - Bug in which :meth:`DataFrame.to_csv` caused a segfault for a reindexed data frame, when the indices were single-level :class:`MultiIndex` (:issue:`26303`). -- Fixed bug where assigning a :class:`arrays.PandasArray` to a :class:`pandas.core.frame.DataFrame` would raise error (:issue:`26390`) +- Fixed bug where assigning a :class:`arrays.PandasArray` to a :class:`pandas.DataFrame` would raise error (:issue:`26390`) - Allow keyword arguments for callable local reference used in the :meth:`DataFrame.query` string (:issue:`26426`) - Fixed a ``KeyError`` when indexing a :class:`MultiIndex` level with a list containing exactly one label, which is missing (:issue:`27148`) - Bug which produced ``AttributeError`` on partial matching :class:`Timestamp` in a :class:`MultiIndex` (:issue:`26944`) @@ -1205,7 +1205,7 @@ GroupBy/resample/rolling - Bug in :meth:`pandas.core.groupby.GroupBy.cumsum`, :meth:`pandas.core.groupby.GroupBy.cumprod`, :meth:`pandas.core.groupby.GroupBy.cummin` and :meth:`pandas.core.groupby.GroupBy.cummax` with categorical column having absent categories, would return incorrect result or segfault (:issue:`16771`) - Bug in :meth:`pandas.core.groupby.GroupBy.nth` where NA values in the grouping would return incorrect results (:issue:`26011`) - Bug in :meth:`pandas.core.groupby.SeriesGroupBy.transform` where transforming an empty group would raise a ``ValueError`` (:issue:`26208`) -- Bug in :meth:`pandas.core.frame.DataFrame.groupby` where passing a :class:`pandas.core.groupby.grouper.Grouper` would return incorrect groups when using the ``.groups`` accessor (:issue:`26326`) +- Bug in :meth:`pandas.DataFrame.groupby` where passing a :class:`pandas.core.groupby.grouper.Grouper` would return incorrect groups when using the ``.groups`` accessor (:issue:`26326`) - Bug in :meth:`pandas.core.groupby.GroupBy.agg` where incorrect results are returned for uint64 columns. (:issue:`26310`) - Bug in :meth:`pandas.core.window.Rolling.median` and :meth:`pandas.core.window.Rolling.quantile` where MemoryError is raised with empty window (:issue:`26005`) - Bug in :meth:`pandas.core.window.Rolling.median` and :meth:`pandas.core.window.Rolling.quantile` where incorrect results are returned with ``closed='left'`` and ``closed='neither'`` (:issue:`26005`) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 5e4559303a8b7..97131343116ed 100755 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -414,7 +414,7 @@ Extended verbose info output for :class:`~pandas.DataFrame` ... "text_col": ["a", "b", "c"], ... "float_col": [0.0, 0.1, 0.2]}) In [2]: df.info(verbose=True) - + RangeIndex: 3 entries, 0 to 2 Data columns (total 3 columns): int_col 3 non-null int64 diff --git a/pandas/conftest.py b/pandas/conftest.py index ac0275bf695d4..71e37cc0808b5 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -117,7 +117,7 @@ def ignore_doctest_warning(item: pytest.Item, path: str, message: str) -> None: item : pytest.Item pytest test item. path : str - Module path to Python object, e.g. "pandas.core.frame.DataFrame.append". A + Module path to Python object, e.g. "pandas.DataFrame.append". A warning will be filtered when item.name ends with in given path. So it is sufficient to specify e.g. "DataFrame.append". message : str diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 871e5817fdf0d..0fd65db0bef6b 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -214,7 +214,7 @@ def iloc(self) -> _iLocIndexer: a b c d 0 1 2 3 4 >>> type(df.iloc[[0]]) - + >>> df.iloc[[0, 1]] a b c d diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 2297f7945a264..487664d8ae4bb 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1010,7 +1010,7 @@ class DataFrameRenderer: - to_csv - to_latex - Called in pandas.core.frame.DataFrame: + Called in pandas.DataFrame: - to_html - to_string diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index d20c2a62c61e2..0a1b3e77b940b 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -72,7 +72,7 @@ Prints information of all columns: >>> df.info(verbose=True) - + RangeIndex: 5 entries, 0 to 4 Data columns (total 3 columns): # Column Non-Null Count Dtype @@ -87,7 +87,7 @@ information: >>> df.info(verbose=False) - + RangeIndex: 5 entries, 0 to 4 Columns: 3 entries, int_col to float_col dtypes: float64(1), int64(1), object(1) @@ -115,7 +115,7 @@ ... 'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6) ... }) >>> df.info() - + RangeIndex: 1000000 entries, 0 to 999999 Data columns (total 3 columns): # Column Non-Null Count Dtype @@ -127,7 +127,7 @@ memory usage: 22.9+ MB >>> df.info(memory_usage='deep') - + RangeIndex: 1000000 entries, 0 to 999999 Data columns (total 3 columns): # Column Non-Null Count Dtype diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index d05b60fd56b5f..1ed567f964f8c 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -480,7 +480,7 @@ def test_groupby_with_datetime_key(self): assert len(gb.groups.keys()) == 4 def test_grouping_error_on_multidim_input(self, df): - msg = "Grouper for '' not 1-dimensional" + msg = "Grouper for '' not 1-dimensional" with pytest.raises(ValueError, match=msg): Grouping(df.index, df[["A", "A"]]) diff --git a/pandas/tests/io/formats/test_info.py b/pandas/tests/io/formats/test_info.py index 6c3bf01cb1857..2fc22043ef765 100644 --- a/pandas/tests/io/formats/test_info.py +++ b/pandas/tests/io/formats/test_info.py @@ -40,7 +40,7 @@ def test_info_empty(): result = buf.getvalue() expected = textwrap.dedent( """\ - + RangeIndex: 0 entries Empty DataFrame\n""" ) @@ -194,7 +194,7 @@ def test_info_memory(): bytes = float(df.memory_usage().sum()) expected = textwrap.dedent( f"""\ - + RangeIndex: 2 entries, 0 to 1 Data columns (total 1 columns): # Column Non-Null Count Dtype @@ -487,7 +487,7 @@ def test_info_int_columns(): result = buf.getvalue() expected = textwrap.dedent( """\ - + Index: 2 entries, A to B Data columns (total 2 columns): # Column Non-Null Count Dtype From c7ea1d32b37389f2a0179614915f3bad12ab43a6 Mon Sep 17 00:00:00 2001 From: deepak Date: Mon, 18 Sep 2023 16:44:58 +0200 Subject: [PATCH 7/8] add new line for test --- pandas/tests/api/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index f22fe438ae52a..70e6f19ae30fb 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -384,4 +384,4 @@ def test_pandas_array_alias(): def test_set_module(): - assert pd.DataFrame.__module__ == "pandas" \ No newline at end of file + assert pd.DataFrame.__module__ == "pandas" From d337a7131071193c095f8d477e9652eb375aeaa7 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 23 Mar 2024 10:35:23 +0100 Subject: [PATCH 8/8] lint --- pandas/util/_decorators.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 6f4934a4733f2..d287fa72d552d 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -510,11 +510,12 @@ def set_module(module): Example usage:: - @set_module('pandas') + @set_module("pandas") def example(): pass - assert example.__module__ == 'pandas' + + assert example.__module__ == "pandas" """ def decorator(func):