doc.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. """Any shareable docstring components for rolling/expanding/ewm"""
  2. from __future__ import annotations
  3. from textwrap import dedent
  4. from pandas.core.shared_docs import _shared_docs
  5. _shared_docs = dict(**_shared_docs)
  6. def create_section_header(header: str) -> str:
  7. """Create numpydoc section header"""
  8. return f"{header}\n{'-' * len(header)}\n"
  9. template_header = "\nCalculate the {window_method} {aggregation_description}.\n\n"
  10. template_returns = dedent(
  11. """
  12. Series or DataFrame
  13. Return type is the same as the original object with ``np.float64`` dtype.\n
  14. """
  15. ).replace("\n", "", 1)
  16. template_see_also = dedent(
  17. """
  18. pandas.Series.{window_method} : Calling {window_method} with Series data.
  19. pandas.DataFrame.{window_method} : Calling {window_method} with DataFrames.
  20. pandas.Series.{agg_method} : Aggregating {agg_method} for Series.
  21. pandas.DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n
  22. """
  23. ).replace("\n", "", 1)
  24. kwargs_numeric_only = dedent(
  25. """
  26. numeric_only : bool, default False
  27. Include only float, int, boolean columns.
  28. .. versionadded:: 1.5.0\n
  29. """
  30. ).replace("\n", "", 1)
  31. kwargs_scipy = dedent(
  32. """
  33. **kwargs
  34. Keyword arguments to configure the ``SciPy`` weighted window type.\n
  35. """
  36. ).replace("\n", "", 1)
  37. window_apply_parameters = dedent(
  38. """
  39. func : function
  40. Must produce a single value from an ndarray input if ``raw=True``
  41. or a single value from a Series if ``raw=False``. Can also accept a
  42. Numba JIT function with ``engine='numba'`` specified.
  43. raw : bool, default False
  44. * ``False`` : passes each row or column as a Series to the
  45. function.
  46. * ``True`` : the passed function will receive ndarray
  47. objects instead.
  48. If you are just applying a NumPy reduction function this will
  49. achieve much better performance.
  50. engine : str, default None
  51. * ``'cython'`` : Runs rolling apply through C-extensions from cython.
  52. * ``'numba'`` : Runs rolling apply through JIT compiled code from numba.
  53. Only available when ``raw`` is set to ``True``.
  54. * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
  55. engine_kwargs : dict, default None
  56. * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
  57. * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
  58. and ``parallel`` dictionary keys. The values must either be ``True`` or
  59. ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
  60. ``{{'nopython': True, 'nogil': False, 'parallel': False}}`` and will be
  61. applied to both the ``func`` and the ``apply`` rolling aggregation.
  62. args : tuple, default None
  63. Positional arguments to be passed into func.
  64. kwargs : dict, default None
  65. Keyword arguments to be passed into func.\n
  66. """
  67. ).replace("\n", "", 1)
  68. numba_notes = (
  69. "See :ref:`window.numba_engine` and :ref:`enhancingperf.numba` for "
  70. "extended documentation and performance considerations for the Numba engine.\n\n"
  71. )
  72. def window_agg_numba_parameters(version: str = "1.3") -> str:
  73. return (
  74. dedent(
  75. """
  76. engine : str, default None
  77. * ``'cython'`` : Runs the operation through C-extensions from cython.
  78. * ``'numba'`` : Runs the operation through JIT compiled code from numba.
  79. * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
  80. .. versionadded:: {version}.0
  81. engine_kwargs : dict, default None
  82. * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
  83. * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
  84. and ``parallel`` dictionary keys. The values must either be ``True`` or
  85. ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
  86. ``{{'nopython': True, 'nogil': False, 'parallel': False}}``
  87. .. versionadded:: {version}.0\n
  88. """
  89. )
  90. .replace("\n", "", 1)
  91. .replace("{version}", version)
  92. )