Skip to content

Commit a211b51

Browse files
topper-123jorisvandenbossche
authored andcommitted
DOC: add references for different index types + examples for pd.Index (#17680)
1 parent 1bc238a commit a211b51

File tree

10 files changed

+105
-12
lines changed

10 files changed

+105
-12
lines changed

doc/source/api.rst

+47-2
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,52 @@ Conversion
16261626

16271627
.. currentmodule:: pandas
16281628

1629+
PeriodIndex
1630+
--------------
1631+
1632+
.. autosummary::
1633+
:toctree: generated/
1634+
:template: autosummary/class_without_autosummary.rst
1635+
1636+
PeriodIndex
1637+
1638+
Attributes
1639+
~~~~~~~~~~
1640+
.. autosummary::
1641+
:toctree: generated/
1642+
1643+
PeriodIndex.day
1644+
PeriodIndex.dayofweek
1645+
PeriodIndex.dayofyear
1646+
PeriodIndex.days_in_month
1647+
PeriodIndex.daysinmonth
1648+
PeriodIndex.end_time
1649+
PeriodIndex.freq
1650+
PeriodIndex.freqstr
1651+
PeriodIndex.hour
1652+
PeriodIndex.is_leap_year
1653+
PeriodIndex.minute
1654+
PeriodIndex.month
1655+
PeriodIndex.quarter
1656+
PeriodIndex.qyear
1657+
PeriodIndex.second
1658+
PeriodIndex.start_time
1659+
PeriodIndex.week
1660+
PeriodIndex.weekday
1661+
PeriodIndex.weekofyear
1662+
PeriodIndex.year
1663+
1664+
Methods
1665+
~~~~~~~
1666+
.. autosummary::
1667+
:toctree: generated/
1668+
1669+
PeriodIndex.asfreq
1670+
PeriodIndex.strftime
1671+
PeriodIndex.to_timestamp
1672+
PeriodIndex.tz_convert
1673+
PeriodIndex.tz_localize
1674+
16291675
Scalars
16301676
-------
16311677

@@ -1653,13 +1699,11 @@ Attributes
16531699
Period.is_leap_year
16541700
Period.minute
16551701
Period.month
1656-
Period.now
16571702
Period.ordinal
16581703
Period.quarter
16591704
Period.qyear
16601705
Period.second
16611706
Period.start_time
1662-
Period.strftime
16631707
Period.week
16641708
Period.weekday
16651709
Period.weekofyear
@@ -1671,6 +1715,7 @@ Methods
16711715
:toctree: generated/
16721716

16731717
Period.asfreq
1718+
Period.now
16741719
Period.strftime
16751720
Period.to_timestamp
16761721

doc/sphinxext/numpydoc/numpydoc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def mangle_docstrings(app, what, name, obj, options, lines,
4545
# PANDAS HACK (to remove the list of methods/attributes for Categorical)
4646
no_autosummary = [".Categorical", "CategoricalIndex", "IntervalIndex",
4747
"RangeIndex", "Int64Index", "UInt64Index",
48-
"Float64Index"]
48+
"Float64Index", "PeriodIndex"]
4949
if what == "class" and any(name.endswith(n) for n in no_autosummary):
5050
cfg['class_members_list'] = False
5151

pandas/core/indexes/base.py

+17
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,23 @@ class Index(IndexOpsMixin, PandasObject):
123123
Notes
124124
-----
125125
An Index instance can **only** contain hashable objects
126+
127+
Examples
128+
--------
129+
>>> pd.Index([1, 2, 3])
130+
Int64Index([1, 2, 3], dtype='int64')
131+
132+
>>> pd.Index(list('abc'))
133+
Index(['a', 'b', 'c'], dtype='object')
134+
135+
See Also
136+
---------
137+
RangeIndex : Index implementing a monotonic integer range
138+
CategoricalIndex : Index of :class:`Categorical` s.
139+
MultiIndex : A multi-level, or hierarchical, Index
140+
IntervalIndex : an Index of :class:`Interval` s.
141+
DatetimeIndex, TimedeltaIndex, PeriodIndex
142+
Int64Index, UInt64Index, Float64Index
126143
"""
127144
# To hand over control to subclasses
128145
_join_precedence = 1

pandas/core/indexes/datetimes.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,14 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin,
208208
209209
Notes
210210
-----
211-
212211
To learn more about the frequency strings, please see `this link
213212
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
213+
214+
See Also
215+
---------
216+
Index : The base pandas Index type
217+
TimedeltaIndex : Index of timedelta64 data
218+
PeriodIndex : Index of Period data
214219
"""
215220

216221
_typ = 'datetimeindex'

pandas/core/indexes/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class IntervalIndex(IntervalMixin, Index):
147147
148148
See Also
149149
--------
150-
Index
150+
Index : The base pandas Index type
151151
Interval : A bounded slice-like interval
152152
interval_range : Function to create a fixed frequency
153153
IntervalIndex, IntervalIndex.from_arrays, IntervalIndex.from_breaks,

pandas/core/indexes/multi.py

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class MultiIndex(Index):
9595
MultiIndex.from_product : Create a MultiIndex from the cartesian product
9696
of iterables
9797
MultiIndex.from_tuples : Convert list of tuples to a MultiIndex
98+
Index : The base pandas Index type
9899
"""
99100

100101
# initialize to zero-length tuples to make everything work

pandas/core/indexes/numeric.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,21 @@ def is_all_dates(self):
108108
Make a copy of input ndarray
109109
name : object
110110
Name to be stored in the index
111+
111112
Notes
112113
-----
113114
An Index instance can **only** contain hashable objects.
115+
116+
See also
117+
--------
118+
Index : The base pandas Index type
114119
"""
115120

116121
_int64_descr_args = dict(
117122
klass='Int64Index',
118123
ltype='integer',
119124
dtype='int64',
120-
extra="""This is the default index type used
121-
by the DataFrame and Series ctors when no explicit
122-
index is provided by the user.
123-
"""
125+
extra=''
124126
)
125127

126128

pandas/core/indexes/period.py

+7
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ class PeriodIndex(DatelikeOps, DatetimeIndexOpsMixin, Int64Index):
164164
>>> idx = PeriodIndex(year=year_arr, quarter=q_arr)
165165
166166
>>> idx2 = PeriodIndex(start='2000', end='2010', freq='A')
167+
168+
See Also
169+
---------
170+
Index : The base pandas Index type
171+
Period : Represents a period of time
172+
DatetimeIndex : Index with datetime64 data
173+
TimedeltaIndex : Index of timedelta64 data
167174
"""
168175
_box_scalars = True
169176
_typ = 'periodindex'

pandas/core/indexes/range.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
class RangeIndex(Int64Index):
2424

2525
"""
26-
Immutable Index implementing a monotonic range. RangeIndex is a
27-
memory-saving special case of Int64Index limited to representing
28-
monotonic ranges.
26+
Immutable Index implementing a monotonic integer range.
27+
28+
RangeIndex is a memory-saving special case of Int64Index limited to
29+
representing monotonic ranges. Using RangeIndex may in some instances
30+
improve computing speed.
31+
32+
This is the default index type used
33+
by DataFrame and Series when no explicit index is provided by the user.
2934
3035
Parameters
3136
----------
@@ -38,6 +43,10 @@ class RangeIndex(Int64Index):
3843
copy : bool, default False
3944
Unused, accepted for homogeneity with other index types.
4045
46+
See Also
47+
--------
48+
Index : The base pandas Index type
49+
Int64Index : Index of int64 data
4150
"""
4251

4352
_typ = 'rangeindex'

pandas/core/indexes/timedeltas.py

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ class TimedeltaIndex(DatetimeIndexOpsMixin, TimelikeOps, Int64Index):
114114
115115
To learn more about the frequency strings, please see `this link
116116
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
117+
118+
See Also
119+
---------
120+
Index : The base pandas Index type
121+
Timedelta : Represents a duration between two dates or times.
122+
DatetimeIndex : Index of datetime64 data
123+
PeriodIndex : Index of Period data
117124
"""
118125

119126
_typ = 'timedeltaindex'

0 commit comments

Comments
 (0)