Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/_constants.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/_optional.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/compressors.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/pickle_compat.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/pyarrow.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/numpy/__init__.py +53 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/numpy/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/numpy/__pycache__/function.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/compat/numpy/function.py +418 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/accessor.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/algorithms.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/api.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/apply.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/arraylike.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/base.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/common.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/config_init.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/construction.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/flags.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/missing.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/nanops.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/roperator.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/sample.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/shared_docs.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/sorting.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/__init__.py +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/__pycache__/executor.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/__pycache__/extensions.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/executor.py +239 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/extensions.py +585 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__init__.py +27 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/mean_.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/min_max_.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/shared.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/sum_.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/var_.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/mean_.py +196 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/min_max_.py +125 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/shared.py +29 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/sum_.py +244 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/var_.py +245 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__init__.py +9 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__pycache__/datetimelike_accumulations.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__pycache__/masked_accumulations.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__pycache__/masked_reductions.cpython-312.pyc +0 -0
.venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (6.01 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/_constants.cpython-312.pyc
ADDED
|
Binary file (1.11 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/_optional.cpython-312.pyc
ADDED
|
Binary file (5.47 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/compressors.cpython-312.pyc
ADDED
|
Binary file (2.33 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/pickle_compat.cpython-312.pyc
ADDED
|
Binary file (8.35 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/__pycache__/pyarrow.cpython-312.pyc
ADDED
|
Binary file (1.64 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/numpy/__init__.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" support numpy compatibility across versions """
|
| 2 |
+
import warnings
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
from pandas.util.version import Version
|
| 7 |
+
|
| 8 |
+
# numpy versioning
|
| 9 |
+
_np_version = np.__version__
|
| 10 |
+
_nlv = Version(_np_version)
|
| 11 |
+
np_version_lt1p23 = _nlv < Version("1.23")
|
| 12 |
+
np_version_gte1p24 = _nlv >= Version("1.24")
|
| 13 |
+
np_version_gte1p24p3 = _nlv >= Version("1.24.3")
|
| 14 |
+
np_version_gte1p25 = _nlv >= Version("1.25")
|
| 15 |
+
np_version_gt2 = _nlv >= Version("2.0.0")
|
| 16 |
+
is_numpy_dev = _nlv.dev is not None
|
| 17 |
+
_min_numpy_ver = "1.22.4"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
if _nlv < Version(_min_numpy_ver):
|
| 21 |
+
raise ImportError(
|
| 22 |
+
f"this version of pandas is incompatible with numpy < {_min_numpy_ver}\n"
|
| 23 |
+
f"your numpy version is {_np_version}.\n"
|
| 24 |
+
f"Please upgrade numpy to >= {_min_numpy_ver} to use this pandas version"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
np_long: type
|
| 29 |
+
np_ulong: type
|
| 30 |
+
|
| 31 |
+
if np_version_gt2:
|
| 32 |
+
try:
|
| 33 |
+
with warnings.catch_warnings():
|
| 34 |
+
warnings.filterwarnings(
|
| 35 |
+
"ignore",
|
| 36 |
+
r".*In the future `np\.long` will be defined as.*",
|
| 37 |
+
FutureWarning,
|
| 38 |
+
)
|
| 39 |
+
np_long = np.long # type: ignore[attr-defined]
|
| 40 |
+
np_ulong = np.ulong # type: ignore[attr-defined]
|
| 41 |
+
except AttributeError:
|
| 42 |
+
np_long = np.int_
|
| 43 |
+
np_ulong = np.uint
|
| 44 |
+
else:
|
| 45 |
+
np_long = np.int_
|
| 46 |
+
np_ulong = np.uint
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
__all__ = [
|
| 50 |
+
"np",
|
| 51 |
+
"_np_version",
|
| 52 |
+
"is_numpy_dev",
|
| 53 |
+
]
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/numpy/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (1.9 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/numpy/__pycache__/function.cpython-312.pyc
ADDED
|
Binary file (13.2 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/compat/numpy/function.py
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
For compatibility with numpy libraries, pandas functions or methods have to
|
| 3 |
+
accept '*args' and '**kwargs' parameters to accommodate numpy arguments that
|
| 4 |
+
are not actually used or respected in the pandas implementation.
|
| 5 |
+
|
| 6 |
+
To ensure that users do not abuse these parameters, validation is performed in
|
| 7 |
+
'validators.py' to make sure that any extra parameters passed correspond ONLY
|
| 8 |
+
to those in the numpy signature. Part of that validation includes whether or
|
| 9 |
+
not the user attempted to pass in non-default values for these extraneous
|
| 10 |
+
parameters. As we want to discourage users from relying on these parameters
|
| 11 |
+
when calling the pandas implementation, we want them only to pass in the
|
| 12 |
+
default values for these parameters.
|
| 13 |
+
|
| 14 |
+
This module provides a set of commonly used default arguments for functions and
|
| 15 |
+
methods that are spread throughout the codebase. This module will make it
|
| 16 |
+
easier to adjust to future upstream changes in the analogous numpy signatures.
|
| 17 |
+
"""
|
| 18 |
+
from __future__ import annotations
|
| 19 |
+
|
| 20 |
+
from typing import (
|
| 21 |
+
TYPE_CHECKING,
|
| 22 |
+
Any,
|
| 23 |
+
TypeVar,
|
| 24 |
+
cast,
|
| 25 |
+
overload,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
import numpy as np
|
| 29 |
+
from numpy import ndarray
|
| 30 |
+
|
| 31 |
+
from pandas._libs.lib import (
|
| 32 |
+
is_bool,
|
| 33 |
+
is_integer,
|
| 34 |
+
)
|
| 35 |
+
from pandas.errors import UnsupportedFunctionCall
|
| 36 |
+
from pandas.util._validators import (
|
| 37 |
+
validate_args,
|
| 38 |
+
validate_args_and_kwargs,
|
| 39 |
+
validate_kwargs,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
if TYPE_CHECKING:
|
| 43 |
+
from pandas._typing import (
|
| 44 |
+
Axis,
|
| 45 |
+
AxisInt,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
AxisNoneT = TypeVar("AxisNoneT", Axis, None)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class CompatValidator:
|
| 52 |
+
def __init__(
|
| 53 |
+
self,
|
| 54 |
+
defaults,
|
| 55 |
+
fname=None,
|
| 56 |
+
method: str | None = None,
|
| 57 |
+
max_fname_arg_count=None,
|
| 58 |
+
) -> None:
|
| 59 |
+
self.fname = fname
|
| 60 |
+
self.method = method
|
| 61 |
+
self.defaults = defaults
|
| 62 |
+
self.max_fname_arg_count = max_fname_arg_count
|
| 63 |
+
|
| 64 |
+
def __call__(
|
| 65 |
+
self,
|
| 66 |
+
args,
|
| 67 |
+
kwargs,
|
| 68 |
+
fname=None,
|
| 69 |
+
max_fname_arg_count=None,
|
| 70 |
+
method: str | None = None,
|
| 71 |
+
) -> None:
|
| 72 |
+
if not args and not kwargs:
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
fname = self.fname if fname is None else fname
|
| 76 |
+
max_fname_arg_count = (
|
| 77 |
+
self.max_fname_arg_count
|
| 78 |
+
if max_fname_arg_count is None
|
| 79 |
+
else max_fname_arg_count
|
| 80 |
+
)
|
| 81 |
+
method = self.method if method is None else method
|
| 82 |
+
|
| 83 |
+
if method == "args":
|
| 84 |
+
validate_args(fname, args, max_fname_arg_count, self.defaults)
|
| 85 |
+
elif method == "kwargs":
|
| 86 |
+
validate_kwargs(fname, kwargs, self.defaults)
|
| 87 |
+
elif method == "both":
|
| 88 |
+
validate_args_and_kwargs(
|
| 89 |
+
fname, args, kwargs, max_fname_arg_count, self.defaults
|
| 90 |
+
)
|
| 91 |
+
else:
|
| 92 |
+
raise ValueError(f"invalid validation method '{method}'")
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
ARGMINMAX_DEFAULTS = {"out": None}
|
| 96 |
+
validate_argmin = CompatValidator(
|
| 97 |
+
ARGMINMAX_DEFAULTS, fname="argmin", method="both", max_fname_arg_count=1
|
| 98 |
+
)
|
| 99 |
+
validate_argmax = CompatValidator(
|
| 100 |
+
ARGMINMAX_DEFAULTS, fname="argmax", method="both", max_fname_arg_count=1
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def process_skipna(skipna: bool | ndarray | None, args) -> tuple[bool, Any]:
|
| 105 |
+
if isinstance(skipna, ndarray) or skipna is None:
|
| 106 |
+
args = (skipna,) + args
|
| 107 |
+
skipna = True
|
| 108 |
+
|
| 109 |
+
return skipna, args
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def validate_argmin_with_skipna(skipna: bool | ndarray | None, args, kwargs) -> bool:
|
| 113 |
+
"""
|
| 114 |
+
If 'Series.argmin' is called via the 'numpy' library, the third parameter
|
| 115 |
+
in its signature is 'out', which takes either an ndarray or 'None', so
|
| 116 |
+
check if the 'skipna' parameter is either an instance of ndarray or is
|
| 117 |
+
None, since 'skipna' itself should be a boolean
|
| 118 |
+
"""
|
| 119 |
+
skipna, args = process_skipna(skipna, args)
|
| 120 |
+
validate_argmin(args, kwargs)
|
| 121 |
+
return skipna
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def validate_argmax_with_skipna(skipna: bool | ndarray | None, args, kwargs) -> bool:
|
| 125 |
+
"""
|
| 126 |
+
If 'Series.argmax' is called via the 'numpy' library, the third parameter
|
| 127 |
+
in its signature is 'out', which takes either an ndarray or 'None', so
|
| 128 |
+
check if the 'skipna' parameter is either an instance of ndarray or is
|
| 129 |
+
None, since 'skipna' itself should be a boolean
|
| 130 |
+
"""
|
| 131 |
+
skipna, args = process_skipna(skipna, args)
|
| 132 |
+
validate_argmax(args, kwargs)
|
| 133 |
+
return skipna
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
ARGSORT_DEFAULTS: dict[str, int | str | None] = {}
|
| 137 |
+
ARGSORT_DEFAULTS["axis"] = -1
|
| 138 |
+
ARGSORT_DEFAULTS["kind"] = "quicksort"
|
| 139 |
+
ARGSORT_DEFAULTS["order"] = None
|
| 140 |
+
ARGSORT_DEFAULTS["kind"] = None
|
| 141 |
+
ARGSORT_DEFAULTS["stable"] = None
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
validate_argsort = CompatValidator(
|
| 145 |
+
ARGSORT_DEFAULTS, fname="argsort", max_fname_arg_count=0, method="both"
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
# two different signatures of argsort, this second validation for when the
|
| 149 |
+
# `kind` param is supported
|
| 150 |
+
ARGSORT_DEFAULTS_KIND: dict[str, int | None] = {}
|
| 151 |
+
ARGSORT_DEFAULTS_KIND["axis"] = -1
|
| 152 |
+
ARGSORT_DEFAULTS_KIND["order"] = None
|
| 153 |
+
ARGSORT_DEFAULTS_KIND["stable"] = None
|
| 154 |
+
validate_argsort_kind = CompatValidator(
|
| 155 |
+
ARGSORT_DEFAULTS_KIND, fname="argsort", max_fname_arg_count=0, method="both"
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def validate_argsort_with_ascending(ascending: bool | int | None, args, kwargs) -> bool:
|
| 160 |
+
"""
|
| 161 |
+
If 'Categorical.argsort' is called via the 'numpy' library, the first
|
| 162 |
+
parameter in its signature is 'axis', which takes either an integer or
|
| 163 |
+
'None', so check if the 'ascending' parameter has either integer type or is
|
| 164 |
+
None, since 'ascending' itself should be a boolean
|
| 165 |
+
"""
|
| 166 |
+
if is_integer(ascending) or ascending is None:
|
| 167 |
+
args = (ascending,) + args
|
| 168 |
+
ascending = True
|
| 169 |
+
|
| 170 |
+
validate_argsort_kind(args, kwargs, max_fname_arg_count=3)
|
| 171 |
+
ascending = cast(bool, ascending)
|
| 172 |
+
return ascending
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
CLIP_DEFAULTS: dict[str, Any] = {"out": None}
|
| 176 |
+
validate_clip = CompatValidator(
|
| 177 |
+
CLIP_DEFAULTS, fname="clip", method="both", max_fname_arg_count=3
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
@overload
|
| 182 |
+
def validate_clip_with_axis(axis: ndarray, args, kwargs) -> None:
|
| 183 |
+
...
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
@overload
|
| 187 |
+
def validate_clip_with_axis(axis: AxisNoneT, args, kwargs) -> AxisNoneT:
|
| 188 |
+
...
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def validate_clip_with_axis(
|
| 192 |
+
axis: ndarray | AxisNoneT, args, kwargs
|
| 193 |
+
) -> AxisNoneT | None:
|
| 194 |
+
"""
|
| 195 |
+
If 'NDFrame.clip' is called via the numpy library, the third parameter in
|
| 196 |
+
its signature is 'out', which can takes an ndarray, so check if the 'axis'
|
| 197 |
+
parameter is an instance of ndarray, since 'axis' itself should either be
|
| 198 |
+
an integer or None
|
| 199 |
+
"""
|
| 200 |
+
if isinstance(axis, ndarray):
|
| 201 |
+
args = (axis,) + args
|
| 202 |
+
# error: Incompatible types in assignment (expression has type "None",
|
| 203 |
+
# variable has type "Union[ndarray[Any, Any], str, int]")
|
| 204 |
+
axis = None # type: ignore[assignment]
|
| 205 |
+
|
| 206 |
+
validate_clip(args, kwargs)
|
| 207 |
+
# error: Incompatible return value type (got "Union[ndarray[Any, Any],
|
| 208 |
+
# str, int]", expected "Union[str, int, None]")
|
| 209 |
+
return axis # type: ignore[return-value]
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
CUM_FUNC_DEFAULTS: dict[str, Any] = {}
|
| 213 |
+
CUM_FUNC_DEFAULTS["dtype"] = None
|
| 214 |
+
CUM_FUNC_DEFAULTS["out"] = None
|
| 215 |
+
validate_cum_func = CompatValidator(
|
| 216 |
+
CUM_FUNC_DEFAULTS, method="both", max_fname_arg_count=1
|
| 217 |
+
)
|
| 218 |
+
validate_cumsum = CompatValidator(
|
| 219 |
+
CUM_FUNC_DEFAULTS, fname="cumsum", method="both", max_fname_arg_count=1
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def validate_cum_func_with_skipna(skipna: bool, args, kwargs, name) -> bool:
|
| 224 |
+
"""
|
| 225 |
+
If this function is called via the 'numpy' library, the third parameter in
|
| 226 |
+
its signature is 'dtype', which takes either a 'numpy' dtype or 'None', so
|
| 227 |
+
check if the 'skipna' parameter is a boolean or not
|
| 228 |
+
"""
|
| 229 |
+
if not is_bool(skipna):
|
| 230 |
+
args = (skipna,) + args
|
| 231 |
+
skipna = True
|
| 232 |
+
elif isinstance(skipna, np.bool_):
|
| 233 |
+
skipna = bool(skipna)
|
| 234 |
+
|
| 235 |
+
validate_cum_func(args, kwargs, fname=name)
|
| 236 |
+
return skipna
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
ALLANY_DEFAULTS: dict[str, bool | None] = {}
|
| 240 |
+
ALLANY_DEFAULTS["dtype"] = None
|
| 241 |
+
ALLANY_DEFAULTS["out"] = None
|
| 242 |
+
ALLANY_DEFAULTS["keepdims"] = False
|
| 243 |
+
ALLANY_DEFAULTS["axis"] = None
|
| 244 |
+
validate_all = CompatValidator(
|
| 245 |
+
ALLANY_DEFAULTS, fname="all", method="both", max_fname_arg_count=1
|
| 246 |
+
)
|
| 247 |
+
validate_any = CompatValidator(
|
| 248 |
+
ALLANY_DEFAULTS, fname="any", method="both", max_fname_arg_count=1
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
LOGICAL_FUNC_DEFAULTS = {"out": None, "keepdims": False}
|
| 252 |
+
validate_logical_func = CompatValidator(LOGICAL_FUNC_DEFAULTS, method="kwargs")
|
| 253 |
+
|
| 254 |
+
MINMAX_DEFAULTS = {"axis": None, "dtype": None, "out": None, "keepdims": False}
|
| 255 |
+
validate_min = CompatValidator(
|
| 256 |
+
MINMAX_DEFAULTS, fname="min", method="both", max_fname_arg_count=1
|
| 257 |
+
)
|
| 258 |
+
validate_max = CompatValidator(
|
| 259 |
+
MINMAX_DEFAULTS, fname="max", method="both", max_fname_arg_count=1
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
RESHAPE_DEFAULTS: dict[str, str] = {"order": "C"}
|
| 263 |
+
validate_reshape = CompatValidator(
|
| 264 |
+
RESHAPE_DEFAULTS, fname="reshape", method="both", max_fname_arg_count=1
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
REPEAT_DEFAULTS: dict[str, Any] = {"axis": None}
|
| 268 |
+
validate_repeat = CompatValidator(
|
| 269 |
+
REPEAT_DEFAULTS, fname="repeat", method="both", max_fname_arg_count=1
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
ROUND_DEFAULTS: dict[str, Any] = {"out": None}
|
| 273 |
+
validate_round = CompatValidator(
|
| 274 |
+
ROUND_DEFAULTS, fname="round", method="both", max_fname_arg_count=1
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
SORT_DEFAULTS: dict[str, int | str | None] = {}
|
| 278 |
+
SORT_DEFAULTS["axis"] = -1
|
| 279 |
+
SORT_DEFAULTS["kind"] = "quicksort"
|
| 280 |
+
SORT_DEFAULTS["order"] = None
|
| 281 |
+
validate_sort = CompatValidator(SORT_DEFAULTS, fname="sort", method="kwargs")
|
| 282 |
+
|
| 283 |
+
STAT_FUNC_DEFAULTS: dict[str, Any | None] = {}
|
| 284 |
+
STAT_FUNC_DEFAULTS["dtype"] = None
|
| 285 |
+
STAT_FUNC_DEFAULTS["out"] = None
|
| 286 |
+
|
| 287 |
+
SUM_DEFAULTS = STAT_FUNC_DEFAULTS.copy()
|
| 288 |
+
SUM_DEFAULTS["axis"] = None
|
| 289 |
+
SUM_DEFAULTS["keepdims"] = False
|
| 290 |
+
SUM_DEFAULTS["initial"] = None
|
| 291 |
+
|
| 292 |
+
PROD_DEFAULTS = SUM_DEFAULTS.copy()
|
| 293 |
+
|
| 294 |
+
MEAN_DEFAULTS = SUM_DEFAULTS.copy()
|
| 295 |
+
|
| 296 |
+
MEDIAN_DEFAULTS = STAT_FUNC_DEFAULTS.copy()
|
| 297 |
+
MEDIAN_DEFAULTS["overwrite_input"] = False
|
| 298 |
+
MEDIAN_DEFAULTS["keepdims"] = False
|
| 299 |
+
|
| 300 |
+
STAT_FUNC_DEFAULTS["keepdims"] = False
|
| 301 |
+
|
| 302 |
+
validate_stat_func = CompatValidator(STAT_FUNC_DEFAULTS, method="kwargs")
|
| 303 |
+
validate_sum = CompatValidator(
|
| 304 |
+
SUM_DEFAULTS, fname="sum", method="both", max_fname_arg_count=1
|
| 305 |
+
)
|
| 306 |
+
validate_prod = CompatValidator(
|
| 307 |
+
PROD_DEFAULTS, fname="prod", method="both", max_fname_arg_count=1
|
| 308 |
+
)
|
| 309 |
+
validate_mean = CompatValidator(
|
| 310 |
+
MEAN_DEFAULTS, fname="mean", method="both", max_fname_arg_count=1
|
| 311 |
+
)
|
| 312 |
+
validate_median = CompatValidator(
|
| 313 |
+
MEDIAN_DEFAULTS, fname="median", method="both", max_fname_arg_count=1
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
+
STAT_DDOF_FUNC_DEFAULTS: dict[str, bool | None] = {}
|
| 317 |
+
STAT_DDOF_FUNC_DEFAULTS["dtype"] = None
|
| 318 |
+
STAT_DDOF_FUNC_DEFAULTS["out"] = None
|
| 319 |
+
STAT_DDOF_FUNC_DEFAULTS["keepdims"] = False
|
| 320 |
+
validate_stat_ddof_func = CompatValidator(STAT_DDOF_FUNC_DEFAULTS, method="kwargs")
|
| 321 |
+
|
| 322 |
+
TAKE_DEFAULTS: dict[str, str | None] = {}
|
| 323 |
+
TAKE_DEFAULTS["out"] = None
|
| 324 |
+
TAKE_DEFAULTS["mode"] = "raise"
|
| 325 |
+
validate_take = CompatValidator(TAKE_DEFAULTS, fname="take", method="kwargs")
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def validate_take_with_convert(convert: ndarray | bool | None, args, kwargs) -> bool:
|
| 329 |
+
"""
|
| 330 |
+
If this function is called via the 'numpy' library, the third parameter in
|
| 331 |
+
its signature is 'axis', which takes either an ndarray or 'None', so check
|
| 332 |
+
if the 'convert' parameter is either an instance of ndarray or is None
|
| 333 |
+
"""
|
| 334 |
+
if isinstance(convert, ndarray) or convert is None:
|
| 335 |
+
args = (convert,) + args
|
| 336 |
+
convert = True
|
| 337 |
+
|
| 338 |
+
validate_take(args, kwargs, max_fname_arg_count=3, method="both")
|
| 339 |
+
return convert
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
TRANSPOSE_DEFAULTS = {"axes": None}
|
| 343 |
+
validate_transpose = CompatValidator(
|
| 344 |
+
TRANSPOSE_DEFAULTS, fname="transpose", method="both", max_fname_arg_count=0
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def validate_groupby_func(name: str, args, kwargs, allowed=None) -> None:
|
| 349 |
+
"""
|
| 350 |
+
'args' and 'kwargs' should be empty, except for allowed kwargs because all
|
| 351 |
+
of their necessary parameters are explicitly listed in the function
|
| 352 |
+
signature
|
| 353 |
+
"""
|
| 354 |
+
if allowed is None:
|
| 355 |
+
allowed = []
|
| 356 |
+
|
| 357 |
+
kwargs = set(kwargs) - set(allowed)
|
| 358 |
+
|
| 359 |
+
if len(args) + len(kwargs) > 0:
|
| 360 |
+
raise UnsupportedFunctionCall(
|
| 361 |
+
"numpy operations are not valid with groupby. "
|
| 362 |
+
f"Use .groupby(...).{name}() instead"
|
| 363 |
+
)
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
RESAMPLER_NUMPY_OPS = ("min", "max", "sum", "prod", "mean", "std", "var")
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def validate_resampler_func(method: str, args, kwargs) -> None:
|
| 370 |
+
"""
|
| 371 |
+
'args' and 'kwargs' should be empty because all of their necessary
|
| 372 |
+
parameters are explicitly listed in the function signature
|
| 373 |
+
"""
|
| 374 |
+
if len(args) + len(kwargs) > 0:
|
| 375 |
+
if method in RESAMPLER_NUMPY_OPS:
|
| 376 |
+
raise UnsupportedFunctionCall(
|
| 377 |
+
"numpy operations are not valid with resample. "
|
| 378 |
+
f"Use .resample(...).{method}() instead"
|
| 379 |
+
)
|
| 380 |
+
raise TypeError("too many arguments passed in")
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def validate_minmax_axis(axis: AxisInt | None, ndim: int = 1) -> None:
|
| 384 |
+
"""
|
| 385 |
+
Ensure that the axis argument passed to min, max, argmin, or argmax is zero
|
| 386 |
+
or None, as otherwise it will be incorrectly ignored.
|
| 387 |
+
|
| 388 |
+
Parameters
|
| 389 |
+
----------
|
| 390 |
+
axis : int or None
|
| 391 |
+
ndim : int, default 1
|
| 392 |
+
|
| 393 |
+
Raises
|
| 394 |
+
------
|
| 395 |
+
ValueError
|
| 396 |
+
"""
|
| 397 |
+
if axis is None:
|
| 398 |
+
return
|
| 399 |
+
if axis >= ndim or (axis < 0 and ndim + axis < 0):
|
| 400 |
+
raise ValueError(f"`axis` must be fewer than the number of dimensions ({ndim})")
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
_validation_funcs = {
|
| 404 |
+
"median": validate_median,
|
| 405 |
+
"mean": validate_mean,
|
| 406 |
+
"min": validate_min,
|
| 407 |
+
"max": validate_max,
|
| 408 |
+
"sum": validate_sum,
|
| 409 |
+
"prod": validate_prod,
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def validate_func(fname, args, kwargs) -> None:
|
| 414 |
+
if fname not in _validation_funcs:
|
| 415 |
+
return validate_stat_func(args, kwargs, fname=fname)
|
| 416 |
+
|
| 417 |
+
validation_func = _validation_funcs[fname]
|
| 418 |
+
return validation_func(args, kwargs)
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (203 Bytes). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/accessor.cpython-312.pyc
ADDED
|
Binary file (13.1 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/algorithms.cpython-312.pyc
ADDED
|
Binary file (55.6 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/api.cpython-312.pyc
ADDED
|
Binary file (2.75 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/apply.cpython-312.pyc
ADDED
|
Binary file (75.8 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/arraylike.cpython-312.pyc
ADDED
|
Binary file (21.2 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/base.cpython-312.pyc
ADDED
|
Binary file (47.3 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/common.cpython-312.pyc
ADDED
|
Binary file (23 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/config_init.cpython-312.pyc
ADDED
|
Binary file (28.5 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/construction.cpython-312.pyc
ADDED
|
Binary file (27.3 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/flags.cpython-312.pyc
ADDED
|
Binary file (5.07 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/missing.cpython-312.pyc
ADDED
|
Binary file (36.4 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/nanops.cpython-312.pyc
ADDED
|
Binary file (58.3 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/roperator.cpython-312.pyc
ADDED
|
Binary file (2.21 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/sample.cpython-312.pyc
ADDED
|
Binary file (5.2 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/shared_docs.cpython-312.pyc
ADDED
|
Binary file (30.4 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/__pycache__/sorting.cpython-312.pyc
ADDED
|
Binary file (27 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/__init__.py
ADDED
|
File without changes
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (210 Bytes). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/__pycache__/executor.cpython-312.pyc
ADDED
|
Binary file (9.79 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/__pycache__/extensions.cpython-312.pyc
ADDED
|
Binary file (28.6 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/executor.py
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ar
|
| 12 |
+
|
| 13 |
+
import numpy as np
|
| 14 |
+
|
| 15 |
+
from pandas.compat._optional import import_optional_dependency
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@functools.cache
|
| 19 |
+
def generate_apply_looper(func, nopython=True, nogil=True, parallel=False):
|
| 20 |
+
if TYPE_CHECKING:
|
| 21 |
+
import numba
|
| 22 |
+
else:
|
| 23 |
+
numba = import_optional_dependency("numba")
|
| 24 |
+
nb_compat_func = numba.extending.register_jitable(func)
|
| 25 |
+
|
| 26 |
+
@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel)
|
| 27 |
+
def nb_looper(values, axis):
|
| 28 |
+
# Operate on the first row/col in order to get
|
| 29 |
+
# the output shape
|
| 30 |
+
if axis == 0:
|
| 31 |
+
first_elem = values[:, 0]
|
| 32 |
+
dim0 = values.shape[1]
|
| 33 |
+
else:
|
| 34 |
+
first_elem = values[0]
|
| 35 |
+
dim0 = values.shape[0]
|
| 36 |
+
res0 = nb_compat_func(first_elem)
|
| 37 |
+
# Use np.asarray to get shape for
|
| 38 |
+
# https://github.com/numba/numba/issues/4202#issuecomment-1185981507
|
| 39 |
+
buf_shape = (dim0,) + np.atleast_1d(np.asarray(res0)).shape
|
| 40 |
+
if axis == 0:
|
| 41 |
+
buf_shape = buf_shape[::-1]
|
| 42 |
+
buff = np.empty(buf_shape)
|
| 43 |
+
|
| 44 |
+
if axis == 1:
|
| 45 |
+
buff[0] = res0
|
| 46 |
+
for i in numba.prange(1, values.shape[0]):
|
| 47 |
+
buff[i] = nb_compat_func(values[i])
|
| 48 |
+
else:
|
| 49 |
+
buff[:, 0] = res0
|
| 50 |
+
for j in numba.prange(1, values.shape[1]):
|
| 51 |
+
buff[:, j] = nb_compat_func(values[:, j])
|
| 52 |
+
return buff
|
| 53 |
+
|
| 54 |
+
return nb_looper
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
@functools.cache
|
| 58 |
+
def make_looper(func, result_dtype, is_grouped_kernel, nopython, nogil, parallel):
|
| 59 |
+
if TYPE_CHECKING:
|
| 60 |
+
import numba
|
| 61 |
+
else:
|
| 62 |
+
numba = import_optional_dependency("numba")
|
| 63 |
+
|
| 64 |
+
if is_grouped_kernel:
|
| 65 |
+
|
| 66 |
+
@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel)
|
| 67 |
+
def column_looper(
|
| 68 |
+
values: np.ndarray,
|
| 69 |
+
labels: np.ndarray,
|
| 70 |
+
ngroups: int,
|
| 71 |
+
min_periods: int,
|
| 72 |
+
*args,
|
| 73 |
+
):
|
| 74 |
+
result = np.empty((values.shape[0], ngroups), dtype=result_dtype)
|
| 75 |
+
na_positions = {}
|
| 76 |
+
for i in numba.prange(values.shape[0]):
|
| 77 |
+
output, na_pos = func(
|
| 78 |
+
values[i], result_dtype, labels, ngroups, min_periods, *args
|
| 79 |
+
)
|
| 80 |
+
result[i] = output
|
| 81 |
+
if len(na_pos) > 0:
|
| 82 |
+
na_positions[i] = np.array(na_pos)
|
| 83 |
+
return result, na_positions
|
| 84 |
+
|
| 85 |
+
else:
|
| 86 |
+
|
| 87 |
+
@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel)
|
| 88 |
+
def column_looper(
|
| 89 |
+
values: np.ndarray,
|
| 90 |
+
start: np.ndarray,
|
| 91 |
+
end: np.ndarray,
|
| 92 |
+
min_periods: int,
|
| 93 |
+
*args,
|
| 94 |
+
):
|
| 95 |
+
result = np.empty((values.shape[0], len(start)), dtype=result_dtype)
|
| 96 |
+
na_positions = {}
|
| 97 |
+
for i in numba.prange(values.shape[0]):
|
| 98 |
+
output, na_pos = func(
|
| 99 |
+
values[i], result_dtype, start, end, min_periods, *args
|
| 100 |
+
)
|
| 101 |
+
result[i] = output
|
| 102 |
+
if len(na_pos) > 0:
|
| 103 |
+
na_positions[i] = np.array(na_pos)
|
| 104 |
+
return result, na_positions
|
| 105 |
+
|
| 106 |
+
return column_looper
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
default_dtype_mapping: dict[np.dtype, Any] = {
|
| 110 |
+
np.dtype("int8"): np.int64,
|
| 111 |
+
np.dtype("int16"): np.int64,
|
| 112 |
+
np.dtype("int32"): np.int64,
|
| 113 |
+
np.dtype("int64"): np.int64,
|
| 114 |
+
np.dtype("uint8"): np.uint64,
|
| 115 |
+
np.dtype("uint16"): np.uint64,
|
| 116 |
+
np.dtype("uint32"): np.uint64,
|
| 117 |
+
np.dtype("uint64"): np.uint64,
|
| 118 |
+
np.dtype("float32"): np.float64,
|
| 119 |
+
np.dtype("float64"): np.float64,
|
| 120 |
+
np.dtype("complex64"): np.complex128,
|
| 121 |
+
np.dtype("complex128"): np.complex128,
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
# TODO: Preserve complex dtypes
|
| 126 |
+
|
| 127 |
+
float_dtype_mapping: dict[np.dtype, Any] = {
|
| 128 |
+
np.dtype("int8"): np.float64,
|
| 129 |
+
np.dtype("int16"): np.float64,
|
| 130 |
+
np.dtype("int32"): np.float64,
|
| 131 |
+
np.dtype("int64"): np.float64,
|
| 132 |
+
np.dtype("uint8"): np.float64,
|
| 133 |
+
np.dtype("uint16"): np.float64,
|
| 134 |
+
np.dtype("uint32"): np.float64,
|
| 135 |
+
np.dtype("uint64"): np.float64,
|
| 136 |
+
np.dtype("float32"): np.float64,
|
| 137 |
+
np.dtype("float64"): np.float64,
|
| 138 |
+
np.dtype("complex64"): np.float64,
|
| 139 |
+
np.dtype("complex128"): np.float64,
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
identity_dtype_mapping: dict[np.dtype, Any] = {
|
| 143 |
+
np.dtype("int8"): np.int8,
|
| 144 |
+
np.dtype("int16"): np.int16,
|
| 145 |
+
np.dtype("int32"): np.int32,
|
| 146 |
+
np.dtype("int64"): np.int64,
|
| 147 |
+
np.dtype("uint8"): np.uint8,
|
| 148 |
+
np.dtype("uint16"): np.uint16,
|
| 149 |
+
np.dtype("uint32"): np.uint32,
|
| 150 |
+
np.dtype("uint64"): np.uint64,
|
| 151 |
+
np.dtype("float32"): np.float32,
|
| 152 |
+
np.dtype("float64"): np.float64,
|
| 153 |
+
np.dtype("complex64"): np.complex64,
|
| 154 |
+
np.dtype("complex128"): np.complex128,
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def generate_shared_aggregator(
|
| 159 |
+
func: Callable[..., Scalar],
|
| 160 |
+
dtype_mapping: dict[np.dtype, np.dtype],
|
| 161 |
+
is_grouped_kernel: bool,
|
| 162 |
+
nopython: bool,
|
| 163 |
+
nogil: bool,
|
| 164 |
+
parallel: bool,
|
| 165 |
+
):
|
| 166 |
+
"""
|
| 167 |
+
Generate a Numba function that loops over the columns 2D object and applies
|
| 168 |
+
a 1D numba kernel over each column.
|
| 169 |
+
|
| 170 |
+
Parameters
|
| 171 |
+
----------
|
| 172 |
+
func : function
|
| 173 |
+
aggregation function to be applied to each column
|
| 174 |
+
dtype_mapping: dict or None
|
| 175 |
+
If not None, maps a dtype to a result dtype.
|
| 176 |
+
Otherwise, will fall back to default mapping.
|
| 177 |
+
is_grouped_kernel: bool, default False
|
| 178 |
+
Whether func operates using the group labels (True)
|
| 179 |
+
or using starts/ends arrays
|
| 180 |
+
|
| 181 |
+
If true, you also need to pass the number of groups to this function
|
| 182 |
+
nopython : bool
|
| 183 |
+
nopython to be passed into numba.jit
|
| 184 |
+
nogil : bool
|
| 185 |
+
nogil to be passed into numba.jit
|
| 186 |
+
parallel : bool
|
| 187 |
+
parallel to be passed into numba.jit
|
| 188 |
+
|
| 189 |
+
Returns
|
| 190 |
+
-------
|
| 191 |
+
Numba function
|
| 192 |
+
"""
|
| 193 |
+
|
| 194 |
+
# A wrapper around the looper function,
|
| 195 |
+
# to dispatch based on dtype since numba is unable to do that in nopython mode
|
| 196 |
+
|
| 197 |
+
# It also post-processes the values by inserting nans where number of observations
|
| 198 |
+
# is less than min_periods
|
| 199 |
+
# Cannot do this in numba nopython mode
|
| 200 |
+
# (you'll run into type-unification error when you cast int -> float)
|
| 201 |
+
def looper_wrapper(
|
| 202 |
+
values,
|
| 203 |
+
start=None,
|
| 204 |
+
end=None,
|
| 205 |
+
labels=None,
|
| 206 |
+
ngroups=None,
|
| 207 |
+
min_periods: int = 0,
|
| 208 |
+
**kwargs,
|
| 209 |
+
):
|
| 210 |
+
result_dtype = dtype_mapping[values.dtype]
|
| 211 |
+
column_looper = make_looper(
|
| 212 |
+
func, result_dtype, is_grouped_kernel, nopython, nogil, parallel
|
| 213 |
+
)
|
| 214 |
+
# Need to unpack kwargs since numba only supports *args
|
| 215 |
+
if is_grouped_kernel:
|
| 216 |
+
result, na_positions = column_looper(
|
| 217 |
+
values, labels, ngroups, min_periods, *kwargs.values()
|
| 218 |
+
)
|
| 219 |
+
else:
|
| 220 |
+
result, na_positions = column_looper(
|
| 221 |
+
values, start, end, min_periods, *kwargs.values()
|
| 222 |
+
)
|
| 223 |
+
if result.dtype.kind == "i":
|
| 224 |
+
# Look if na_positions is not empty
|
| 225 |
+
# If so, convert the whole block
|
| 226 |
+
# This is OK since int dtype cannot hold nan,
|
| 227 |
+
# so if min_periods not satisfied for 1 col, it is not satisfied for
|
| 228 |
+
# all columns at that index
|
| 229 |
+
for na_pos in na_positions.values():
|
| 230 |
+
if len(na_pos) > 0:
|
| 231 |
+
result = result.astype("float64")
|
| 232 |
+
break
|
| 233 |
+
# TODO: Optimize this
|
| 234 |
+
for i, na_pos in na_positions.items():
|
| 235 |
+
if len(na_pos) > 0:
|
| 236 |
+
result[i, na_pos] = np.nan
|
| 237 |
+
return result
|
| 238 |
+
|
| 239 |
+
return looper_wrapper
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/extensions.py
ADDED
|
@@ -0,0 +1,585 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Disable type checking for this module since numba's internals
|
| 2 |
+
# are not typed, and we use numba's internals via its extension API
|
| 3 |
+
# mypy: ignore-errors
|
| 4 |
+
"""
|
| 5 |
+
Utility classes/functions to let numba recognize
|
| 6 |
+
pandas Index/Series/DataFrame
|
| 7 |
+
|
| 8 |
+
Mostly vendored from https://github.com/numba/numba/blob/main/numba/tests/pdlike_usecase.py
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
from contextlib import contextmanager
|
| 14 |
+
import operator
|
| 15 |
+
|
| 16 |
+
import numba
|
| 17 |
+
from numba import types
|
| 18 |
+
from numba.core import cgutils
|
| 19 |
+
from numba.core.datamodel import models
|
| 20 |
+
from numba.core.extending import (
|
| 21 |
+
NativeValue,
|
| 22 |
+
box,
|
| 23 |
+
lower_builtin,
|
| 24 |
+
make_attribute_wrapper,
|
| 25 |
+
overload,
|
| 26 |
+
overload_attribute,
|
| 27 |
+
overload_method,
|
| 28 |
+
register_model,
|
| 29 |
+
type_callable,
|
| 30 |
+
typeof_impl,
|
| 31 |
+
unbox,
|
| 32 |
+
)
|
| 33 |
+
from numba.core.imputils import impl_ret_borrowed
|
| 34 |
+
import numpy as np
|
| 35 |
+
|
| 36 |
+
from pandas._libs import lib
|
| 37 |
+
|
| 38 |
+
from pandas.core.indexes.base import Index
|
| 39 |
+
from pandas.core.indexing import _iLocIndexer
|
| 40 |
+
from pandas.core.internals import SingleBlockManager
|
| 41 |
+
from pandas.core.series import Series
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Helper function to hack around fact that Index casts numpy string dtype to object
|
| 45 |
+
#
|
| 46 |
+
# Idea is to set an attribute on a Index called _numba_data
|
| 47 |
+
# that is the original data, or the object data casted to numpy string dtype,
|
| 48 |
+
# with a context manager that is unset afterwards
|
| 49 |
+
@contextmanager
|
| 50 |
+
def set_numba_data(index: Index):
|
| 51 |
+
numba_data = index._data
|
| 52 |
+
if numba_data.dtype in (object, "string"):
|
| 53 |
+
numba_data = np.asarray(numba_data)
|
| 54 |
+
if not lib.is_string_array(numba_data):
|
| 55 |
+
raise ValueError(
|
| 56 |
+
"The numba engine only supports using string or numeric column names"
|
| 57 |
+
)
|
| 58 |
+
numba_data = numba_data.astype("U")
|
| 59 |
+
try:
|
| 60 |
+
index._numba_data = numba_data
|
| 61 |
+
yield index
|
| 62 |
+
finally:
|
| 63 |
+
del index._numba_data
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# TODO: Range index support
|
| 67 |
+
# (this currently lowers OK, but does not round-trip)
|
| 68 |
+
class IndexType(types.Type):
|
| 69 |
+
"""
|
| 70 |
+
The type class for Index objects.
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
def __init__(self, dtype, layout, pyclass: any) -> None:
|
| 74 |
+
self.pyclass = pyclass
|
| 75 |
+
name = f"index({dtype}, {layout})"
|
| 76 |
+
self.dtype = dtype
|
| 77 |
+
self.layout = layout
|
| 78 |
+
super().__init__(name)
|
| 79 |
+
|
| 80 |
+
@property
|
| 81 |
+
def key(self):
|
| 82 |
+
return self.pyclass, self.dtype, self.layout
|
| 83 |
+
|
| 84 |
+
@property
|
| 85 |
+
def as_array(self):
|
| 86 |
+
return types.Array(self.dtype, 1, self.layout)
|
| 87 |
+
|
| 88 |
+
def copy(self, dtype=None, ndim: int = 1, layout=None):
|
| 89 |
+
assert ndim == 1
|
| 90 |
+
if dtype is None:
|
| 91 |
+
dtype = self.dtype
|
| 92 |
+
layout = layout or self.layout
|
| 93 |
+
return type(self)(dtype, layout, self.pyclass)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class SeriesType(types.Type):
|
| 97 |
+
"""
|
| 98 |
+
The type class for Series objects.
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
def __init__(self, dtype, index, namety) -> None:
|
| 102 |
+
assert isinstance(index, IndexType)
|
| 103 |
+
self.dtype = dtype
|
| 104 |
+
self.index = index
|
| 105 |
+
self.values = types.Array(self.dtype, 1, "C")
|
| 106 |
+
self.namety = namety
|
| 107 |
+
name = f"series({dtype}, {index}, {namety})"
|
| 108 |
+
super().__init__(name)
|
| 109 |
+
|
| 110 |
+
@property
|
| 111 |
+
def key(self):
|
| 112 |
+
return self.dtype, self.index, self.namety
|
| 113 |
+
|
| 114 |
+
@property
|
| 115 |
+
def as_array(self):
|
| 116 |
+
return self.values
|
| 117 |
+
|
| 118 |
+
def copy(self, dtype=None, ndim: int = 1, layout: str = "C"):
|
| 119 |
+
assert ndim == 1
|
| 120 |
+
assert layout == "C"
|
| 121 |
+
if dtype is None:
|
| 122 |
+
dtype = self.dtype
|
| 123 |
+
return type(self)(dtype, self.index, self.namety)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
@typeof_impl.register(Index)
|
| 127 |
+
def typeof_index(val, c):
|
| 128 |
+
"""
|
| 129 |
+
This will assume that only strings are in object dtype
|
| 130 |
+
index.
|
| 131 |
+
(you should check this before this gets lowered down to numba)
|
| 132 |
+
"""
|
| 133 |
+
# arrty = typeof_impl(val._data, c)
|
| 134 |
+
arrty = typeof_impl(val._numba_data, c)
|
| 135 |
+
assert arrty.ndim == 1
|
| 136 |
+
return IndexType(arrty.dtype, arrty.layout, type(val))
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
@typeof_impl.register(Series)
|
| 140 |
+
def typeof_series(val, c):
|
| 141 |
+
index = typeof_impl(val.index, c)
|
| 142 |
+
arrty = typeof_impl(val.values, c)
|
| 143 |
+
namety = typeof_impl(val.name, c)
|
| 144 |
+
assert arrty.ndim == 1
|
| 145 |
+
assert arrty.layout == "C"
|
| 146 |
+
return SeriesType(arrty.dtype, index, namety)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@type_callable(Series)
|
| 150 |
+
def type_series_constructor(context):
|
| 151 |
+
def typer(data, index, name=None):
|
| 152 |
+
if isinstance(index, IndexType) and isinstance(data, types.Array):
|
| 153 |
+
assert data.ndim == 1
|
| 154 |
+
if name is None:
|
| 155 |
+
name = types.intp
|
| 156 |
+
return SeriesType(data.dtype, index, name)
|
| 157 |
+
|
| 158 |
+
return typer
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
@type_callable(Index)
|
| 162 |
+
def type_index_constructor(context):
|
| 163 |
+
def typer(data, hashmap=None):
|
| 164 |
+
if isinstance(data, types.Array):
|
| 165 |
+
assert data.layout == "C"
|
| 166 |
+
assert data.ndim == 1
|
| 167 |
+
assert hashmap is None or isinstance(hashmap, types.DictType)
|
| 168 |
+
return IndexType(data.dtype, layout=data.layout, pyclass=Index)
|
| 169 |
+
|
| 170 |
+
return typer
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
# Backend extensions for Index and Series and Frame
|
| 174 |
+
@register_model(IndexType)
|
| 175 |
+
class IndexModel(models.StructModel):
|
| 176 |
+
def __init__(self, dmm, fe_type) -> None:
|
| 177 |
+
# We don't want the numpy string scalar type in our hashmap
|
| 178 |
+
members = [
|
| 179 |
+
("data", fe_type.as_array),
|
| 180 |
+
# This is an attempt to emulate our hashtable code with a numba
|
| 181 |
+
# typed dict
|
| 182 |
+
# It maps from values in the index to their integer positions in the array
|
| 183 |
+
("hashmap", types.DictType(fe_type.dtype, types.intp)),
|
| 184 |
+
# Pointer to the Index object this was created from, or that it
|
| 185 |
+
# boxes to
|
| 186 |
+
# https://numba.discourse.group/t/qst-how-to-cache-the-boxing-of-an-object/2128/2?u=lithomas1
|
| 187 |
+
("parent", types.pyobject),
|
| 188 |
+
]
|
| 189 |
+
models.StructModel.__init__(self, dmm, fe_type, members)
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
@register_model(SeriesType)
|
| 193 |
+
class SeriesModel(models.StructModel):
|
| 194 |
+
def __init__(self, dmm, fe_type) -> None:
|
| 195 |
+
members = [
|
| 196 |
+
("index", fe_type.index),
|
| 197 |
+
("values", fe_type.as_array),
|
| 198 |
+
("name", fe_type.namety),
|
| 199 |
+
]
|
| 200 |
+
models.StructModel.__init__(self, dmm, fe_type, members)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
make_attribute_wrapper(IndexType, "data", "_data")
|
| 204 |
+
make_attribute_wrapper(IndexType, "hashmap", "hashmap")
|
| 205 |
+
|
| 206 |
+
make_attribute_wrapper(SeriesType, "index", "index")
|
| 207 |
+
make_attribute_wrapper(SeriesType, "values", "values")
|
| 208 |
+
make_attribute_wrapper(SeriesType, "name", "name")
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
@lower_builtin(Series, types.Array, IndexType)
|
| 212 |
+
def pdseries_constructor(context, builder, sig, args):
|
| 213 |
+
data, index = args
|
| 214 |
+
series = cgutils.create_struct_proxy(sig.return_type)(context, builder)
|
| 215 |
+
series.index = index
|
| 216 |
+
series.values = data
|
| 217 |
+
series.name = context.get_constant(types.intp, 0)
|
| 218 |
+
return impl_ret_borrowed(context, builder, sig.return_type, series._getvalue())
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
@lower_builtin(Series, types.Array, IndexType, types.intp)
|
| 222 |
+
@lower_builtin(Series, types.Array, IndexType, types.float64)
|
| 223 |
+
@lower_builtin(Series, types.Array, IndexType, types.unicode_type)
|
| 224 |
+
def pdseries_constructor_with_name(context, builder, sig, args):
|
| 225 |
+
data, index, name = args
|
| 226 |
+
series = cgutils.create_struct_proxy(sig.return_type)(context, builder)
|
| 227 |
+
series.index = index
|
| 228 |
+
series.values = data
|
| 229 |
+
series.name = name
|
| 230 |
+
return impl_ret_borrowed(context, builder, sig.return_type, series._getvalue())
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
@lower_builtin(Index, types.Array, types.DictType, types.pyobject)
|
| 234 |
+
def index_constructor_2arg(context, builder, sig, args):
|
| 235 |
+
(data, hashmap, parent) = args
|
| 236 |
+
index = cgutils.create_struct_proxy(sig.return_type)(context, builder)
|
| 237 |
+
|
| 238 |
+
index.data = data
|
| 239 |
+
index.hashmap = hashmap
|
| 240 |
+
index.parent = parent
|
| 241 |
+
return impl_ret_borrowed(context, builder, sig.return_type, index._getvalue())
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
@lower_builtin(Index, types.Array, types.DictType)
|
| 245 |
+
def index_constructor_2arg_parent(context, builder, sig, args):
|
| 246 |
+
# Basically same as index_constructor_1arg, but also lets you specify the
|
| 247 |
+
# parent object
|
| 248 |
+
(data, hashmap) = args
|
| 249 |
+
index = cgutils.create_struct_proxy(sig.return_type)(context, builder)
|
| 250 |
+
|
| 251 |
+
index.data = data
|
| 252 |
+
index.hashmap = hashmap
|
| 253 |
+
return impl_ret_borrowed(context, builder, sig.return_type, index._getvalue())
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
@lower_builtin(Index, types.Array)
|
| 257 |
+
def index_constructor_1arg(context, builder, sig, args):
|
| 258 |
+
from numba.typed import Dict
|
| 259 |
+
|
| 260 |
+
key_type = sig.return_type.dtype
|
| 261 |
+
value_type = types.intp
|
| 262 |
+
|
| 263 |
+
def index_impl(data):
|
| 264 |
+
return Index(data, Dict.empty(key_type, value_type))
|
| 265 |
+
|
| 266 |
+
return context.compile_internal(builder, index_impl, sig, args)
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
# Helper to convert the unicodecharseq (numpy string scalar) into a unicode_type
|
| 270 |
+
# (regular string)
|
| 271 |
+
def maybe_cast_str(x):
|
| 272 |
+
# Dummy function that numba can overload
|
| 273 |
+
pass
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
@overload(maybe_cast_str)
|
| 277 |
+
def maybe_cast_str_impl(x):
|
| 278 |
+
"""Converts numba UnicodeCharSeq (numpy string scalar) -> unicode type (string).
|
| 279 |
+
Is a no-op for other types."""
|
| 280 |
+
if isinstance(x, types.UnicodeCharSeq):
|
| 281 |
+
return lambda x: str(x)
|
| 282 |
+
else:
|
| 283 |
+
return lambda x: x
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
@unbox(IndexType)
|
| 287 |
+
def unbox_index(typ, obj, c):
|
| 288 |
+
"""
|
| 289 |
+
Convert a Index object to a native structure.
|
| 290 |
+
|
| 291 |
+
Note: Object dtype is not allowed here
|
| 292 |
+
"""
|
| 293 |
+
data_obj = c.pyapi.object_getattr_string(obj, "_numba_data")
|
| 294 |
+
index = cgutils.create_struct_proxy(typ)(c.context, c.builder)
|
| 295 |
+
# If we see an object array, assume its been validated as only containing strings
|
| 296 |
+
# We still need to do the conversion though
|
| 297 |
+
index.data = c.unbox(typ.as_array, data_obj).value
|
| 298 |
+
typed_dict_obj = c.pyapi.unserialize(c.pyapi.serialize_object(numba.typed.Dict))
|
| 299 |
+
# Create an empty typed dict in numba for the hashmap for indexing
|
| 300 |
+
# equiv of numba.typed.Dict.empty(typ.dtype, types.intp)
|
| 301 |
+
arr_type_obj = c.pyapi.unserialize(c.pyapi.serialize_object(typ.dtype))
|
| 302 |
+
intp_type_obj = c.pyapi.unserialize(c.pyapi.serialize_object(types.intp))
|
| 303 |
+
hashmap_obj = c.pyapi.call_method(
|
| 304 |
+
typed_dict_obj, "empty", (arr_type_obj, intp_type_obj)
|
| 305 |
+
)
|
| 306 |
+
index.hashmap = c.unbox(types.DictType(typ.dtype, types.intp), hashmap_obj).value
|
| 307 |
+
# Set the parent for speedy boxing.
|
| 308 |
+
index.parent = obj
|
| 309 |
+
|
| 310 |
+
# Decrefs
|
| 311 |
+
c.pyapi.decref(data_obj)
|
| 312 |
+
c.pyapi.decref(arr_type_obj)
|
| 313 |
+
c.pyapi.decref(intp_type_obj)
|
| 314 |
+
c.pyapi.decref(typed_dict_obj)
|
| 315 |
+
|
| 316 |
+
return NativeValue(index._getvalue())
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
@unbox(SeriesType)
|
| 320 |
+
def unbox_series(typ, obj, c):
|
| 321 |
+
"""
|
| 322 |
+
Convert a Series object to a native structure.
|
| 323 |
+
"""
|
| 324 |
+
index_obj = c.pyapi.object_getattr_string(obj, "index")
|
| 325 |
+
values_obj = c.pyapi.object_getattr_string(obj, "values")
|
| 326 |
+
name_obj = c.pyapi.object_getattr_string(obj, "name")
|
| 327 |
+
|
| 328 |
+
series = cgutils.create_struct_proxy(typ)(c.context, c.builder)
|
| 329 |
+
series.index = c.unbox(typ.index, index_obj).value
|
| 330 |
+
series.values = c.unbox(typ.values, values_obj).value
|
| 331 |
+
series.name = c.unbox(typ.namety, name_obj).value
|
| 332 |
+
|
| 333 |
+
# Decrefs
|
| 334 |
+
c.pyapi.decref(index_obj)
|
| 335 |
+
c.pyapi.decref(values_obj)
|
| 336 |
+
c.pyapi.decref(name_obj)
|
| 337 |
+
|
| 338 |
+
return NativeValue(series._getvalue())
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
@box(IndexType)
|
| 342 |
+
def box_index(typ, val, c):
|
| 343 |
+
"""
|
| 344 |
+
Convert a native index structure to a Index object.
|
| 345 |
+
|
| 346 |
+
If our native index is of a numpy string dtype, we'll cast it to
|
| 347 |
+
object.
|
| 348 |
+
"""
|
| 349 |
+
# First build a Numpy array object, then wrap it in a Index
|
| 350 |
+
index = cgutils.create_struct_proxy(typ)(c.context, c.builder, value=val)
|
| 351 |
+
|
| 352 |
+
res = cgutils.alloca_once_value(c.builder, index.parent)
|
| 353 |
+
|
| 354 |
+
# Does parent exist?
|
| 355 |
+
# (it means already boxed once, or Index same as original df.index or df.columns)
|
| 356 |
+
# xref https://github.com/numba/numba/blob/596e8a55334cc46854e3192766e643767bd7c934/numba/core/boxing.py#L593C17-L593C17
|
| 357 |
+
with c.builder.if_else(cgutils.is_not_null(c.builder, index.parent)) as (
|
| 358 |
+
has_parent,
|
| 359 |
+
otherwise,
|
| 360 |
+
):
|
| 361 |
+
with has_parent:
|
| 362 |
+
c.pyapi.incref(index.parent)
|
| 363 |
+
with otherwise:
|
| 364 |
+
# TODO: preserve the original class for the index
|
| 365 |
+
# Also need preserve the name of the Index
|
| 366 |
+
# class_obj = c.pyapi.unserialize(c.pyapi.serialize_object(typ.pyclass))
|
| 367 |
+
class_obj = c.pyapi.unserialize(c.pyapi.serialize_object(Index))
|
| 368 |
+
array_obj = c.box(typ.as_array, index.data)
|
| 369 |
+
if isinstance(typ.dtype, types.UnicodeCharSeq):
|
| 370 |
+
# We converted to numpy string dtype, convert back
|
| 371 |
+
# to object since _simple_new won't do that for uss
|
| 372 |
+
object_str_obj = c.pyapi.unserialize(c.pyapi.serialize_object("object"))
|
| 373 |
+
array_obj = c.pyapi.call_method(array_obj, "astype", (object_str_obj,))
|
| 374 |
+
c.pyapi.decref(object_str_obj)
|
| 375 |
+
# this is basically Index._simple_new(array_obj, name_obj) in python
|
| 376 |
+
index_obj = c.pyapi.call_method(class_obj, "_simple_new", (array_obj,))
|
| 377 |
+
index.parent = index_obj
|
| 378 |
+
c.builder.store(index_obj, res)
|
| 379 |
+
|
| 380 |
+
# Decrefs
|
| 381 |
+
c.pyapi.decref(class_obj)
|
| 382 |
+
c.pyapi.decref(array_obj)
|
| 383 |
+
return c.builder.load(res)
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
@box(SeriesType)
|
| 387 |
+
def box_series(typ, val, c):
|
| 388 |
+
"""
|
| 389 |
+
Convert a native series structure to a Series object.
|
| 390 |
+
"""
|
| 391 |
+
series = cgutils.create_struct_proxy(typ)(c.context, c.builder, value=val)
|
| 392 |
+
series_const_obj = c.pyapi.unserialize(c.pyapi.serialize_object(Series._from_mgr))
|
| 393 |
+
mgr_const_obj = c.pyapi.unserialize(
|
| 394 |
+
c.pyapi.serialize_object(SingleBlockManager.from_array)
|
| 395 |
+
)
|
| 396 |
+
index_obj = c.box(typ.index, series.index)
|
| 397 |
+
array_obj = c.box(typ.as_array, series.values)
|
| 398 |
+
name_obj = c.box(typ.namety, series.name)
|
| 399 |
+
# This is basically equivalent of
|
| 400 |
+
# pd.Series(data=array_obj, index=index_obj)
|
| 401 |
+
# To improve perf, we will construct the Series from a manager
|
| 402 |
+
# object to avoid checks.
|
| 403 |
+
# We'll also set the name attribute manually to avoid validation
|
| 404 |
+
mgr_obj = c.pyapi.call_function_objargs(
|
| 405 |
+
mgr_const_obj,
|
| 406 |
+
(
|
| 407 |
+
array_obj,
|
| 408 |
+
index_obj,
|
| 409 |
+
),
|
| 410 |
+
)
|
| 411 |
+
mgr_axes_obj = c.pyapi.object_getattr_string(mgr_obj, "axes")
|
| 412 |
+
# Series._constructor_from_mgr(mgr, axes)
|
| 413 |
+
series_obj = c.pyapi.call_function_objargs(
|
| 414 |
+
series_const_obj, (mgr_obj, mgr_axes_obj)
|
| 415 |
+
)
|
| 416 |
+
c.pyapi.object_setattr_string(series_obj, "_name", name_obj)
|
| 417 |
+
|
| 418 |
+
# Decrefs
|
| 419 |
+
c.pyapi.decref(series_const_obj)
|
| 420 |
+
c.pyapi.decref(mgr_axes_obj)
|
| 421 |
+
c.pyapi.decref(mgr_obj)
|
| 422 |
+
c.pyapi.decref(mgr_const_obj)
|
| 423 |
+
c.pyapi.decref(index_obj)
|
| 424 |
+
c.pyapi.decref(array_obj)
|
| 425 |
+
c.pyapi.decref(name_obj)
|
| 426 |
+
|
| 427 |
+
return series_obj
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
# Add common series reductions (e.g. mean, sum),
|
| 431 |
+
# and also add common binops (e.g. add, sub, mul, div)
|
| 432 |
+
def generate_series_reduction(ser_reduction, ser_method):
|
| 433 |
+
@overload_method(SeriesType, ser_reduction)
|
| 434 |
+
def series_reduction(series):
|
| 435 |
+
def series_reduction_impl(series):
|
| 436 |
+
return ser_method(series.values)
|
| 437 |
+
|
| 438 |
+
return series_reduction_impl
|
| 439 |
+
|
| 440 |
+
return series_reduction
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
def generate_series_binop(binop):
|
| 444 |
+
@overload(binop)
|
| 445 |
+
def series_binop(series1, value):
|
| 446 |
+
if isinstance(series1, SeriesType):
|
| 447 |
+
if isinstance(value, SeriesType):
|
| 448 |
+
|
| 449 |
+
def series_binop_impl(series1, series2):
|
| 450 |
+
# TODO: Check index matching?
|
| 451 |
+
return Series(
|
| 452 |
+
binop(series1.values, series2.values),
|
| 453 |
+
series1.index,
|
| 454 |
+
series1.name,
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
return series_binop_impl
|
| 458 |
+
else:
|
| 459 |
+
|
| 460 |
+
def series_binop_impl(series1, value):
|
| 461 |
+
return Series(
|
| 462 |
+
binop(series1.values, value), series1.index, series1.name
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
return series_binop_impl
|
| 466 |
+
|
| 467 |
+
return series_binop
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
series_reductions = [
|
| 471 |
+
("sum", np.sum),
|
| 472 |
+
("mean", np.mean),
|
| 473 |
+
# Disabled due to discrepancies between numba std. dev
|
| 474 |
+
# and pandas std. dev (no way to specify dof)
|
| 475 |
+
# ("std", np.std),
|
| 476 |
+
# ("var", np.var),
|
| 477 |
+
("min", np.min),
|
| 478 |
+
("max", np.max),
|
| 479 |
+
]
|
| 480 |
+
for reduction, reduction_method in series_reductions:
|
| 481 |
+
generate_series_reduction(reduction, reduction_method)
|
| 482 |
+
|
| 483 |
+
series_binops = [operator.add, operator.sub, operator.mul, operator.truediv]
|
| 484 |
+
|
| 485 |
+
for ser_binop in series_binops:
|
| 486 |
+
generate_series_binop(ser_binop)
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
# get_loc on Index
|
| 490 |
+
@overload_method(IndexType, "get_loc")
|
| 491 |
+
def index_get_loc(index, item):
|
| 492 |
+
def index_get_loc_impl(index, item):
|
| 493 |
+
# Initialize the hash table if not initialized
|
| 494 |
+
if len(index.hashmap) == 0:
|
| 495 |
+
for i, val in enumerate(index._data):
|
| 496 |
+
index.hashmap[val] = i
|
| 497 |
+
return index.hashmap[item]
|
| 498 |
+
|
| 499 |
+
return index_get_loc_impl
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
# Indexing for Series/Index
|
| 503 |
+
@overload(operator.getitem)
|
| 504 |
+
def series_indexing(series, item):
|
| 505 |
+
if isinstance(series, SeriesType):
|
| 506 |
+
|
| 507 |
+
def series_getitem(series, item):
|
| 508 |
+
loc = series.index.get_loc(item)
|
| 509 |
+
return series.iloc[loc]
|
| 510 |
+
|
| 511 |
+
return series_getitem
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
@overload(operator.getitem)
|
| 515 |
+
def index_indexing(index, idx):
|
| 516 |
+
if isinstance(index, IndexType):
|
| 517 |
+
|
| 518 |
+
def index_getitem(index, idx):
|
| 519 |
+
return index._data[idx]
|
| 520 |
+
|
| 521 |
+
return index_getitem
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
class IlocType(types.Type):
|
| 525 |
+
def __init__(self, obj_type) -> None:
|
| 526 |
+
self.obj_type = obj_type
|
| 527 |
+
name = f"iLocIndexer({obj_type})"
|
| 528 |
+
super().__init__(name=name)
|
| 529 |
+
|
| 530 |
+
@property
|
| 531 |
+
def key(self):
|
| 532 |
+
return self.obj_type
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
@typeof_impl.register(_iLocIndexer)
|
| 536 |
+
def typeof_iloc(val, c):
|
| 537 |
+
objtype = typeof_impl(val.obj, c)
|
| 538 |
+
return IlocType(objtype)
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
@type_callable(_iLocIndexer)
|
| 542 |
+
def type_iloc_constructor(context):
|
| 543 |
+
def typer(obj):
|
| 544 |
+
if isinstance(obj, SeriesType):
|
| 545 |
+
return IlocType(obj)
|
| 546 |
+
|
| 547 |
+
return typer
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
@lower_builtin(_iLocIndexer, SeriesType)
|
| 551 |
+
def iloc_constructor(context, builder, sig, args):
|
| 552 |
+
(obj,) = args
|
| 553 |
+
iloc_indexer = cgutils.create_struct_proxy(sig.return_type)(context, builder)
|
| 554 |
+
iloc_indexer.obj = obj
|
| 555 |
+
return impl_ret_borrowed(
|
| 556 |
+
context, builder, sig.return_type, iloc_indexer._getvalue()
|
| 557 |
+
)
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
@register_model(IlocType)
|
| 561 |
+
class ILocModel(models.StructModel):
|
| 562 |
+
def __init__(self, dmm, fe_type) -> None:
|
| 563 |
+
members = [("obj", fe_type.obj_type)]
|
| 564 |
+
models.StructModel.__init__(self, dmm, fe_type, members)
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
make_attribute_wrapper(IlocType, "obj", "obj")
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
@overload_attribute(SeriesType, "iloc")
|
| 571 |
+
def series_iloc(series):
|
| 572 |
+
def get(series):
|
| 573 |
+
return _iLocIndexer(series)
|
| 574 |
+
|
| 575 |
+
return get
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
@overload(operator.getitem)
|
| 579 |
+
def iloc_getitem(iloc_indexer, i):
|
| 580 |
+
if isinstance(iloc_indexer, IlocType):
|
| 581 |
+
|
| 582 |
+
def getitem_impl(iloc_indexer, i):
|
| 583 |
+
return iloc_indexer.obj.values[i]
|
| 584 |
+
|
| 585 |
+
return getitem_impl
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pandas.core._numba.kernels.mean_ import (
|
| 2 |
+
grouped_mean,
|
| 3 |
+
sliding_mean,
|
| 4 |
+
)
|
| 5 |
+
from pandas.core._numba.kernels.min_max_ import (
|
| 6 |
+
grouped_min_max,
|
| 7 |
+
sliding_min_max,
|
| 8 |
+
)
|
| 9 |
+
from pandas.core._numba.kernels.sum_ import (
|
| 10 |
+
grouped_sum,
|
| 11 |
+
sliding_sum,
|
| 12 |
+
)
|
| 13 |
+
from pandas.core._numba.kernels.var_ import (
|
| 14 |
+
grouped_var,
|
| 15 |
+
sliding_var,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
__all__ = [
|
| 19 |
+
"sliding_mean",
|
| 20 |
+
"grouped_mean",
|
| 21 |
+
"sliding_sum",
|
| 22 |
+
"grouped_sum",
|
| 23 |
+
"sliding_var",
|
| 24 |
+
"grouped_var",
|
| 25 |
+
"sliding_min_max",
|
| 26 |
+
"grouped_min_max",
|
| 27 |
+
]
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (669 Bytes). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/mean_.cpython-312.pyc
ADDED
|
Binary file (5.09 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/min_max_.cpython-312.pyc
ADDED
|
Binary file (4.39 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/shared.cpython-312.pyc
ADDED
|
Binary file (1.02 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/sum_.cpython-312.pyc
ADDED
|
Binary file (6.23 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/__pycache__/var_.cpython-312.pyc
ADDED
|
Binary file (6.26 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kern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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Numba 1D mean kernels that can be shared by
|
| 3 |
+
* Dataframe / Series
|
| 4 |
+
* groupby
|
| 5 |
+
* rolling / expanding
|
| 6 |
+
|
| 7 |
+
Mirrors pandas/_libs/window/aggregation.pyx
|
| 8 |
+
"""
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
from typing import TYPE_CHECKING
|
| 12 |
+
|
| 13 |
+
import numba
|
| 14 |
+
import numpy as np
|
| 15 |
+
|
| 16 |
+
from pandas.core._numba.kernels.shared import is_monotonic_increasing
|
| 17 |
+
from pandas.core._numba.kernels.sum_ import grouped_kahan_sum
|
| 18 |
+
|
| 19 |
+
if TYPE_CHECKING:
|
| 20 |
+
from pandas._typing import npt
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 24 |
+
def add_mean(
|
| 25 |
+
val: float,
|
| 26 |
+
nobs: int,
|
| 27 |
+
sum_x: float,
|
| 28 |
+
neg_ct: int,
|
| 29 |
+
compensation: float,
|
| 30 |
+
num_consecutive_same_value: int,
|
| 31 |
+
prev_value: float,
|
| 32 |
+
) -> tuple[int, float, int, float, int, float]:
|
| 33 |
+
if not np.isnan(val):
|
| 34 |
+
nobs += 1
|
| 35 |
+
y = val - compensation
|
| 36 |
+
t = sum_x + y
|
| 37 |
+
compensation = t - sum_x - y
|
| 38 |
+
sum_x = t
|
| 39 |
+
if val < 0:
|
| 40 |
+
neg_ct += 1
|
| 41 |
+
|
| 42 |
+
if val == prev_value:
|
| 43 |
+
num_consecutive_same_value += 1
|
| 44 |
+
else:
|
| 45 |
+
num_consecutive_same_value = 1
|
| 46 |
+
prev_value = val
|
| 47 |
+
|
| 48 |
+
return nobs, sum_x, neg_ct, compensation, num_consecutive_same_value, prev_value
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 52 |
+
def remove_mean(
|
| 53 |
+
val: float, nobs: int, sum_x: float, neg_ct: int, compensation: float
|
| 54 |
+
) -> tuple[int, float, int, float]:
|
| 55 |
+
if not np.isnan(val):
|
| 56 |
+
nobs -= 1
|
| 57 |
+
y = -val - compensation
|
| 58 |
+
t = sum_x + y
|
| 59 |
+
compensation = t - sum_x - y
|
| 60 |
+
sum_x = t
|
| 61 |
+
if val < 0:
|
| 62 |
+
neg_ct -= 1
|
| 63 |
+
return nobs, sum_x, neg_ct, compensation
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 67 |
+
def sliding_mean(
|
| 68 |
+
values: np.ndarray,
|
| 69 |
+
result_dtype: np.dtype,
|
| 70 |
+
start: np.ndarray,
|
| 71 |
+
end: np.ndarray,
|
| 72 |
+
min_periods: int,
|
| 73 |
+
) -> tuple[np.ndarray, list[int]]:
|
| 74 |
+
N = len(start)
|
| 75 |
+
nobs = 0
|
| 76 |
+
sum_x = 0.0
|
| 77 |
+
neg_ct = 0
|
| 78 |
+
compensation_add = 0.0
|
| 79 |
+
compensation_remove = 0.0
|
| 80 |
+
|
| 81 |
+
is_monotonic_increasing_bounds = is_monotonic_increasing(
|
| 82 |
+
start
|
| 83 |
+
) and is_monotonic_increasing(end)
|
| 84 |
+
|
| 85 |
+
output = np.empty(N, dtype=result_dtype)
|
| 86 |
+
|
| 87 |
+
for i in range(N):
|
| 88 |
+
s = start[i]
|
| 89 |
+
e = end[i]
|
| 90 |
+
if i == 0 or not is_monotonic_increasing_bounds:
|
| 91 |
+
prev_value = values[s]
|
| 92 |
+
num_consecutive_same_value = 0
|
| 93 |
+
|
| 94 |
+
for j in range(s, e):
|
| 95 |
+
val = values[j]
|
| 96 |
+
(
|
| 97 |
+
nobs,
|
| 98 |
+
sum_x,
|
| 99 |
+
neg_ct,
|
| 100 |
+
compensation_add,
|
| 101 |
+
num_consecutive_same_value,
|
| 102 |
+
prev_value,
|
| 103 |
+
) = add_mean(
|
| 104 |
+
val,
|
| 105 |
+
nobs,
|
| 106 |
+
sum_x,
|
| 107 |
+
neg_ct,
|
| 108 |
+
compensation_add,
|
| 109 |
+
num_consecutive_same_value,
|
| 110 |
+
prev_value, # pyright: ignore[reportGeneralTypeIssues]
|
| 111 |
+
)
|
| 112 |
+
else:
|
| 113 |
+
for j in range(start[i - 1], s):
|
| 114 |
+
val = values[j]
|
| 115 |
+
nobs, sum_x, neg_ct, compensation_remove = remove_mean(
|
| 116 |
+
val, nobs, sum_x, neg_ct, compensation_remove
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
for j in range(end[i - 1], e):
|
| 120 |
+
val = values[j]
|
| 121 |
+
(
|
| 122 |
+
nobs,
|
| 123 |
+
sum_x,
|
| 124 |
+
neg_ct,
|
| 125 |
+
compensation_add,
|
| 126 |
+
num_consecutive_same_value,
|
| 127 |
+
prev_value,
|
| 128 |
+
) = add_mean(
|
| 129 |
+
val,
|
| 130 |
+
nobs,
|
| 131 |
+
sum_x,
|
| 132 |
+
neg_ct,
|
| 133 |
+
compensation_add,
|
| 134 |
+
num_consecutive_same_value,
|
| 135 |
+
prev_value, # pyright: ignore[reportGeneralTypeIssues]
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
if nobs >= min_periods and nobs > 0:
|
| 139 |
+
result = sum_x / nobs
|
| 140 |
+
if num_consecutive_same_value >= nobs:
|
| 141 |
+
result = prev_value
|
| 142 |
+
elif neg_ct == 0 and result < 0:
|
| 143 |
+
result = 0
|
| 144 |
+
elif neg_ct == nobs and result > 0:
|
| 145 |
+
result = 0
|
| 146 |
+
else:
|
| 147 |
+
result = np.nan
|
| 148 |
+
|
| 149 |
+
output[i] = result
|
| 150 |
+
|
| 151 |
+
if not is_monotonic_increasing_bounds:
|
| 152 |
+
nobs = 0
|
| 153 |
+
sum_x = 0.0
|
| 154 |
+
neg_ct = 0
|
| 155 |
+
compensation_remove = 0.0
|
| 156 |
+
|
| 157 |
+
# na_position is empty list since float64 can already hold nans
|
| 158 |
+
# Do list comprehension, since numba cannot figure out that na_pos is
|
| 159 |
+
# empty list of ints on its own
|
| 160 |
+
na_pos = [0 for i in range(0)]
|
| 161 |
+
return output, na_pos
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 165 |
+
def grouped_mean(
|
| 166 |
+
values: np.ndarray,
|
| 167 |
+
result_dtype: np.dtype,
|
| 168 |
+
labels: npt.NDArray[np.intp],
|
| 169 |
+
ngroups: int,
|
| 170 |
+
min_periods: int,
|
| 171 |
+
) -> tuple[np.ndarray, list[int]]:
|
| 172 |
+
output, nobs_arr, comp_arr, consecutive_counts, prev_vals = grouped_kahan_sum(
|
| 173 |
+
values, result_dtype, labels, ngroups
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
# Post-processing, replace sums that don't satisfy min_periods
|
| 177 |
+
for lab in range(ngroups):
|
| 178 |
+
nobs = nobs_arr[lab]
|
| 179 |
+
num_consecutive_same_value = consecutive_counts[lab]
|
| 180 |
+
prev_value = prev_vals[lab]
|
| 181 |
+
sum_x = output[lab]
|
| 182 |
+
if nobs >= min_periods:
|
| 183 |
+
if num_consecutive_same_value >= nobs:
|
| 184 |
+
result = prev_value * nobs
|
| 185 |
+
else:
|
| 186 |
+
result = sum_x
|
| 187 |
+
else:
|
| 188 |
+
result = np.nan
|
| 189 |
+
result /= nobs
|
| 190 |
+
output[lab] = result
|
| 191 |
+
|
| 192 |
+
# na_position is empty list since float64 can already hold nans
|
| 193 |
+
# Do list comprehension, since numba cannot figure out that na_pos is
|
| 194 |
+
# empty list of ints on its own
|
| 195 |
+
na_pos = [0 for i in range(0)]
|
| 196 |
+
return output, na_pos
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/min_max_.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Numba 1D min/max kernels that can be shared by
|
| 3 |
+
* Dataframe / Series
|
| 4 |
+
* groupby
|
| 5 |
+
* rolling / expanding
|
| 6 |
+
|
| 7 |
+
Mirrors pandas/_libs/window/aggregation.pyx
|
| 8 |
+
"""
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
from typing import TYPE_CHECKING
|
| 12 |
+
|
| 13 |
+
import numba
|
| 14 |
+
import numpy as np
|
| 15 |
+
|
| 16 |
+
if TYPE_CHECKING:
|
| 17 |
+
from pandas._typing import npt
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 21 |
+
def sliding_min_max(
|
| 22 |
+
values: np.ndarray,
|
| 23 |
+
result_dtype: np.dtype,
|
| 24 |
+
start: np.ndarray,
|
| 25 |
+
end: np.ndarray,
|
| 26 |
+
min_periods: int,
|
| 27 |
+
is_max: bool,
|
| 28 |
+
) -> tuple[np.ndarray, list[int]]:
|
| 29 |
+
N = len(start)
|
| 30 |
+
nobs = 0
|
| 31 |
+
output = np.empty(N, dtype=result_dtype)
|
| 32 |
+
na_pos = []
|
| 33 |
+
# Use deque once numba supports it
|
| 34 |
+
# https://github.com/numba/numba/issues/7417
|
| 35 |
+
Q: list = []
|
| 36 |
+
W: list = []
|
| 37 |
+
for i in range(N):
|
| 38 |
+
curr_win_size = end[i] - start[i]
|
| 39 |
+
if i == 0:
|
| 40 |
+
st = start[i]
|
| 41 |
+
else:
|
| 42 |
+
st = end[i - 1]
|
| 43 |
+
|
| 44 |
+
for k in range(st, end[i]):
|
| 45 |
+
ai = values[k]
|
| 46 |
+
if not np.isnan(ai):
|
| 47 |
+
nobs += 1
|
| 48 |
+
elif is_max:
|
| 49 |
+
ai = -np.inf
|
| 50 |
+
else:
|
| 51 |
+
ai = np.inf
|
| 52 |
+
# Discard previous entries if we find new min or max
|
| 53 |
+
if is_max:
|
| 54 |
+
while Q and ((ai >= values[Q[-1]]) or values[Q[-1]] != values[Q[-1]]):
|
| 55 |
+
Q.pop()
|
| 56 |
+
else:
|
| 57 |
+
while Q and ((ai <= values[Q[-1]]) or values[Q[-1]] != values[Q[-1]]):
|
| 58 |
+
Q.pop()
|
| 59 |
+
Q.append(k)
|
| 60 |
+
W.append(k)
|
| 61 |
+
|
| 62 |
+
# Discard entries outside and left of current window
|
| 63 |
+
while Q and Q[0] <= start[i] - 1:
|
| 64 |
+
Q.pop(0)
|
| 65 |
+
while W and W[0] <= start[i] - 1:
|
| 66 |
+
if not np.isnan(values[W[0]]):
|
| 67 |
+
nobs -= 1
|
| 68 |
+
W.pop(0)
|
| 69 |
+
|
| 70 |
+
# Save output based on index in input value array
|
| 71 |
+
if Q and curr_win_size > 0 and nobs >= min_periods:
|
| 72 |
+
output[i] = values[Q[0]]
|
| 73 |
+
else:
|
| 74 |
+
if values.dtype.kind != "i":
|
| 75 |
+
output[i] = np.nan
|
| 76 |
+
else:
|
| 77 |
+
na_pos.append(i)
|
| 78 |
+
|
| 79 |
+
return output, na_pos
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 83 |
+
def grouped_min_max(
|
| 84 |
+
values: np.ndarray,
|
| 85 |
+
result_dtype: np.dtype,
|
| 86 |
+
labels: npt.NDArray[np.intp],
|
| 87 |
+
ngroups: int,
|
| 88 |
+
min_periods: int,
|
| 89 |
+
is_max: bool,
|
| 90 |
+
) -> tuple[np.ndarray, list[int]]:
|
| 91 |
+
N = len(labels)
|
| 92 |
+
nobs = np.zeros(ngroups, dtype=np.int64)
|
| 93 |
+
na_pos = []
|
| 94 |
+
output = np.empty(ngroups, dtype=result_dtype)
|
| 95 |
+
|
| 96 |
+
for i in range(N):
|
| 97 |
+
lab = labels[i]
|
| 98 |
+
val = values[i]
|
| 99 |
+
if lab < 0:
|
| 100 |
+
continue
|
| 101 |
+
|
| 102 |
+
if values.dtype.kind == "i" or not np.isnan(val):
|
| 103 |
+
nobs[lab] += 1
|
| 104 |
+
else:
|
| 105 |
+
# NaN value cannot be a min/max value
|
| 106 |
+
continue
|
| 107 |
+
|
| 108 |
+
if nobs[lab] == 1:
|
| 109 |
+
# First element in group, set output equal to this
|
| 110 |
+
output[lab] = val
|
| 111 |
+
continue
|
| 112 |
+
|
| 113 |
+
if is_max:
|
| 114 |
+
if val > output[lab]:
|
| 115 |
+
output[lab] = val
|
| 116 |
+
else:
|
| 117 |
+
if val < output[lab]:
|
| 118 |
+
output[lab] = val
|
| 119 |
+
|
| 120 |
+
# Set labels that don't satisfy min_periods as np.nan
|
| 121 |
+
for lab, count in enumerate(nobs):
|
| 122 |
+
if count < min_periods:
|
| 123 |
+
na_pos.append(lab)
|
| 124 |
+
|
| 125 |
+
return output, na_pos
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/shared.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING
|
| 4 |
+
|
| 5 |
+
import numba
|
| 6 |
+
|
| 7 |
+
if TYPE_CHECKING:
|
| 8 |
+
import numpy as np
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@numba.jit(
|
| 12 |
+
# error: Any? not callable
|
| 13 |
+
numba.boolean(numba.int64[:]), # type: ignore[misc]
|
| 14 |
+
nopython=True,
|
| 15 |
+
nogil=True,
|
| 16 |
+
parallel=False,
|
| 17 |
+
)
|
| 18 |
+
def is_monotonic_increasing(bounds: np.ndarray) -> bool:
|
| 19 |
+
"""Check if int64 values are monotonically increasing."""
|
| 20 |
+
n = len(bounds)
|
| 21 |
+
if n < 2:
|
| 22 |
+
return True
|
| 23 |
+
prev = bounds[0]
|
| 24 |
+
for i in range(1, n):
|
| 25 |
+
cur = bounds[i]
|
| 26 |
+
if cur < prev:
|
| 27 |
+
return False
|
| 28 |
+
prev = cur
|
| 29 |
+
return True
|
.venv_haddock/lib/python3.12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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Numba 1D sum kernels that can be shared by
|
| 3 |
+
* Dataframe / Series
|
| 4 |
+
* groupby
|
| 5 |
+
* rolling / expanding
|
| 6 |
+
|
| 7 |
+
Mirrors pandas/_libs/window/aggregation.pyx
|
| 8 |
+
"""
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
from typing import (
|
| 12 |
+
TYPE_CHECKING,
|
| 13 |
+
Any,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
import numba
|
| 17 |
+
from numba.extending import register_jitable
|
| 18 |
+
import numpy as np
|
| 19 |
+
|
| 20 |
+
if TYPE_CHECKING:
|
| 21 |
+
from pandas._typing import npt
|
| 22 |
+
|
| 23 |
+
from pandas.core._numba.kernels.shared import is_monotonic_increasing
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 27 |
+
def add_sum(
|
| 28 |
+
val: Any,
|
| 29 |
+
nobs: int,
|
| 30 |
+
sum_x: Any,
|
| 31 |
+
compensation: Any,
|
| 32 |
+
num_consecutive_same_value: int,
|
| 33 |
+
prev_value: Any,
|
| 34 |
+
) -> tuple[int, Any, Any, int, Any]:
|
| 35 |
+
if not np.isnan(val):
|
| 36 |
+
nobs += 1
|
| 37 |
+
y = val - compensation
|
| 38 |
+
t = sum_x + y
|
| 39 |
+
compensation = t - sum_x - y
|
| 40 |
+
sum_x = t
|
| 41 |
+
|
| 42 |
+
if val == prev_value:
|
| 43 |
+
num_consecutive_same_value += 1
|
| 44 |
+
else:
|
| 45 |
+
num_consecutive_same_value = 1
|
| 46 |
+
prev_value = val
|
| 47 |
+
|
| 48 |
+
return nobs, sum_x, compensation, num_consecutive_same_value, prev_value
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 52 |
+
def remove_sum(
|
| 53 |
+
val: Any, nobs: int, sum_x: Any, compensation: Any
|
| 54 |
+
) -> tuple[int, Any, Any]:
|
| 55 |
+
if not np.isnan(val):
|
| 56 |
+
nobs -= 1
|
| 57 |
+
y = -val - compensation
|
| 58 |
+
t = sum_x + y
|
| 59 |
+
compensation = t - sum_x - y
|
| 60 |
+
sum_x = t
|
| 61 |
+
return nobs, sum_x, compensation
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 65 |
+
def sliding_sum(
|
| 66 |
+
values: np.ndarray,
|
| 67 |
+
result_dtype: np.dtype,
|
| 68 |
+
start: np.ndarray,
|
| 69 |
+
end: np.ndarray,
|
| 70 |
+
min_periods: int,
|
| 71 |
+
) -> tuple[np.ndarray, list[int]]:
|
| 72 |
+
dtype = values.dtype
|
| 73 |
+
|
| 74 |
+
na_val: object = np.nan
|
| 75 |
+
if dtype.kind == "i":
|
| 76 |
+
na_val = 0
|
| 77 |
+
|
| 78 |
+
N = len(start)
|
| 79 |
+
nobs = 0
|
| 80 |
+
sum_x = 0
|
| 81 |
+
compensation_add = 0
|
| 82 |
+
compensation_remove = 0
|
| 83 |
+
na_pos = []
|
| 84 |
+
|
| 85 |
+
is_monotonic_increasing_bounds = is_monotonic_increasing(
|
| 86 |
+
start
|
| 87 |
+
) and is_monotonic_increasing(end)
|
| 88 |
+
|
| 89 |
+
output = np.empty(N, dtype=result_dtype)
|
| 90 |
+
|
| 91 |
+
for i in range(N):
|
| 92 |
+
s = start[i]
|
| 93 |
+
e = end[i]
|
| 94 |
+
if i == 0 or not is_monotonic_increasing_bounds:
|
| 95 |
+
prev_value = values[s]
|
| 96 |
+
num_consecutive_same_value = 0
|
| 97 |
+
|
| 98 |
+
for j in range(s, e):
|
| 99 |
+
val = values[j]
|
| 100 |
+
(
|
| 101 |
+
nobs,
|
| 102 |
+
sum_x,
|
| 103 |
+
compensation_add,
|
| 104 |
+
num_consecutive_same_value,
|
| 105 |
+
prev_value,
|
| 106 |
+
) = add_sum(
|
| 107 |
+
val,
|
| 108 |
+
nobs,
|
| 109 |
+
sum_x,
|
| 110 |
+
compensation_add,
|
| 111 |
+
num_consecutive_same_value,
|
| 112 |
+
prev_value,
|
| 113 |
+
)
|
| 114 |
+
else:
|
| 115 |
+
for j in range(start[i - 1], s):
|
| 116 |
+
val = values[j]
|
| 117 |
+
nobs, sum_x, compensation_remove = remove_sum(
|
| 118 |
+
val, nobs, sum_x, compensation_remove
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
for j in range(end[i - 1], e):
|
| 122 |
+
val = values[j]
|
| 123 |
+
(
|
| 124 |
+
nobs,
|
| 125 |
+
sum_x,
|
| 126 |
+
compensation_add,
|
| 127 |
+
num_consecutive_same_value,
|
| 128 |
+
prev_value,
|
| 129 |
+
) = add_sum(
|
| 130 |
+
val,
|
| 131 |
+
nobs,
|
| 132 |
+
sum_x,
|
| 133 |
+
compensation_add,
|
| 134 |
+
num_consecutive_same_value,
|
| 135 |
+
prev_value,
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
if nobs == 0 == min_periods:
|
| 139 |
+
result: object = 0
|
| 140 |
+
elif nobs >= min_periods:
|
| 141 |
+
if num_consecutive_same_value >= nobs:
|
| 142 |
+
result = prev_value * nobs
|
| 143 |
+
else:
|
| 144 |
+
result = sum_x
|
| 145 |
+
else:
|
| 146 |
+
result = na_val
|
| 147 |
+
if dtype.kind == "i":
|
| 148 |
+
na_pos.append(i)
|
| 149 |
+
|
| 150 |
+
output[i] = result
|
| 151 |
+
|
| 152 |
+
if not is_monotonic_increasing_bounds:
|
| 153 |
+
nobs = 0
|
| 154 |
+
sum_x = 0
|
| 155 |
+
compensation_remove = 0
|
| 156 |
+
|
| 157 |
+
return output, na_pos
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
# Mypy/pyright don't like the fact that the decorator is untyped
|
| 161 |
+
@register_jitable # type: ignore[misc]
|
| 162 |
+
def grouped_kahan_sum(
|
| 163 |
+
values: np.ndarray,
|
| 164 |
+
result_dtype: np.dtype,
|
| 165 |
+
labels: npt.NDArray[np.intp],
|
| 166 |
+
ngroups: int,
|
| 167 |
+
) -> tuple[
|
| 168 |
+
np.ndarray, npt.NDArray[np.int64], np.ndarray, npt.NDArray[np.int64], np.ndarray
|
| 169 |
+
]:
|
| 170 |
+
N = len(labels)
|
| 171 |
+
|
| 172 |
+
nobs_arr = np.zeros(ngroups, dtype=np.int64)
|
| 173 |
+
comp_arr = np.zeros(ngroups, dtype=values.dtype)
|
| 174 |
+
consecutive_counts = np.zeros(ngroups, dtype=np.int64)
|
| 175 |
+
prev_vals = np.zeros(ngroups, dtype=values.dtype)
|
| 176 |
+
output = np.zeros(ngroups, dtype=result_dtype)
|
| 177 |
+
|
| 178 |
+
for i in range(N):
|
| 179 |
+
lab = labels[i]
|
| 180 |
+
val = values[i]
|
| 181 |
+
|
| 182 |
+
if lab < 0:
|
| 183 |
+
continue
|
| 184 |
+
|
| 185 |
+
sum_x = output[lab]
|
| 186 |
+
nobs = nobs_arr[lab]
|
| 187 |
+
compensation_add = comp_arr[lab]
|
| 188 |
+
num_consecutive_same_value = consecutive_counts[lab]
|
| 189 |
+
prev_value = prev_vals[lab]
|
| 190 |
+
|
| 191 |
+
(
|
| 192 |
+
nobs,
|
| 193 |
+
sum_x,
|
| 194 |
+
compensation_add,
|
| 195 |
+
num_consecutive_same_value,
|
| 196 |
+
prev_value,
|
| 197 |
+
) = add_sum(
|
| 198 |
+
val,
|
| 199 |
+
nobs,
|
| 200 |
+
sum_x,
|
| 201 |
+
compensation_add,
|
| 202 |
+
num_consecutive_same_value,
|
| 203 |
+
prev_value,
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
output[lab] = sum_x
|
| 207 |
+
consecutive_counts[lab] = num_consecutive_same_value
|
| 208 |
+
prev_vals[lab] = prev_value
|
| 209 |
+
comp_arr[lab] = compensation_add
|
| 210 |
+
nobs_arr[lab] = nobs
|
| 211 |
+
return output, nobs_arr, comp_arr, consecutive_counts, prev_vals
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 215 |
+
def grouped_sum(
|
| 216 |
+
values: np.ndarray,
|
| 217 |
+
result_dtype: np.dtype,
|
| 218 |
+
labels: npt.NDArray[np.intp],
|
| 219 |
+
ngroups: int,
|
| 220 |
+
min_periods: int,
|
| 221 |
+
) -> tuple[np.ndarray, list[int]]:
|
| 222 |
+
na_pos = []
|
| 223 |
+
|
| 224 |
+
output, nobs_arr, comp_arr, consecutive_counts, prev_vals = grouped_kahan_sum(
|
| 225 |
+
values, result_dtype, labels, ngroups
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
# Post-processing, replace sums that don't satisfy min_periods
|
| 229 |
+
for lab in range(ngroups):
|
| 230 |
+
nobs = nobs_arr[lab]
|
| 231 |
+
num_consecutive_same_value = consecutive_counts[lab]
|
| 232 |
+
prev_value = prev_vals[lab]
|
| 233 |
+
sum_x = output[lab]
|
| 234 |
+
if nobs >= min_periods:
|
| 235 |
+
if num_consecutive_same_value >= nobs:
|
| 236 |
+
result = prev_value * nobs
|
| 237 |
+
else:
|
| 238 |
+
result = sum_x
|
| 239 |
+
else:
|
| 240 |
+
result = sum_x # Don't change val, will be replaced by nan later
|
| 241 |
+
na_pos.append(lab)
|
| 242 |
+
output[lab] = result
|
| 243 |
+
|
| 244 |
+
return output, na_pos
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/_numba/kernels/var_.py
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Numba 1D var kernels that can be shared by
|
| 3 |
+
* Dataframe / Series
|
| 4 |
+
* groupby
|
| 5 |
+
* rolling / expanding
|
| 6 |
+
|
| 7 |
+
Mirrors pandas/_libs/window/aggregation.pyx
|
| 8 |
+
"""
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
from typing import TYPE_CHECKING
|
| 12 |
+
|
| 13 |
+
import numba
|
| 14 |
+
import numpy as np
|
| 15 |
+
|
| 16 |
+
if TYPE_CHECKING:
|
| 17 |
+
from pandas._typing import npt
|
| 18 |
+
|
| 19 |
+
from pandas.core._numba.kernels.shared import is_monotonic_increasing
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 23 |
+
def add_var(
|
| 24 |
+
val: float,
|
| 25 |
+
nobs: int,
|
| 26 |
+
mean_x: float,
|
| 27 |
+
ssqdm_x: float,
|
| 28 |
+
compensation: float,
|
| 29 |
+
num_consecutive_same_value: int,
|
| 30 |
+
prev_value: float,
|
| 31 |
+
) -> tuple[int, float, float, float, int, float]:
|
| 32 |
+
if not np.isnan(val):
|
| 33 |
+
if val == prev_value:
|
| 34 |
+
num_consecutive_same_value += 1
|
| 35 |
+
else:
|
| 36 |
+
num_consecutive_same_value = 1
|
| 37 |
+
prev_value = val
|
| 38 |
+
|
| 39 |
+
nobs += 1
|
| 40 |
+
prev_mean = mean_x - compensation
|
| 41 |
+
y = val - compensation
|
| 42 |
+
t = y - mean_x
|
| 43 |
+
compensation = t + mean_x - y
|
| 44 |
+
delta = t
|
| 45 |
+
if nobs:
|
| 46 |
+
mean_x += delta / nobs
|
| 47 |
+
else:
|
| 48 |
+
mean_x = 0
|
| 49 |
+
ssqdm_x += (val - prev_mean) * (val - mean_x)
|
| 50 |
+
return nobs, mean_x, ssqdm_x, compensation, num_consecutive_same_value, prev_value
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 54 |
+
def remove_var(
|
| 55 |
+
val: float, nobs: int, mean_x: float, ssqdm_x: float, compensation: float
|
| 56 |
+
) -> tuple[int, float, float, float]:
|
| 57 |
+
if not np.isnan(val):
|
| 58 |
+
nobs -= 1
|
| 59 |
+
if nobs:
|
| 60 |
+
prev_mean = mean_x - compensation
|
| 61 |
+
y = val - compensation
|
| 62 |
+
t = y - mean_x
|
| 63 |
+
compensation = t + mean_x - y
|
| 64 |
+
delta = t
|
| 65 |
+
mean_x -= delta / nobs
|
| 66 |
+
ssqdm_x -= (val - prev_mean) * (val - mean_x)
|
| 67 |
+
else:
|
| 68 |
+
mean_x = 0
|
| 69 |
+
ssqdm_x = 0
|
| 70 |
+
return nobs, mean_x, ssqdm_x, compensation
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 74 |
+
def sliding_var(
|
| 75 |
+
values: np.ndarray,
|
| 76 |
+
result_dtype: np.dtype,
|
| 77 |
+
start: np.ndarray,
|
| 78 |
+
end: np.ndarray,
|
| 79 |
+
min_periods: int,
|
| 80 |
+
ddof: int = 1,
|
| 81 |
+
) -> tuple[np.ndarray, list[int]]:
|
| 82 |
+
N = len(start)
|
| 83 |
+
nobs = 0
|
| 84 |
+
mean_x = 0.0
|
| 85 |
+
ssqdm_x = 0.0
|
| 86 |
+
compensation_add = 0.0
|
| 87 |
+
compensation_remove = 0.0
|
| 88 |
+
|
| 89 |
+
min_periods = max(min_periods, 1)
|
| 90 |
+
is_monotonic_increasing_bounds = is_monotonic_increasing(
|
| 91 |
+
start
|
| 92 |
+
) and is_monotonic_increasing(end)
|
| 93 |
+
|
| 94 |
+
output = np.empty(N, dtype=result_dtype)
|
| 95 |
+
|
| 96 |
+
for i in range(N):
|
| 97 |
+
s = start[i]
|
| 98 |
+
e = end[i]
|
| 99 |
+
if i == 0 or not is_monotonic_increasing_bounds:
|
| 100 |
+
prev_value = values[s]
|
| 101 |
+
num_consecutive_same_value = 0
|
| 102 |
+
|
| 103 |
+
for j in range(s, e):
|
| 104 |
+
val = values[j]
|
| 105 |
+
(
|
| 106 |
+
nobs,
|
| 107 |
+
mean_x,
|
| 108 |
+
ssqdm_x,
|
| 109 |
+
compensation_add,
|
| 110 |
+
num_consecutive_same_value,
|
| 111 |
+
prev_value,
|
| 112 |
+
) = add_var(
|
| 113 |
+
val,
|
| 114 |
+
nobs,
|
| 115 |
+
mean_x,
|
| 116 |
+
ssqdm_x,
|
| 117 |
+
compensation_add,
|
| 118 |
+
num_consecutive_same_value,
|
| 119 |
+
prev_value,
|
| 120 |
+
)
|
| 121 |
+
else:
|
| 122 |
+
for j in range(start[i - 1], s):
|
| 123 |
+
val = values[j]
|
| 124 |
+
nobs, mean_x, ssqdm_x, compensation_remove = remove_var(
|
| 125 |
+
val, nobs, mean_x, ssqdm_x, compensation_remove
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
for j in range(end[i - 1], e):
|
| 129 |
+
val = values[j]
|
| 130 |
+
(
|
| 131 |
+
nobs,
|
| 132 |
+
mean_x,
|
| 133 |
+
ssqdm_x,
|
| 134 |
+
compensation_add,
|
| 135 |
+
num_consecutive_same_value,
|
| 136 |
+
prev_value,
|
| 137 |
+
) = add_var(
|
| 138 |
+
val,
|
| 139 |
+
nobs,
|
| 140 |
+
mean_x,
|
| 141 |
+
ssqdm_x,
|
| 142 |
+
compensation_add,
|
| 143 |
+
num_consecutive_same_value,
|
| 144 |
+
prev_value,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
if nobs >= min_periods and nobs > ddof:
|
| 148 |
+
if nobs == 1 or num_consecutive_same_value >= nobs:
|
| 149 |
+
result = 0.0
|
| 150 |
+
else:
|
| 151 |
+
result = ssqdm_x / (nobs - ddof)
|
| 152 |
+
else:
|
| 153 |
+
result = np.nan
|
| 154 |
+
|
| 155 |
+
output[i] = result
|
| 156 |
+
|
| 157 |
+
if not is_monotonic_increasing_bounds:
|
| 158 |
+
nobs = 0
|
| 159 |
+
mean_x = 0.0
|
| 160 |
+
ssqdm_x = 0.0
|
| 161 |
+
compensation_remove = 0.0
|
| 162 |
+
|
| 163 |
+
# na_position is empty list since float64 can already hold nans
|
| 164 |
+
# Do list comprehension, since numba cannot figure out that na_pos is
|
| 165 |
+
# empty list of ints on its own
|
| 166 |
+
na_pos = [0 for i in range(0)]
|
| 167 |
+
return output, na_pos
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
@numba.jit(nopython=True, nogil=True, parallel=False)
|
| 171 |
+
def grouped_var(
|
| 172 |
+
values: np.ndarray,
|
| 173 |
+
result_dtype: np.dtype,
|
| 174 |
+
labels: npt.NDArray[np.intp],
|
| 175 |
+
ngroups: int,
|
| 176 |
+
min_periods: int,
|
| 177 |
+
ddof: int = 1,
|
| 178 |
+
) -> tuple[np.ndarray, list[int]]:
|
| 179 |
+
N = len(labels)
|
| 180 |
+
|
| 181 |
+
nobs_arr = np.zeros(ngroups, dtype=np.int64)
|
| 182 |
+
comp_arr = np.zeros(ngroups, dtype=values.dtype)
|
| 183 |
+
consecutive_counts = np.zeros(ngroups, dtype=np.int64)
|
| 184 |
+
prev_vals = np.zeros(ngroups, dtype=values.dtype)
|
| 185 |
+
output = np.zeros(ngroups, dtype=result_dtype)
|
| 186 |
+
means = np.zeros(ngroups, dtype=result_dtype)
|
| 187 |
+
|
| 188 |
+
for i in range(N):
|
| 189 |
+
lab = labels[i]
|
| 190 |
+
val = values[i]
|
| 191 |
+
|
| 192 |
+
if lab < 0:
|
| 193 |
+
continue
|
| 194 |
+
|
| 195 |
+
mean_x = means[lab]
|
| 196 |
+
ssqdm_x = output[lab]
|
| 197 |
+
nobs = nobs_arr[lab]
|
| 198 |
+
compensation_add = comp_arr[lab]
|
| 199 |
+
num_consecutive_same_value = consecutive_counts[lab]
|
| 200 |
+
prev_value = prev_vals[lab]
|
| 201 |
+
|
| 202 |
+
(
|
| 203 |
+
nobs,
|
| 204 |
+
mean_x,
|
| 205 |
+
ssqdm_x,
|
| 206 |
+
compensation_add,
|
| 207 |
+
num_consecutive_same_value,
|
| 208 |
+
prev_value,
|
| 209 |
+
) = add_var(
|
| 210 |
+
val,
|
| 211 |
+
nobs,
|
| 212 |
+
mean_x,
|
| 213 |
+
ssqdm_x,
|
| 214 |
+
compensation_add,
|
| 215 |
+
num_consecutive_same_value,
|
| 216 |
+
prev_value,
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
output[lab] = ssqdm_x
|
| 220 |
+
means[lab] = mean_x
|
| 221 |
+
consecutive_counts[lab] = num_consecutive_same_value
|
| 222 |
+
prev_vals[lab] = prev_value
|
| 223 |
+
comp_arr[lab] = compensation_add
|
| 224 |
+
nobs_arr[lab] = nobs
|
| 225 |
+
|
| 226 |
+
# Post-processing, replace vars that don't satisfy min_periods
|
| 227 |
+
for lab in range(ngroups):
|
| 228 |
+
nobs = nobs_arr[lab]
|
| 229 |
+
num_consecutive_same_value = consecutive_counts[lab]
|
| 230 |
+
ssqdm_x = output[lab]
|
| 231 |
+
if nobs >= min_periods and nobs > ddof:
|
| 232 |
+
if nobs == 1 or num_consecutive_same_value >= nobs:
|
| 233 |
+
result = 0.0
|
| 234 |
+
else:
|
| 235 |
+
result = ssqdm_x / (nobs - ddof)
|
| 236 |
+
else:
|
| 237 |
+
result = np.nan
|
| 238 |
+
output[lab] = result
|
| 239 |
+
|
| 240 |
+
# Second pass to get the std.dev
|
| 241 |
+
# na_position is empty list since float64 can already hold nans
|
| 242 |
+
# Do list comprehension, since numba cannot figure out that na_pos is
|
| 243 |
+
# empty list of ints on its own
|
| 244 |
+
na_pos = [0 for i in range(0)]
|
| 245 |
+
return output, na_pos
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
core.array_algos is for algorithms that operate on ndarray and ExtensionArray.
|
| 3 |
+
These should:
|
| 4 |
+
|
| 5 |
+
- Assume that any Index, Series, or DataFrame objects have already been unwrapped.
|
| 6 |
+
- Assume that any list arguments have already been cast to ndarray/EA.
|
| 7 |
+
- Not depend on Index, Series, or DataFrame, nor import any of these.
|
| 8 |
+
- May dispatch to ExtensionArray methods, but should not import from core.arrays.
|
| 9 |
+
"""
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (636 Bytes). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__pycache__/datetimelike_accumulations.cpython-312.pyc
ADDED
|
Binary file (3 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__pycache__/masked_accumulations.cpython-312.pyc
ADDED
|
Binary file (3.67 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/pandas/core/array_algos/__pycache__/masked_reductions.cpython-312.pyc
ADDED
|
Binary file (6.27 kB). View file
|
|
|