Skip to content

Commit 19801b8

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#53403)
* NA, InvalidVersion, & Index examples * Changed None to np.nan
1 parent df6c30a commit 19801b8

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
@@ -1065,6 +1065,14 @@ def astype(self, dtype, copy: bool = True):
10651065
-------
10661066
Index
10671067
Index with values cast to specified dtype.
1068+
1069+
Examples
1070+
--------
1071+
>>> idx = pd.Index([1, 2, 3])
1072+
>>> idx
1073+
Index([1, 2, 3], dtype='int64')
1074+
>>> idx.astype('float')
1075+
Index([1.0, 2.0, 3.0], dtype='float64')
10681076
"""
10691077
if dtype is not None:
10701078
dtype = pandas_dtype(dtype)
@@ -2948,6 +2956,12 @@ def fillna(self, value=None, downcast=None):
29482956
--------
29492957
DataFrame.fillna : Fill NaN values of a DataFrame.
29502958
Series.fillna : Fill NaN Values of a Series.
2959+
2960+
Examples
2961+
--------
2962+
>>> idx = pd.Index([np.nan, np.nan, 3])
2963+
>>> idx.fillna(0)
2964+
Index([0.0, 0.0, 3.0], dtype='float64')
29512965
"""
29522966
if not is_scalar(value):
29532967
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}")
@@ -2978,6 +2992,12 @@ def dropna(self, how: AnyAll = "any") -> Self:
29782992
Returns
29792993
-------
29802994
Index
2995+
2996+
Examples
2997+
--------
2998+
>>> idx = pd.Index([1, np.nan, 3])
2999+
>>> idx.dropna()
3000+
Index([1.0, 3.0], dtype='float64')
29813001
"""
29823002
if how not in ("any", "all"):
29833003
raise ValueError(f"invalid how option: {how}")
@@ -4544,6 +4564,13 @@ def join(
45444564
Returns
45454565
-------
45464566
join_index, (left_indexer, right_indexer)
4567+
4568+
Examples
4569+
--------
4570+
>>> idx1 = pd.Index([1, 2, 3])
4571+
>>> idx2 = pd.Index([4, 5, 6])
4572+
>>> idx1.join(idx2, how='outer')
4573+
Index([1, 2, 3, 4, 5, 6], dtype='int64')
45474574
"""
45484575
other = ensure_index(other)
45494576

@@ -5368,6 +5395,12 @@ def append(self, other: Index | Sequence[Index]) -> Index:
53685395
Returns
53695396
-------
53705397
Index
5398+
5399+
Examples
5400+
--------
5401+
>>> idx = pd.Index([1, 2, 3])
5402+
>>> idx.append(pd.Index([4]))
5403+
Index([1, 2, 3, 4], dtype='int64')
53715404
"""
53725405
to_concat = [self]
53735406

@@ -6304,6 +6337,22 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
63046337
The output of the mapping function applied to the index.
63056338
If the function returns a tuple with more than one element
63066339
a MultiIndex will be returned.
6340+
6341+
Examples
6342+
--------
6343+
>>> idx = pd.Index([1, 2, 3])
6344+
>>> idx.map({1: 'a', 2: 'b', 3: 'c'})
6345+
Index(['a', 'b', 'c'], dtype='object')
6346+
6347+
Using `map` with a function:
6348+
6349+
>>> idx = pd.Index([1, 2, 3])
6350+
>>> idx.map('I am a {}'.format)
6351+
Index(['I am a 1', 'I am a 2', 'I am a 3'], dtype='object')
6352+
6353+
>>> idx = pd.Index(['a', 'b', 'c'])
6354+
>>> idx.map(lambda x: x.upper())
6355+
Index(['A', 'B', 'C'], dtype='object')
63076356
"""
63086357
from pandas.core.indexes.multi import MultiIndex
63096358

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)