Skip to content

Commit 23a8505

Browse files
authored
ENH: set __module__ in core.reshape.{melt,pivot,tile} (#62420)
1 parent 22bae73 commit 23a8505

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

pandas/core/reshape/melt.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import numpy as np
77

8+
from pandas.util._decorators import set_module
9+
810
from pandas.core.dtypes.common import (
911
is_iterator,
1012
is_list_like,
@@ -39,6 +41,7 @@ def ensure_list_vars(arg_vars, variable: str, columns) -> list:
3941
return []
4042

4143

44+
@set_module("pandas")
4245
def melt(
4346
frame: DataFrame,
4447
id_vars=None,
@@ -275,6 +278,7 @@ def melt(
275278
return result
276279

277280

281+
@set_module("pandas")
278282
def lreshape(data: DataFrame, groups: dict, dropna: bool = True) -> DataFrame:
279283
"""
280284
Reshape wide-format data to long. Generalized inverse of DataFrame.pivot.
@@ -361,6 +365,7 @@ def lreshape(data: DataFrame, groups: dict, dropna: bool = True) -> DataFrame:
361365
return data._constructor(mdata, columns=id_cols + pivot_cols)
362366

363367

368+
@set_module("pandas")
364369
def wide_to_long(
365370
df: DataFrame, stubnames, i, j, sep: str = "", suffix: str = r"\d+"
366371
) -> DataFrame:

pandas/core/reshape/pivot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import numpy as np
1111

1212
from pandas._libs import lib
13+
from pandas.util._decorators import set_module
1314

1415
from pandas.core.dtypes.cast import maybe_downcast_to_dtype
1516
from pandas.core.dtypes.common import (
@@ -50,6 +51,7 @@
5051
from pandas import DataFrame
5152

5253

54+
@set_module("pandas")
5355
def pivot_table(
5456
data: DataFrame,
5557
values=None,
@@ -699,6 +701,7 @@ def _convert_by(by):
699701
return by
700702

701703

704+
@set_module("pandas")
702705
def pivot(
703706
data: DataFrame,
704707
*,
@@ -917,6 +920,7 @@ def pivot(
917920
return result
918921

919922

923+
@set_module("pandas")
920924
def crosstab(
921925
index,
922926
columns,

pandas/core/reshape/tile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Timestamp,
1818
lib,
1919
)
20+
from pandas.util._decorators import set_module
2021

2122
from pandas.core.dtypes.common import (
2223
ensure_platform_int,
@@ -51,6 +52,7 @@
5152
)
5253

5354

55+
@set_module("pandas")
5456
def cut(
5557
x,
5658
bins,
@@ -287,6 +289,7 @@ def cut(
287289
return _postprocess_for_cut(fac, bins, retbins, original)
288290

289291

292+
@set_module("pandas")
290293
def qcut(
291294
x,
292295
q,

pandas/tests/api/test_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,5 +530,13 @@ def test_set_module():
530530
assert pd.to_numeric.__module__ == "pandas"
531531
assert pd.NamedAgg.__module__ == "pandas"
532532
assert pd.IndexSlice.__module__ == "pandas"
533+
assert pd.lreshape.__module__ == "pandas"
534+
assert pd.melt.__module__ == "pandas"
535+
assert pd.wide_to_long.__module__ == "pandas"
536+
assert pd.crosstab.__module__ == "pandas"
537+
assert pd.pivot_table.__module__ == "pandas"
538+
assert pd.pivot.__module__ == "pandas"
539+
assert pd.cut.__module__ == "pandas"
540+
assert pd.qcut.__module__ == "pandas"
533541
assert api.typing.SeriesGroupBy.__module__ == "pandas.api.typing"
534542
assert api.typing.DataFrameGroupBy.__module__ == "pandas.api.typing"

0 commit comments

Comments
 (0)