Skip to content

Commit b434476

Browse files
authored
ENH: set __module__ on Series (#60263)
1 parent 4fcee0e commit b434476

File tree

9 files changed

+15
-12
lines changed

9 files changed

+15
-12
lines changed

doc/source/development/contributing_docstring.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ Finally, docstrings can also be appended to with the ``doc`` decorator.
940940

941941
In this example, we'll create a parent docstring normally (this is like
942942
``pandas.core.generic.NDFrame``). Then we'll have two children (like
943-
``pandas.core.series.Series`` and ``pandas.DataFrame``). We'll
943+
``pandas.Series`` and ``pandas.DataFrame``). We'll
944944
substitute the class names in this docstring.
945945

946946
.. code-block:: python
@@ -995,5 +995,5 @@ mapping function names to docstrings. Wherever possible, we prefer using
995995
``doc``, since the docstring-writing processes is slightly closer to normal.
996996

997997
See ``pandas.core.generic.NDFrame.fillna`` for an example template, and
998-
``pandas.core.series.Series.fillna`` and ``pandas.core.generic.frame.fillna``
998+
``pandas.Series.fillna`` and ``pandas.core.generic.frame.fillna``
999999
for the filled versions.

pandas/core/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def iloc(self) -> _iLocIndexer:
212212
With a scalar integer.
213213
214214
>>> type(df.iloc[0])
215-
<class 'pandas.core.series.Series'>
215+
<class 'pandas.Series'>
216216
>>> df.iloc[0]
217217
a 1
218218
b 2

pandas/core/series.py

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
Substitution,
5151
deprecate_nonkeyword_arguments,
5252
doc,
53+
set_module,
5354
)
5455
from pandas.util._validators import (
5556
validate_ascending,
@@ -229,6 +230,7 @@
229230
# error: Cannot override final attribute "size" (previously declared in base
230231
# class "NDFrame")
231232
# definition in base class "NDFrame"
233+
@set_module("pandas")
232234
class Series(base.IndexOpsMixin, NDFrame): # type: ignore[misc]
233235
"""
234236
One-dimensional ndarray with axis labels (including time series).

pandas/io/formats/info.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
>>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
166166
>>> s = pd.Series(text_values, index=int_values)
167167
>>> s.info()
168-
<class 'pandas.core.series.Series'>
168+
<class 'pandas.Series'>
169169
Index: 5 entries, 1 to 5
170170
Series name: None
171171
Non-Null Count Dtype
@@ -177,7 +177,7 @@
177177
Prints a summary excluding information about its values:
178178
179179
>>> s.info(verbose=False)
180-
<class 'pandas.core.series.Series'>
180+
<class 'pandas.Series'>
181181
Index: 5 entries, 1 to 5
182182
dtypes: object(1)
183183
memory usage: 80.0+ bytes
@@ -200,7 +200,7 @@
200200
>>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6)
201201
>>> s = pd.Series(np.random.choice(['a', 'b', 'c'], 10 ** 6))
202202
>>> s.info()
203-
<class 'pandas.core.series.Series'>
203+
<class 'pandas.Series'>
204204
RangeIndex: 1000000 entries, 0 to 999999
205205
Series name: None
206206
Non-Null Count Dtype
@@ -210,7 +210,7 @@
210210
memory usage: 7.6+ MB
211211
212212
>>> s.info(memory_usage='deep')
213-
<class 'pandas.core.series.Series'>
213+
<class 'pandas.Series'>
214214
RangeIndex: 1000000 entries, 0 to 999999
215215
Series name: None
216216
Non-Null Count Dtype

pandas/plotting/_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def hist_frame(
428428
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by='X',
429429
... return_type='axes')
430430
>>> type(boxplot)
431-
<class 'pandas.core.series.Series'>
431+
<class 'pandas.Series'>
432432
433433
If ``return_type`` is `None`, a NumPy array of axes with the same shape
434434
as ``layout`` is returned:

pandas/tests/api/test_api.py

+1
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,4 @@ def test_set_module():
416416
assert pd.Period.__module__ == "pandas"
417417
assert pd.Timestamp.__module__ == "pandas"
418418
assert pd.Timedelta.__module__ == "pandas"
419+
assert pd.Series.__module__ == "pandas"

pandas/tests/io/pytables/test_append.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ def test_append_raise(setup_path):
795795
# series directly
796796
msg = re.escape(
797797
"cannot properly create the storer for: "
798-
"[group->df,value-><class 'pandas.core.series.Series'>]"
798+
"[group->df,value-><class 'pandas.Series'>]"
799799
)
800800
with pytest.raises(TypeError, match=msg):
801801
store.append("df", Series(np.arange(10)))

pandas/tests/series/methods/test_argsort.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_argsort_stable(self):
6666
tm.assert_series_equal(qindexer.astype(np.intp), Series(qexpected))
6767
msg = (
6868
r"ndarray Expected type <class 'numpy\.ndarray'>, "
69-
r"found <class 'pandas\.core\.series\.Series'> instead"
69+
r"found <class 'pandas\.Series'> instead"
7070
)
7171
with pytest.raises(AssertionError, match=msg):
7272
tm.assert_numpy_array_equal(qindexer, mindexer)

pandas/tests/series/methods/test_info.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_info_series(
5656

5757
expected = textwrap.dedent(
5858
"""\
59-
<class 'pandas.core.series.Series'>
59+
<class 'pandas.Series'>
6060
MultiIndex: 10 entries, ('foo', 'one') to ('qux', 'three')
6161
"""
6262
)
@@ -87,7 +87,7 @@ def test_info_memory():
8787
memory_bytes = float(s.memory_usage())
8888
expected = textwrap.dedent(
8989
f"""\
90-
<class 'pandas.core.series.Series'>
90+
<class 'pandas.Series'>
9191
RangeIndex: 2 entries, 0 to 1
9292
Series name: None
9393
Non-Null Count Dtype

0 commit comments

Comments
 (0)