Skip to content

DOC: Add redirect for moved classes #16200

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

Merged
merged 2 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 4 additions & 9 deletions doc/_templates/api_redirect.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{% set pgn = pagename.split('.') -%}
{% if pgn[-2][0].isupper() -%}
{% set redirect = ["pandas", pgn[-2], pgn[-1], 'html']|join('.') -%}
{% else -%}
{% set redirect = ["pandas", pgn[-1], 'html']|join('.') -%}
{% endif -%}
{% set redirect = redirects[pagename.split("/")[-1]] %}
<html>
<head>
<meta http-equiv="Refresh" content="0; url={{ redirect }}" />
<meta http-equiv="Refresh" content="0; url={{ redirect }}.html" />
<title>This API page has moved</title>
</head>
<body>
<p>This API page has moved <a href="{{ redirect }}">here</a>.</p>
<p>This API page has moved <a href="{{ redirect }}.html">here</a>.</p>
</body>
</html>
</html>
76 changes: 63 additions & 13 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import re
import inspect
import importlib
from pandas.compat import u, PY3

# https://github.com/sphinx-doc/sphinx/pull/2325/files
Expand Down Expand Up @@ -226,20 +227,69 @@
# Additional templates that should be rendered to pages, maps page names to
# template names.

# Add redirect for previously existing API pages (which are now included in
# the API pages as top-level functions) based on a template (GH9911)
# Add redirect for previously existing API pages
# each item is like `(from_old, to_new)`
# To redirect a class and all its methods, see below
# https://github.com/pandas-dev/pandas/issues/16186

moved_api_pages = [
'pandas.core.common.isnull', 'pandas.core.common.notnull', 'pandas.core.reshape.get_dummies',
'pandas.tools.merge.concat', 'pandas.tools.merge.merge', 'pandas.tools.pivot.pivot_table',
'pandas.tseries.tools.to_datetime', 'pandas.io.clipboard.read_clipboard', 'pandas.io.excel.ExcelFile.parse',
'pandas.io.excel.read_excel', 'pandas.io.html.read_html', 'pandas.io.json.read_json',
'pandas.io.parsers.read_csv', 'pandas.io.parsers.read_fwf', 'pandas.io.parsers.read_table',
'pandas.io.pickle.read_pickle', 'pandas.io.pytables.HDFStore.append', 'pandas.io.pytables.HDFStore.get',
'pandas.io.pytables.HDFStore.put', 'pandas.io.pytables.HDFStore.select', 'pandas.io.pytables.read_hdf',
'pandas.io.sql.read_sql', 'pandas.io.sql.read_frame', 'pandas.io.sql.write_frame',
'pandas.io.stata.read_stata']

html_additional_pages = {'generated/' + page: 'api_redirect.html' for page in moved_api_pages}
('pandas.core.common.isnull', 'pandas.isnull'),
('pandas.core.common.notnull', 'pandas.notnull'),
('pandas.core.reshape.get_dummies', 'pandas.get_dummies'),
('pandas.tools.merge.concat', 'pandas.concat'),
('pandas.tools.merge.merge', 'pandas.merge'),
('pandas.tools.pivot.pivot_table', 'pandas.pivot_table'),
('pandas.tseries.tools.to_datetime', 'pandas.to_datetime'),
('pandas.io.clipboard.read_clipboard', 'pandas.read_clipboard'),
('pandas.io.excel.ExcelFile.parse', 'pandas.ExcelFile.parse'),
('pandas.io.excel.read_excel', 'pandas.read_excel'),
('pandas.io.html.read_html', 'pandas.read_html'),
('pandas.io.json.read_json', 'pandas.read_json'),
('pandas.io.parsers.read_csv', 'pandas.read_csv'),
('pandas.io.parsers.read_fwf', 'pandas.read_fwf'),
('pandas.io.parsers.read_table', 'pandas.read_table'),
('pandas.io.pickle.read_pickle', 'pandas.read_pickle'),
('pandas.io.pytables.HDFStore.append', 'pandas.HDFStore.append'),
('pandas.io.pytables.HDFStore.get', 'pandas.HDFStore.get'),
('pandas.io.pytables.HDFStore.put', 'pandas.HDFStore.put'),
('pandas.io.pytables.HDFStore.select', 'pandas.HDFStore.select'),
('pandas.io.pytables.read_hdf', 'pandas.read_hdf'),
('pandas.io.sql.read_sql', 'pandas.read_sql'),
('pandas.io.sql.read_frame', 'pandas.read_frame'),
('pandas.io.sql.write_frame', 'pandas.write_frame'),
('pandas.io.stata.read_stata', 'pandas.read_stata'),
]

# Again, tuples of (from_old, to_new)
moved_classes = [
('pandas.tseries.resample.Resampler', 'pandas.core.resample.Resampler'),
('pandas.formats.style.Styler', 'pandas.io.formats.style.Styler'),
]

for old, new in moved_classes:
# the class itself...
moved_api_pages.append((old, new))

mod, classname = new.rsplit('.', 1)
klass = getattr(importlib.import_module(mod), classname)
methods = [x for x in dir(klass)
if not x.startswith('_') or x in ('__iter__', '__array__')]

for method in methods:
# ... and each of its public methods
moved_api_pages.append(
("{old}.{method}".format(old=old, method=method),
"{new}.{method}".format(new=new, method=method))
)

html_additional_pages = {
'generated/' + page[0]: 'api_redirect.html'
for page in moved_api_pages
}

html_context = {
'redirects': {old: new for old, new in moved_api_pages}
}

# If false, no module index is generated.
html_use_modindex = True
Expand Down