Skip to content

Commit 5e725e9

Browse files
authored
DOC: Fixing EX01 - Added examples (pandas-dev#53306)
* Added examples for Interval and IntervalArray * changed code_checks.sh * forgot these * Some examples for Index
1 parent 7b22448 commit 5e725e9

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

ci/code_checks.sh

-8
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
260260
pandas.util.hash_pandas_object \
261261
pandas_object \
262262
pandas.api.interchange.from_dataframe \
263-
pandas.Index.values \
264-
pandas.Index.dtype \
265-
pandas.Index.inferred_type \
266-
pandas.Index.shape \
267-
pandas.Index.name \
268-
pandas.Index.nbytes \
269-
pandas.Index.ndim \
270-
pandas.Index.size \
271263
pandas.Index.T \
272264
pandas.Index.memory_usage \
273265
pandas.Index.copy \

pandas/core/base.py

+28
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ def ndim(self) -> Literal[1]:
346346
dtype: object
347347
>>> s.ndim
348348
1
349+
350+
For Index:
351+
352+
>>> idx = pd.Index([1, 2, 3])
353+
>>> idx
354+
Index([1, 2, 3], dtype='int64')
355+
>>> idx.ndim
356+
1
349357
"""
350358
return 1
351359

@@ -387,6 +395,8 @@ def nbytes(self) -> int:
387395
388396
Examples
389397
--------
398+
For Series:
399+
390400
>>> s = pd.Series(['Ant', 'Bear', 'Cow'])
391401
>>> s
392402
0 Ant
@@ -395,6 +405,14 @@ def nbytes(self) -> int:
395405
dtype: object
396406
>>> s.nbytes
397407
24
408+
409+
For Index:
410+
411+
>>> idx = pd.Index([1, 2, 3])
412+
>>> idx
413+
Index([1, 2, 3], dtype='int64')
414+
>>> idx.nbytes
415+
24
398416
"""
399417
return self._values.nbytes
400418

@@ -405,6 +423,8 @@ def size(self) -> int:
405423
406424
Examples
407425
--------
426+
For Series:
427+
408428
>>> s = pd.Series(['Ant', 'Bear', 'Cow'])
409429
>>> s
410430
0 Ant
@@ -413,6 +433,14 @@ def size(self) -> int:
413433
dtype: object
414434
>>> s.size
415435
3
436+
437+
For Index:
438+
439+
>>> idx = pd.Index([1, 2, 3])
440+
>>> idx
441+
Index([1, 2, 3], dtype='int64')
442+
>>> idx.size
443+
3
416444
"""
417445
return len(self._values)
418446

pandas/core/indexes/base.py

+40
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,14 @@ def __array_wrap__(self, result, context=None):
944944
def dtype(self) -> DtypeObj:
945945
"""
946946
Return the dtype object of the underlying data.
947+
948+
Examples
949+
--------
950+
>>> idx = pd.Index([1, 2, 3])
951+
>>> idx
952+
Index([1, 2, 3], dtype='int64')
953+
>>> idx.dtype
954+
dtype('int64')
947955
"""
948956
return self._data.dtype
949957

@@ -1599,6 +1607,14 @@ def to_frame(
15991607
def name(self) -> Hashable:
16001608
"""
16011609
Return Index or MultiIndex name.
1610+
1611+
Examples
1612+
--------
1613+
>>> idx = pd.Index([1, 2, 3], name='x')
1614+
>>> idx
1615+
Index([1, 2, 3], dtype='int64', name='x')
1616+
>>> idx.name
1617+
'x'
16021618
"""
16031619
return self._name
16041620

@@ -2658,6 +2674,14 @@ def holds_integer(self) -> bool:
26582674
def inferred_type(self) -> str_t:
26592675
"""
26602676
Return a string of the type inferred from the values.
2677+
2678+
Examples
2679+
--------
2680+
>>> idx = pd.Index([1, 2, 3])
2681+
>>> idx
2682+
Index([1, 2, 3], dtype='int64')
2683+
>>> idx.inferred_type
2684+
'integer'
26612685
"""
26622686
return lib.infer_dtype(self._values, skipna=False)
26632687

@@ -4957,6 +4981,14 @@ def values(self) -> ArrayLike:
49574981
--------
49584982
Index.array : Reference to the underlying data.
49594983
Index.to_numpy : A NumPy array representing the underlying data.
4984+
4985+
Examples
4986+
--------
4987+
>>> idx = pd.Index([1, 2, 3])
4988+
>>> idx
4989+
Index([1, 2, 3], dtype='int64')
4990+
>>> idx.values
4991+
array([1, 2, 3])
49604992
"""
49614993
return self._data
49624994

@@ -7177,6 +7209,14 @@ def max(self, axis=None, skipna: bool = True, *args, **kwargs):
71777209
def shape(self) -> Shape:
71787210
"""
71797211
Return a tuple of the shape of the underlying data.
7212+
7213+
Examples
7214+
--------
7215+
>>> idx = pd.Index([1, 2, 3])
7216+
>>> idx
7217+
Index([1, 2, 3], dtype='int64')
7218+
>>> idx.shape
7219+
(3,)
71807220
"""
71817221
# See GH#27775, GH#27384 for history/reasoning in how this is defined.
71827222
return (len(self),)

0 commit comments

Comments
 (0)