Skip to content

Commit 4d1d169

Browse files
DeaMariaLeontopper-123
authored andcommitted
DOC: Fixing EX01 - Added examples (pandas-dev#53403)
* NA, InvalidVersion, & Index examples * Changed None to np.nan
1 parent 8ebacf5 commit 4d1d169

File tree

5 files changed

+86
-9
lines changed

5 files changed

+86
-9
lines changed

ci/code_checks.sh

-9
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
117117
pandas.errors.DataError \
118118
pandas.errors.IncompatibilityWarning \
119119
pandas.errors.InvalidComparison \
120-
pandas.errors.InvalidVersion \
121120
pandas.errors.IntCastingNaNError \
122121
pandas.errors.LossySetitemError \
123122
pandas.errors.MergeError \
@@ -165,7 +164,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
165164
pandas.Period.asfreq \
166165
pandas.Period.now \
167166
pandas.arrays.PeriodArray \
168-
pandas.NA \
169167
pandas.CategoricalDtype.categories \
170168
pandas.CategoricalDtype.ordered \
171169
pandas.Categorical.dtype \
@@ -241,13 +239,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
241239
pandas.util.hash_pandas_object \
242240
pandas_object \
243241
pandas.api.interchange.from_dataframe \
244-
pandas.Index.fillna \
245-
pandas.Index.dropna \
246-
pandas.Index.astype \
247-
pandas.Index.map \
248-
pandas.Index.to_list \
249-
pandas.Index.append \
250-
pandas.Index.join \
251242
pandas.Index.asof_locs \
252243
pandas.Index.get_slice_bound \
253244
pandas.RangeIndex \

pandas/_libs/missing.pyx

+20
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,26 @@ class NAType(C_NAType):
377377
378378
The NA singleton is a missing value indicator defined by pandas. It is
379379
used in certain new extension dtypes (currently the "string" dtype).
380+
381+
Examples
382+
--------
383+
>>> pd.NA
384+
<NA>
385+
386+
>>> True | pd.NA
387+
True
388+
389+
>>> True & pd.NA
390+
<NA>
391+
392+
>>> pd.NA != pd.NA
393+
<NA>
394+
395+
>>> pd.NA == pd.NA
396+
<NA>
397+
398+
>>> True | pd.NA
399+
True
380400
"""
381401

382402
_instance = None

pandas/core/base.py

+11
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,20 @@ def tolist(self):
765765
766766
Examples
767767
--------
768+
For Series
769+
768770
>>> s = pd.Series([1, 2, 3])
769771
>>> s.to_list()
770772
[1, 2, 3]
773+
774+
For Index:
775+
776+
>>> idx = pd.Index([1, 2, 3])
777+
>>> idx
778+
Index([1, 2, 3], dtype='int64')
779+
780+
>>> idx.to_list()
781+
[1, 2, 3]
771782
"""
772783
return self._values.tolist()
773784

pandas/core/indexes/base.py

+49
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,14 @@ def astype(self, dtype, copy: bool = True):
10561056
-------
10571057
Index
10581058
Index with values cast to specified dtype.
1059+
1060+
Examples
1061+
--------
1062+
>>> idx = pd.Index([1, 2, 3])
1063+
>>> idx
1064+
Index([1, 2, 3], dtype='int64')
1065+
>>> idx.astype('float')
1066+
Index([1.0, 2.0, 3.0], dtype='float64')
10591067
"""
10601068
if dtype is not None:
10611069
dtype = pandas_dtype(dtype)
@@ -2939,6 +2947,12 @@ def fillna(self, value=None, downcast=None):
29392947
--------
29402948
DataFrame.fillna : Fill NaN values of a DataFrame.
29412949
Series.fillna : Fill NaN Values of a Series.
2950+
2951+
Examples
2952+
--------
2953+
>>> idx = pd.Index([np.nan, np.nan, 3])
2954+
>>> idx.fillna(0)
2955+
Index([0.0, 0.0, 3.0], dtype='float64')
29422956
"""
29432957
if not is_scalar(value):
29442958
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}")
@@ -2969,6 +2983,12 @@ def dropna(self, how: AnyAll = "any") -> Self:
29692983
Returns
29702984
-------
29712985
Index
2986+
2987+
Examples
2988+
--------
2989+
>>> idx = pd.Index([1, np.nan, 3])
2990+
>>> idx.dropna()
2991+
Index([1.0, 3.0], dtype='float64')
29722992
"""
29732993
if how not in ("any", "all"):
29742994
raise ValueError(f"invalid how option: {how}")
@@ -4535,6 +4555,13 @@ def join(
45354555
Returns
45364556
-------
45374557
join_index, (left_indexer, right_indexer)
4558+
4559+
Examples
4560+
--------
4561+
>>> idx1 = pd.Index([1, 2, 3])
4562+
>>> idx2 = pd.Index([4, 5, 6])
4563+
>>> idx1.join(idx2, how='outer')
4564+
Index([1, 2, 3, 4, 5, 6], dtype='int64')
45384565
"""
45394566
other = ensure_index(other)
45404567

@@ -5359,6 +5386,12 @@ def append(self, other: Index | Sequence[Index]) -> Index:
53595386
Returns
53605387
-------
53615388
Index
5389+
5390+
Examples
5391+
--------
5392+
>>> idx = pd.Index([1, 2, 3])
5393+
>>> idx.append(pd.Index([4]))
5394+
Index([1, 2, 3, 4], dtype='int64')
53625395
"""
53635396
to_concat = [self]
53645397

@@ -6295,6 +6328,22 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
62956328
The output of the mapping function applied to the index.
62966329
If the function returns a tuple with more than one element
62976330
a MultiIndex will be returned.
6331+
6332+
Examples
6333+
--------
6334+
>>> idx = pd.Index([1, 2, 3])
6335+
>>> idx.map({1: 'a', 2: 'b', 3: 'c'})
6336+
Index(['a', 'b', 'c'], dtype='object')
6337+
6338+
Using `map` with a function:
6339+
6340+
>>> idx = pd.Index([1, 2, 3])
6341+
>>> idx.map('I am a {}'.format)
6342+
Index(['I am a 1', 'I am a 2', 'I am a 3'], dtype='object')
6343+
6344+
>>> idx = pd.Index(['a', 'b', 'c'])
6345+
>>> idx.map(lambda x: x.upper())
6346+
Index(['A', 'B', 'C'], dtype='object')
62986347
"""
62996348
from pandas.core.indexes.multi import MultiIndex
63006349

pandas/util/version/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ def parse(version: str) -> LegacyVersion | Version:
129129
class InvalidVersion(ValueError):
130130
"""
131131
An invalid version was found, users should refer to PEP 440.
132+
133+
Examples
134+
--------
135+
>>> pd.util.version.Version('1.')
136+
Traceback (most recent call last):
137+
InvalidVersion: Invalid version: '1.'
132138
"""
133139

134140

0 commit comments

Comments
 (0)