Skip to content

DOC: Series.sum() has examples that don't illustrate the actual results #62966

@Dr-Irv

Description

@Dr-Irv

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/reference/api/pandas.Series.sum.html

Documentation problem

Consider this example from the docs:

>>> idx = pd.MultiIndex.from_arrays(
...     [["warm", "warm", "cold", "cold"], ["dog", "falcon", "fish", "spider"]],
...     names=["blooded", "animal"],
... )
>>> s = pd.Series([4, 2, 0, 8], name="legs", index=idx)
>>> s.sum()

The docs indicate that s.sum() is 14.
But at runtime, it is an np.int64:

>>> s.sum()
np.int64(14)

But the printed result depends on the backend:

>>> s = pd.Series([4,2,0,8], name="legs", index=idx, dtype="int64[pyarrow]")
>>> s.sum()
14

The example results are hard coded in the docs, and are not created by executing the code (as in other doc areas).

Suggested fix for documentation

Not sure. Do we fix the docs so that it executes the code rather than have hard coded results?

Do we want to indicate whether we are returning numpy types or python types?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions