Skip to content
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

DOC: document subclasses in API docs with selection of specific methods/attributes #18202

Merged
merged 34 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
500ab71
DOC: Remove numpydoc hack, list methods explicitly
TomAugspurger Nov 9, 2017
257fc8a
[WIP]: API doc
TomAugspurger Nov 9, 2017
d59c0b5
More explicit methods
TomAugspurger Nov 10, 2017
cb57504
More updates
TomAugspurger Nov 10, 2017
5e4cf6d
typos
TomAugspurger Nov 10, 2017
346a73b
Merge remote-tracking branch 'upstream/master' into api-doc-methods
TomAugspurger Nov 11, 2017
b5902ff
more
TomAugspurger Nov 12, 2017
af1e866
Merge remote-tracking branch 'upstream/master' into api-doc-methods
TomAugspurger Nov 12, 2017
874aefe
Add accessors to hidden
TomAugspurger Nov 12, 2017
32c2816
Remove dupe section
TomAugspurger Nov 12, 2017
38673bd
Added Categorical
TomAugspurger Nov 12, 2017
e30335e
More fixups
TomAugspurger Nov 13, 2017
38efdcb
More cleanups
TomAugspurger Nov 13, 2017
5e8bcbe
PEP8
TomAugspurger Nov 13, 2017
8695727
Hide more items
TomAugspurger Nov 13, 2017
4476a5f
Fixups
TomAugspurger Nov 13, 2017
a5005e1
Matching NaT
TomAugspurger Nov 13, 2017
aa92592
Fix typo
TomAugspurger Nov 13, 2017
8841035
Merge remote-tracking branch 'upstream/master' into api-doc-methods
TomAugspurger Nov 13, 2017
1527cdb
PEP8
TomAugspurger Nov 13, 2017
7ca3434
Fix ordering, escaping
TomAugspurger Nov 14, 2017
5a0e10e
Add notes on contributing
TomAugspurger Nov 14, 2017
c8504d1
Fix kwds again
TomAugspurger Nov 14, 2017
f7ed015
Wording
TomAugspurger Nov 14, 2017
094f6f6
Fix ref
TomAugspurger Nov 14, 2017
1c2160f
Another fixup
TomAugspurger Nov 14, 2017
6e99be2
Series of dtype category
TomAugspurger Nov 14, 2017
3bd03db
Move more methods to hidden
TomAugspurger Nov 14, 2017
ba257cc
Hide get_loc
TomAugspurger Nov 14, 2017
169e833
Merge remote-tracking branch 'upstream/master' into api-doc-methods
TomAugspurger Nov 14, 2017
f846713
Just hide attributes
TomAugspurger Nov 14, 2017
141107a
Cleanup hidden
TomAugspurger Nov 14, 2017
3a224be
remove some methods from api.rst
jorisvandenbossche Nov 15, 2017
34834fa
fix warning for float64index
jorisvandenbossche Nov 15, 2017
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
326 changes: 316 additions & 10 deletions doc/source/api.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
]

exclude_patterns = ['**.ipynb_checkpoints']
numpydoc_show_class_members = False
Copy link
Member

Choose a reason for hiding this comment

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

Do you know why this is needed?


with open("index.rst") as f:
index_rst_lines = f.readlines()
Expand Down
7 changes: 0 additions & 7 deletions doc/sphinxext/numpydoc/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ def mangle_docstrings(app, what, name, obj, options, lines,
class_members_toctree=app.config.numpydoc_class_members_toctree,
)

# PANDAS HACK (to remove the list of methods/attributes for Categorical)
no_autosummary = [".Categorical", "CategoricalIndex", "IntervalIndex",
"RangeIndex", "Int64Index", "UInt64Index",
"Float64Index", "PeriodIndex", "CategoricalDtype"]
if what == "class" and any(name.endswith(n) for n in no_autosummary):
cfg['class_members_list'] = False

Copy link
Member

Choose a reason for hiding this comment

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

I think there is also some other code related to this hack that then could be removed (eg the place where I define the 'class_members_list' config). See cf40991 that added it

if what == 'module':
# Strip top title
title_re = re.compile(sixu('^\\s*[#*=]{4,}\\n[a-z0-9 -]+\\n[#*=]{4,}\\s*'),
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class CategoricalDtype(ExtensionDtype):
Must be unique, and must not contain any nulls.
ordered : bool, default False

Attributes
----------
categories
ordered

Notes
-----
This class is useful for specifying the type of a ``Categorical``
Expand Down
19 changes: 19 additions & 0 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ class CategoricalIndex(Index, accessor.PandasDelegate):
See Also
--------
Categorical, Index

Methods
-------
rename_categories
reorder_categories
add_categories
remove_categories
remove_unused_categories
set_categories
as_ordered
as_unordered
get_loc
Copy link
Member

Choose a reason for hiding this comment

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

Mentioned above as well: is there something categorical-specific about get_loc ?

(the map is fine, that has indeed some specifics that are useful)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just saw that the example mentioned CategoricalIndex specifically. Looks pretty similar though, so I'll remove it.

map

Attributes
Copy link
Member

Choose a reason for hiding this comment

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

Attributes before Methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed all these

----------
codes
categories
ordered
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would add here a sentence with something like "For all other methods, see Index", but I am not sure that is allowed in Attributes / Methods sections?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suspect not. I've been thinking of ways to handle this.

I'm not worried about people reading the source / in IPython. They already have the code or object.

I think in the Notes section we can say "See :class:Index for additional methods." or something like that.

"""

_typ = 'categoricalindex'
Expand Down
48 changes: 48 additions & 0 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,54 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin,
Index : The base pandas Index type
TimedeltaIndex : Index of timedelta64 data
PeriodIndex : Index of Period data

Methods
-------
normalize
strftime
snap
tz_convert
tz_localize
round
floor
ceil
to_datetime
to_period
to_perioddelta
to_pydatetime
to_series
to_frame

Attributes
----------
year
month
day
hour
minute
second
microsecond
nanosecond
date
time
dayofyear
weekofyear
week
dayofweek
weekday
weekday_name
quarter
tz
freq
freqstr
is_month_start
is_month_end
is_quarter_start
is_quarter_end
is_year_start
is_year_end
is_leap_year
inferred_freq
"""

_typ = 'datetimeindex'
Expand Down
18 changes: 18 additions & 0 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ class IntervalIndex(IntervalMixin, Index):
IntervalIndex.from_intervals, IntervalIndex.from_tuples
cut, qcut : convert arrays of continuous data into categoricals/series of
``Interval``.

Methods
-------
from_arrays
from_tuples
from_breaks
from_intervals
contains
get_loc

Attributes
----------
left
right
mid
closed
values
is_non_overlapping_monotonic
"""
_typ = 'intervalindex'
_comparables = ['name']
Expand Down
26 changes: 26 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ class MultiIndex(Index):
of iterables
MultiIndex.from_tuples : Convert list of tuples to a MultiIndex
Index : The base pandas Index type

Attributes
----------
names
levels
labels
nlevels
levshape

Methods
-------
from_arrays
from_tuples
from_product
set_levels
set_labels
to_hierarchical
to_frame
is_lexsorted
sortlevel
droplevel
swaplevel
reorder_levels
remove_unused_levels
"""

# initialize to zero-length tuples to make everything work
Expand Down Expand Up @@ -1364,10 +1388,12 @@ def remove_unused_levels(self):

@property
def nlevels(self):
"""Integer number of levels in this MultiIndex."""
return len(self.levels)

@property
def levshape(self):
"""A tuple with the length of each level."""
return tuple(len(x) for x in self.levels)

@Appender(_index_shared_docs['__contains__'] % _index_doc_kwargs)
Expand Down
31 changes: 31 additions & 0 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,37 @@ class PeriodIndex(DatelikeOps, DatetimeIndexOpsMixin, Int64Index):
Timezone for converting datetime64 data to Periods
dtype : str or PeriodDtype, default None

Attributes
----------
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm maybe we can auto gen these?

day
dayofweek
dayofyear
days_in_month
daysinmonth
end_time
freq
freqstr
hour
is_leap_year
minute
month
quarter
qyear
second
start_time
week
weekday
weekofyear
year

Methods
-------
asfreq
strftime
to_timestamp
tz_convert
tz_localize

Examples
--------
>>> idx = PeriodIndex(year=year_arr, quarter=q_arr)
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class RangeIndex(Int64Index):
--------
Index : The base pandas Index type
Int64Index : Index of int64 data

Methods
-------
from_range
Copy link
Member

Choose a reason for hiding this comment

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

Is it because there is no Attributes section that you get those warnings?
(but you said they were fixed with numpydoc master? Then the other places that do an empty section with None are also not needed?)

"""

_typ = 'rangeindex'
Expand Down
18 changes: 18 additions & 0 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ class TimedeltaIndex(DatetimeIndexOpsMixin, TimelikeOps, Int64Index):
Timedelta : Represents a duration between two dates or times.
DatetimeIndex : Index of datetime64 data
PeriodIndex : Index of Period data

Attributes
----------
days
seconds
microseconds
nanoseconds
components
inferred_freq

Methods
-------
to_pytimedelta
to_series
round
floor
ceil
to_frame
"""

_typ = 'timedeltaindex'
Expand Down