Skip to content

DOC: Fixing EX01 - Added examples #53403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.errors.DataError \
pandas.errors.IncompatibilityWarning \
pandas.errors.InvalidComparison \
pandas.errors.InvalidVersion \
pandas.errors.IntCastingNaNError \
pandas.errors.LossySetitemError \
pandas.errors.MergeError \
Expand Down Expand Up @@ -165,7 +164,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.Period.asfreq \
pandas.Period.now \
pandas.arrays.PeriodArray \
pandas.NA \
pandas.CategoricalDtype.categories \
pandas.CategoricalDtype.ordered \
pandas.Categorical.dtype \
Expand Down Expand Up @@ -241,13 +239,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.util.hash_pandas_object \
pandas_object \
pandas.api.interchange.from_dataframe \
pandas.Index.fillna \
pandas.Index.dropna \
pandas.Index.astype \
pandas.Index.map \
pandas.Index.to_list \
pandas.Index.append \
pandas.Index.join \
pandas.Index.asof_locs \
pandas.Index.get_slice_bound \
pandas.RangeIndex \
Expand Down
20 changes: 20 additions & 0 deletions pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,26 @@ class NAType(C_NAType):

The NA singleton is a missing value indicator defined by pandas. It is
used in certain new extension dtypes (currently the "string" dtype).

Examples
--------
>>> pd.NA
<NA>

>>> True | pd.NA
True

>>> True & pd.NA
<NA>

>>> pd.NA != pd.NA
<NA>

>>> pd.NA == pd.NA
<NA>

>>> True | pd.NA
True
"""

_instance = None
Expand Down
11 changes: 11 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,20 @@ def tolist(self):

Examples
--------
For Series

>>> s = pd.Series([1, 2, 3])
>>> s.to_list()
[1, 2, 3]

For Index:

>>> idx = pd.Index([1, 2, 3])
>>> idx
Index([1, 2, 3], dtype='int64')

>>> idx.to_list()
[1, 2, 3]
"""
return self._values.tolist()

Expand Down
49 changes: 49 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,14 @@ def astype(self, dtype, copy: bool = True):
-------
Index
Index with values cast to specified dtype.

Examples
--------
>>> idx = pd.Index([1, 2, 3])
>>> idx
Index([1, 2, 3], dtype='int64')
>>> idx.astype('float')
Index([1.0, 2.0, 3.0], dtype='float64')
"""
if dtype is not None:
dtype = pandas_dtype(dtype)
Expand Down Expand Up @@ -2939,6 +2947,12 @@ def fillna(self, value=None, downcast=None):
--------
DataFrame.fillna : Fill NaN values of a DataFrame.
Series.fillna : Fill NaN Values of a Series.

Examples
--------
>>> idx = pd.Index([np.nan, np.nan, 3])
>>> idx.fillna(0)
Index([0.0, 0.0, 3.0], dtype='float64')
"""
if not is_scalar(value):
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}")
Expand Down Expand Up @@ -2969,6 +2983,12 @@ def dropna(self, how: AnyAll = "any") -> Self:
Returns
-------
Index

Examples
--------
>>> idx = pd.Index([1, np.nan, 3])
>>> idx.dropna()
Index([1.0, 3.0], dtype='float64')
"""
if how not in ("any", "all"):
raise ValueError(f"invalid how option: {how}")
Expand Down Expand Up @@ -4535,6 +4555,13 @@ def join(
Returns
-------
join_index, (left_indexer, right_indexer)

Examples
--------
>>> idx1 = pd.Index([1, 2, 3])
>>> idx2 = pd.Index([4, 5, 6])
>>> idx1.join(idx2, how='outer')
Index([1, 2, 3, 4, 5, 6], dtype='int64')
"""
other = ensure_index(other)

Expand Down Expand Up @@ -5359,6 +5386,12 @@ def append(self, other: Index | Sequence[Index]) -> Index:
Returns
-------
Index

Examples
--------
>>> idx = pd.Index([1, 2, 3])
>>> idx.append(pd.Index([4]))
Index([1, 2, 3, 4], dtype='int64')
"""
to_concat = [self]

Expand Down Expand Up @@ -6295,6 +6328,22 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
The output of the mapping function applied to the index.
If the function returns a tuple with more than one element
a MultiIndex will be returned.

Examples
--------
>>> idx = pd.Index([1, 2, 3])
>>> idx.map({1: 'a', 2: 'b', 3: 'c'})
Index(['a', 'b', 'c'], dtype='object')

Using `map` with a function:

>>> idx = pd.Index([1, 2, 3])
>>> idx.map('I am a {}'.format)
Index(['I am a 1', 'I am a 2', 'I am a 3'], dtype='object')
Comment on lines +6340 to +6342
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 nice example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was something similar already in the docs. I stole it. :-)


>>> idx = pd.Index(['a', 'b', 'c'])
>>> idx.map(lambda x: x.upper())
Index(['A', 'B', 'C'], dtype='object')
"""
from pandas.core.indexes.multi import MultiIndex

Expand Down
6 changes: 6 additions & 0 deletions pandas/util/version/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ def parse(version: str) -> LegacyVersion | Version:
class InvalidVersion(ValueError):
"""
An invalid version was found, users should refer to PEP 440.

Examples
--------
>>> pd.util.version.Version('1.')
Traceback (most recent call last):
InvalidVersion: Invalid version: '1.'
"""


Expand Down