Skip to content

Commit 9a80e3a

Browse files
DOC: Fix docstring validation for Series (GH-59592)
1 parent 0ec3054 commit 9a80e3a

File tree

1 file changed

+30
-99
lines changed

1 file changed

+30
-99
lines changed

pandas/core/series.py

Lines changed: 30 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -237,105 +237,36 @@
237237
@set_module("pandas")
238238
class Series(base.IndexOpsMixin, NDFrame): # type: ignore[misc]
239239
"""
240-
One-dimensional ndarray with axis labels (including time series).
241-
242-
Labels need not be unique but must be a hashable type. The object
243-
supports both integer- and label-based indexing and provides a host of
244-
methods for performing operations involving the index. Statistical
245-
methods from ndarray have been overridden to automatically exclude
246-
missing data (currently represented as NaN).
247-
248-
Operations between Series (+, -, /, \\*, \\*\\*) align values based on their
249-
associated index values-- they need not be the same length. The result
250-
index will be the sorted union of the two indexes.
251-
252-
Parameters
253-
----------
254-
data : array-like, Iterable, dict, or scalar value
255-
Contains data stored in Series. If data is a dict, argument order is
256-
maintained. Unordered sets are not supported.
257-
index : array-like or Index (1d)
258-
Values must be hashable and have the same length as `data`.
259-
Non-unique index values are allowed. Will default to
260-
RangeIndex (0, 1, 2, ..., n) if not provided. If data is dict-like
261-
and index is None, then the keys in the data are used as the index. If the
262-
index is not None, the resulting Series is reindexed with the index values.
263-
dtype : str, numpy.dtype, or ExtensionDtype, optional
264-
Data type for the output Series. If not specified, this will be
265-
inferred from `data`.
266-
See the :ref:`user guide <basics.dtypes>` for more usages.
267-
name : Hashable, default None
268-
The name to give to the Series.
269-
copy : bool, default False
270-
Copy input data. Only affects Series or 1d ndarray input. See examples.
271-
272-
See Also
273-
--------
274-
DataFrame : Two-dimensional, size-mutable, potentially heterogeneous tabular data.
275-
Index : Immutable sequence used for indexing and alignment.
276-
277-
Notes
278-
-----
279-
Please reference the :ref:`User Guide <basics.series>` for more information.
280-
281-
Examples
282-
--------
283-
Constructing Series from a dictionary with an Index specified
284-
285-
>>> d = {"a": 1, "b": 2, "c": 3}
286-
>>> ser = pd.Series(data=d, index=["a", "b", "c"])
287-
>>> ser
288-
a 1
289-
b 2
290-
c 3
291-
dtype: int64
292-
293-
The keys of the dictionary match with the Index values, hence the Index
294-
values have no effect.
295-
296-
>>> d = {"a": 1, "b": 2, "c": 3}
297-
>>> ser = pd.Series(data=d, index=["x", "y", "z"])
298-
>>> ser
299-
x NaN
300-
y NaN
301-
z NaN
302-
dtype: float64
303-
304-
Note that the Index is first built with the keys from the dictionary.
305-
After this the Series is reindexed with the given Index values, hence we
306-
get all NaN as a result.
307-
308-
Constructing Series from a list with `copy=False`.
309-
310-
>>> r = [1, 2]
311-
>>> ser = pd.Series(r, copy=False)
312-
>>> ser.iloc[0] = 999
313-
>>> r
314-
[1, 2]
315-
>>> ser
316-
0 999
317-
1 2
318-
dtype: int64
319-
320-
Due to input data type the Series has a `copy` of
321-
the original data even though `copy=False`, so
322-
the data is unchanged.
323-
324-
Constructing Series from a 1d ndarray with `copy=False`.
325-
326-
>>> r = np.array([1, 2])
327-
>>> ser = pd.Series(r, copy=False)
328-
>>> ser.iloc[0] = 999
329-
>>> r
330-
array([999, 2])
331-
>>> ser
332-
0 999
333-
1 2
334-
dtype: int64
335-
336-
Due to input data type the Series has a `view` on
337-
the original data, so
338-
the data is changed as well.
240+
One-dimensional ndarray with axis labels (including time series).
241+
242+
Labels need not be unique but must be hashable (e.g. 1, 'a', or tuple).
243+
Non-unique labels can be accessed multiple times.
244+
245+
Parameters
246+
----------
247+
data : array-like, Iterable, dict, or scalar value
248+
Contains data stored in Series. If data is a dict, argument order is
249+
maintained if the Python version is >= 3.7 and python is not 3.6.
250+
251+
.. versionchanged:: 2.0.0
252+
Argument order is maintained if the Python version is >= 3.7 and python is not 3.6.
253+
index : array-like or Index (1d)
254+
Values must be hashable and have the same length as `data`. Non-unique
255+
index values are allowed. Default is RangeIndex(0, ..., n).
256+
257+
.. versionchanged:: 2.0.0
258+
Non-unique index values are allowed.
259+
dtype : str, numpy.dtype, or ExtensionDtype, optional
260+
Data type for the Series. If None, dtype will be inferred.
261+
name : str, optional
262+
The name to give to the Series.
263+
copy : bool, default False
264+
Copy input data.
265+
266+
Returns
267+
-------
268+
pandas.Series
269+
The constructed Series object.
339270
"""
340271

341272
_typ = "series"

0 commit comments

Comments
 (0)