|
14 | 14 | import os
|
15 | 15 | import re
|
16 | 16 | import inspect
|
| 17 | +import importlib |
17 | 18 | from pandas.compat import u, PY3
|
18 | 19 |
|
19 | 20 | # https://github.com/sphinx-doc/sphinx/pull/2325/files
|
|
226 | 227 | # Additional templates that should be rendered to pages, maps page names to
|
227 | 228 | # template names.
|
228 | 229 |
|
229 |
| -# Add redirect for previously existing API pages (which are now included in |
230 |
| -# the API pages as top-level functions) based on a template (GH9911) |
| 230 | +# Add redirect for previously existing API pages |
| 231 | +# each item is like `(from_old, to_new)` |
| 232 | +# To redirect a class and all its methods, see below |
| 233 | +# https://github.com/pandas-dev/pandas/issues/16186 |
| 234 | + |
231 | 235 | moved_api_pages = [
|
232 |
| - 'pandas.core.common.isnull', 'pandas.core.common.notnull', 'pandas.core.reshape.get_dummies', |
233 |
| - 'pandas.tools.merge.concat', 'pandas.tools.merge.merge', 'pandas.tools.pivot.pivot_table', |
234 |
| - 'pandas.tseries.tools.to_datetime', 'pandas.io.clipboard.read_clipboard', 'pandas.io.excel.ExcelFile.parse', |
235 |
| - 'pandas.io.excel.read_excel', 'pandas.io.html.read_html', 'pandas.io.json.read_json', |
236 |
| - 'pandas.io.parsers.read_csv', 'pandas.io.parsers.read_fwf', 'pandas.io.parsers.read_table', |
237 |
| - 'pandas.io.pickle.read_pickle', 'pandas.io.pytables.HDFStore.append', 'pandas.io.pytables.HDFStore.get', |
238 |
| - 'pandas.io.pytables.HDFStore.put', 'pandas.io.pytables.HDFStore.select', 'pandas.io.pytables.read_hdf', |
239 |
| - 'pandas.io.sql.read_sql', 'pandas.io.sql.read_frame', 'pandas.io.sql.write_frame', |
240 |
| - 'pandas.io.stata.read_stata'] |
241 |
| - |
242 |
| -html_additional_pages = {'generated/' + page: 'api_redirect.html' for page in moved_api_pages} |
| 236 | + ('pandas.core.common.isnull', 'pandas.isnull'), |
| 237 | + ('pandas.core.common.notnull', 'pandas.notnull'), |
| 238 | + ('pandas.core.reshape.get_dummies', 'pandas.get_dummies'), |
| 239 | + ('pandas.tools.merge.concat', 'pandas.concat'), |
| 240 | + ('pandas.tools.merge.merge', 'pandas.merge'), |
| 241 | + ('pandas.tools.pivot.pivot_table', 'pandas.pivot_table'), |
| 242 | + ('pandas.tseries.tools.to_datetime', 'pandas.to_datetime'), |
| 243 | + ('pandas.io.clipboard.read_clipboard', 'pandas.read_clipboard'), |
| 244 | + ('pandas.io.excel.ExcelFile.parse', 'pandas.ExcelFile.parse'), |
| 245 | + ('pandas.io.excel.read_excel', 'pandas.read_excel'), |
| 246 | + ('pandas.io.html.read_html', 'pandas.read_html'), |
| 247 | + ('pandas.io.json.read_json', 'pandas.read_json'), |
| 248 | + ('pandas.io.parsers.read_csv', 'pandas.read_csv'), |
| 249 | + ('pandas.io.parsers.read_fwf', 'pandas.read_fwf'), |
| 250 | + ('pandas.io.parsers.read_table', 'pandas.read_table'), |
| 251 | + ('pandas.io.pickle.read_pickle', 'pandas.read_pickle'), |
| 252 | + ('pandas.io.pytables.HDFStore.append', 'pandas.HDFStore.append'), |
| 253 | + ('pandas.io.pytables.HDFStore.get', 'pandas.HDFStore.get'), |
| 254 | + ('pandas.io.pytables.HDFStore.put', 'pandas.HDFStore.put'), |
| 255 | + ('pandas.io.pytables.HDFStore.select', 'pandas.HDFStore.select'), |
| 256 | + ('pandas.io.pytables.read_hdf', 'pandas.read_hdf'), |
| 257 | + ('pandas.io.sql.read_sql', 'pandas.read_sql'), |
| 258 | + ('pandas.io.sql.read_frame', 'pandas.read_frame'), |
| 259 | + ('pandas.io.sql.write_frame', 'pandas.write_frame'), |
| 260 | + ('pandas.io.stata.read_stata', 'pandas.read_stata'), |
| 261 | +] |
| 262 | + |
| 263 | +# Again, tuples of (from_old, to_new) |
| 264 | +moved_classes = [ |
| 265 | + ('pandas.tseries.resample.Resampler', 'pandas.core.resample.Resampler'), |
| 266 | + ('pandas.formats.style.Styler', 'pandas.io.formats.style.Styler'), |
| 267 | +] |
| 268 | + |
| 269 | +for old, new in moved_classes: |
| 270 | + # the class itself... |
| 271 | + moved_api_pages.append((old, new)) |
| 272 | + |
| 273 | + mod, classname = new.rsplit('.', 1) |
| 274 | + klass = getattr(importlib.import_module(mod), classname) |
| 275 | + methods = [x for x in dir(klass) |
| 276 | + if not x.startswith('_') or x in ('__iter__', '__array__')] |
| 277 | + |
| 278 | + for method in methods: |
| 279 | + # ... and each of its public methods |
| 280 | + moved_api_pages.append( |
| 281 | + ("{old}.{method}".format(old=old, method=method), |
| 282 | + "{new}.{method}".format(new=new, method=method)) |
| 283 | + ) |
| 284 | + |
| 285 | +html_additional_pages = { |
| 286 | + 'generated/' + page[0]: 'api_redirect.html' |
| 287 | + for page in moved_api_pages |
| 288 | +} |
| 289 | + |
| 290 | +html_context = { |
| 291 | + 'redirects': {old: new for old, new in moved_api_pages} |
| 292 | +} |
243 | 293 |
|
244 | 294 | # If false, no module index is generated.
|
245 | 295 | html_use_modindex = True
|
|
0 commit comments