Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/__init__.py +57 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/config.py +948 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/dates.py +25 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/display.py +62 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/localization.py +172 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/__init__.py +27 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/algos.pyi +416 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/arrays.pyi +40 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/byteswap.cpython-312-x86_64-linux-gnu.so +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/byteswap.pyi +5 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/groupby.pyi +216 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/hashing.pyi +9 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/hashtable.pyi +252 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/index.pyi +100 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/indexing.cpython-312-x86_64-linux-gnu.so +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/indexing.pyi +17 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/internals.pyi +94 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/interval.pyi +174 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/join.pyi +79 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/json.cpython-312-x86_64-linux-gnu.so +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/json.pyi +23 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/lib.pyi +213 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/missing.pyi +16 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/ops.pyi +51 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/ops_dispatch.cpython-312-x86_64-linux-gnu.so +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/ops_dispatch.pyi +5 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/pandas_datetime.cpython-312-x86_64-linux-gnu.so +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/pandas_parser.cpython-312-x86_64-linux-gnu.so +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/parsers.pyi +77 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/properties.cpython-312-x86_64-linux-gnu.so +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/properties.pyi +27 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/reshape.pyi +16 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/sas.pyi +7 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/sparse.pyi +51 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/testing.pyi +12 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/tslib.pyi +37 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/writers.pyi +20 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/api/__init__.py +16 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/__init__.py +199 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/_constants.py +30 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/_optional.py +168 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/compressors.py +77 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/pickle_compat.py +262 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/pyarrow.py +29 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/__init__.py +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/accessor.py +340 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/api.py +140 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/apply.py +2062 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/arraylike.py +530 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/base.py +1391 -0
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/__init__.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pandas._config is considered explicitly upstream of everything else in pandas,
|
| 3 |
+
should have no intra-pandas dependencies.
|
| 4 |
+
|
| 5 |
+
importing `dates` and `display` ensures that keys needed by _libs
|
| 6 |
+
are initialized.
|
| 7 |
+
"""
|
| 8 |
+
__all__ = [
|
| 9 |
+
"config",
|
| 10 |
+
"detect_console_encoding",
|
| 11 |
+
"get_option",
|
| 12 |
+
"set_option",
|
| 13 |
+
"reset_option",
|
| 14 |
+
"describe_option",
|
| 15 |
+
"option_context",
|
| 16 |
+
"options",
|
| 17 |
+
"using_copy_on_write",
|
| 18 |
+
"warn_copy_on_write",
|
| 19 |
+
]
|
| 20 |
+
from pandas._config import config
|
| 21 |
+
from pandas._config import dates # pyright: ignore[reportUnusedImport] # noqa: F401
|
| 22 |
+
from pandas._config.config import (
|
| 23 |
+
_global_config,
|
| 24 |
+
describe_option,
|
| 25 |
+
get_option,
|
| 26 |
+
option_context,
|
| 27 |
+
options,
|
| 28 |
+
reset_option,
|
| 29 |
+
set_option,
|
| 30 |
+
)
|
| 31 |
+
from pandas._config.display import detect_console_encoding
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def using_copy_on_write() -> bool:
|
| 35 |
+
_mode_options = _global_config["mode"]
|
| 36 |
+
return (
|
| 37 |
+
_mode_options["copy_on_write"] is True
|
| 38 |
+
and _mode_options["data_manager"] == "block"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def warn_copy_on_write() -> bool:
|
| 43 |
+
_mode_options = _global_config["mode"]
|
| 44 |
+
return (
|
| 45 |
+
_mode_options["copy_on_write"] == "warn"
|
| 46 |
+
and _mode_options["data_manager"] == "block"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def using_nullable_dtypes() -> bool:
|
| 51 |
+
_mode_options = _global_config["mode"]
|
| 52 |
+
return _mode_options["nullable_dtypes"]
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def using_pyarrow_string_dtype() -> bool:
|
| 56 |
+
_mode_options = _global_config["future"]
|
| 57 |
+
return _mode_options["infer_string"]
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/config.py
ADDED
|
@@ -0,0 +1,948 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
The config module holds package-wide configurables and provides
|
| 3 |
+
a uniform API for working with them.
|
| 4 |
+
|
| 5 |
+
Overview
|
| 6 |
+
========
|
| 7 |
+
|
| 8 |
+
This module supports the following requirements:
|
| 9 |
+
- options are referenced using keys in dot.notation, e.g. "x.y.option - z".
|
| 10 |
+
- keys are case-insensitive.
|
| 11 |
+
- functions should accept partial/regex keys, when unambiguous.
|
| 12 |
+
- options can be registered by modules at import time.
|
| 13 |
+
- options can be registered at init-time (via core.config_init)
|
| 14 |
+
- options have a default value, and (optionally) a description and
|
| 15 |
+
validation function associated with them.
|
| 16 |
+
- options can be deprecated, in which case referencing them
|
| 17 |
+
should produce a warning.
|
| 18 |
+
- deprecated options can optionally be rerouted to a replacement
|
| 19 |
+
so that accessing a deprecated option reroutes to a differently
|
| 20 |
+
named option.
|
| 21 |
+
- options can be reset to their default value.
|
| 22 |
+
- all option can be reset to their default value at once.
|
| 23 |
+
- all options in a certain sub - namespace can be reset at once.
|
| 24 |
+
- the user can set / get / reset or ask for the description of an option.
|
| 25 |
+
- a developer can register and mark an option as deprecated.
|
| 26 |
+
- you can register a callback to be invoked when the option value
|
| 27 |
+
is set or reset. Changing the stored value is considered misuse, but
|
| 28 |
+
is not verboten.
|
| 29 |
+
|
| 30 |
+
Implementation
|
| 31 |
+
==============
|
| 32 |
+
|
| 33 |
+
- Data is stored using nested dictionaries, and should be accessed
|
| 34 |
+
through the provided API.
|
| 35 |
+
|
| 36 |
+
- "Registered options" and "Deprecated options" have metadata associated
|
| 37 |
+
with them, which are stored in auxiliary dictionaries keyed on the
|
| 38 |
+
fully-qualified key, e.g. "x.y.z.option".
|
| 39 |
+
|
| 40 |
+
- the config_init module is imported by the package's __init__.py file.
|
| 41 |
+
placing any register_option() calls there will ensure those options
|
| 42 |
+
are available as soon as pandas is loaded. If you use register_option
|
| 43 |
+
in a module, it will only be available after that module is imported,
|
| 44 |
+
which you should be aware of.
|
| 45 |
+
|
| 46 |
+
- `config_prefix` is a context_manager (for use with the `with` keyword)
|
| 47 |
+
which can save developers some typing, see the docstring.
|
| 48 |
+
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
from __future__ import annotations
|
| 52 |
+
|
| 53 |
+
from contextlib import (
|
| 54 |
+
ContextDecorator,
|
| 55 |
+
contextmanager,
|
| 56 |
+
)
|
| 57 |
+
import re
|
| 58 |
+
from typing import (
|
| 59 |
+
TYPE_CHECKING,
|
| 60 |
+
Any,
|
| 61 |
+
Callable,
|
| 62 |
+
Generic,
|
| 63 |
+
NamedTuple,
|
| 64 |
+
cast,
|
| 65 |
+
)
|
| 66 |
+
import warnings
|
| 67 |
+
|
| 68 |
+
from pandas._typing import (
|
| 69 |
+
F,
|
| 70 |
+
T,
|
| 71 |
+
)
|
| 72 |
+
from pandas.util._exceptions import find_stack_level
|
| 73 |
+
|
| 74 |
+
if TYPE_CHECKING:
|
| 75 |
+
from collections.abc import (
|
| 76 |
+
Generator,
|
| 77 |
+
Iterable,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class DeprecatedOption(NamedTuple):
|
| 82 |
+
key: str
|
| 83 |
+
msg: str | None
|
| 84 |
+
rkey: str | None
|
| 85 |
+
removal_ver: str | None
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class RegisteredOption(NamedTuple):
|
| 89 |
+
key: str
|
| 90 |
+
defval: object
|
| 91 |
+
doc: str
|
| 92 |
+
validator: Callable[[object], Any] | None
|
| 93 |
+
cb: Callable[[str], Any] | None
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# holds deprecated option metadata
|
| 97 |
+
_deprecated_options: dict[str, DeprecatedOption] = {}
|
| 98 |
+
|
| 99 |
+
# holds registered option metadata
|
| 100 |
+
_registered_options: dict[str, RegisteredOption] = {}
|
| 101 |
+
|
| 102 |
+
# holds the current values for registered options
|
| 103 |
+
_global_config: dict[str, Any] = {}
|
| 104 |
+
|
| 105 |
+
# keys which have a special meaning
|
| 106 |
+
_reserved_keys: list[str] = ["all"]
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class OptionError(AttributeError, KeyError):
|
| 110 |
+
"""
|
| 111 |
+
Exception raised for pandas.options.
|
| 112 |
+
|
| 113 |
+
Backwards compatible with KeyError checks.
|
| 114 |
+
|
| 115 |
+
Examples
|
| 116 |
+
--------
|
| 117 |
+
>>> pd.options.context
|
| 118 |
+
Traceback (most recent call last):
|
| 119 |
+
OptionError: No such option
|
| 120 |
+
"""
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
#
|
| 124 |
+
# User API
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _get_single_key(pat: str, silent: bool) -> str:
|
| 128 |
+
keys = _select_options(pat)
|
| 129 |
+
if len(keys) == 0:
|
| 130 |
+
if not silent:
|
| 131 |
+
_warn_if_deprecated(pat)
|
| 132 |
+
raise OptionError(f"No such keys(s): {repr(pat)}")
|
| 133 |
+
if len(keys) > 1:
|
| 134 |
+
raise OptionError("Pattern matched multiple keys")
|
| 135 |
+
key = keys[0]
|
| 136 |
+
|
| 137 |
+
if not silent:
|
| 138 |
+
_warn_if_deprecated(key)
|
| 139 |
+
|
| 140 |
+
key = _translate_key(key)
|
| 141 |
+
|
| 142 |
+
return key
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def _get_option(pat: str, silent: bool = False) -> Any:
|
| 146 |
+
key = _get_single_key(pat, silent)
|
| 147 |
+
|
| 148 |
+
# walk the nested dict
|
| 149 |
+
root, k = _get_root(key)
|
| 150 |
+
return root[k]
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def _set_option(*args, **kwargs) -> None:
|
| 154 |
+
# must at least 1 arg deal with constraints later
|
| 155 |
+
nargs = len(args)
|
| 156 |
+
if not nargs or nargs % 2 != 0:
|
| 157 |
+
raise ValueError("Must provide an even number of non-keyword arguments")
|
| 158 |
+
|
| 159 |
+
# default to false
|
| 160 |
+
silent = kwargs.pop("silent", False)
|
| 161 |
+
|
| 162 |
+
if kwargs:
|
| 163 |
+
kwarg = next(iter(kwargs.keys()))
|
| 164 |
+
raise TypeError(f'_set_option() got an unexpected keyword argument "{kwarg}"')
|
| 165 |
+
|
| 166 |
+
for k, v in zip(args[::2], args[1::2]):
|
| 167 |
+
key = _get_single_key(k, silent)
|
| 168 |
+
|
| 169 |
+
o = _get_registered_option(key)
|
| 170 |
+
if o and o.validator:
|
| 171 |
+
o.validator(v)
|
| 172 |
+
|
| 173 |
+
# walk the nested dict
|
| 174 |
+
root, k_root = _get_root(key)
|
| 175 |
+
root[k_root] = v
|
| 176 |
+
|
| 177 |
+
if o.cb:
|
| 178 |
+
if silent:
|
| 179 |
+
with warnings.catch_warnings(record=True):
|
| 180 |
+
o.cb(key)
|
| 181 |
+
else:
|
| 182 |
+
o.cb(key)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def _describe_option(pat: str = "", _print_desc: bool = True) -> str | None:
|
| 186 |
+
keys = _select_options(pat)
|
| 187 |
+
if len(keys) == 0:
|
| 188 |
+
raise OptionError("No such keys(s)")
|
| 189 |
+
|
| 190 |
+
s = "\n".join([_build_option_description(k) for k in keys])
|
| 191 |
+
|
| 192 |
+
if _print_desc:
|
| 193 |
+
print(s)
|
| 194 |
+
return None
|
| 195 |
+
return s
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def _reset_option(pat: str, silent: bool = False) -> None:
|
| 199 |
+
keys = _select_options(pat)
|
| 200 |
+
|
| 201 |
+
if len(keys) == 0:
|
| 202 |
+
raise OptionError("No such keys(s)")
|
| 203 |
+
|
| 204 |
+
if len(keys) > 1 and len(pat) < 4 and pat != "all":
|
| 205 |
+
raise ValueError(
|
| 206 |
+
"You must specify at least 4 characters when "
|
| 207 |
+
"resetting multiple keys, use the special keyword "
|
| 208 |
+
'"all" to reset all the options to their default value'
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
for k in keys:
|
| 212 |
+
_set_option(k, _registered_options[k].defval, silent=silent)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def get_default_val(pat: str):
|
| 216 |
+
key = _get_single_key(pat, silent=True)
|
| 217 |
+
return _get_registered_option(key).defval
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
class DictWrapper:
|
| 221 |
+
"""provide attribute-style access to a nested dict"""
|
| 222 |
+
|
| 223 |
+
d: dict[str, Any]
|
| 224 |
+
|
| 225 |
+
def __init__(self, d: dict[str, Any], prefix: str = "") -> None:
|
| 226 |
+
object.__setattr__(self, "d", d)
|
| 227 |
+
object.__setattr__(self, "prefix", prefix)
|
| 228 |
+
|
| 229 |
+
def __setattr__(self, key: str, val: Any) -> None:
|
| 230 |
+
prefix = object.__getattribute__(self, "prefix")
|
| 231 |
+
if prefix:
|
| 232 |
+
prefix += "."
|
| 233 |
+
prefix += key
|
| 234 |
+
# you can't set new keys
|
| 235 |
+
# can you can't overwrite subtrees
|
| 236 |
+
if key in self.d and not isinstance(self.d[key], dict):
|
| 237 |
+
_set_option(prefix, val)
|
| 238 |
+
else:
|
| 239 |
+
raise OptionError("You can only set the value of existing options")
|
| 240 |
+
|
| 241 |
+
def __getattr__(self, key: str):
|
| 242 |
+
prefix = object.__getattribute__(self, "prefix")
|
| 243 |
+
if prefix:
|
| 244 |
+
prefix += "."
|
| 245 |
+
prefix += key
|
| 246 |
+
try:
|
| 247 |
+
v = object.__getattribute__(self, "d")[key]
|
| 248 |
+
except KeyError as err:
|
| 249 |
+
raise OptionError("No such option") from err
|
| 250 |
+
if isinstance(v, dict):
|
| 251 |
+
return DictWrapper(v, prefix)
|
| 252 |
+
else:
|
| 253 |
+
return _get_option(prefix)
|
| 254 |
+
|
| 255 |
+
def __dir__(self) -> list[str]:
|
| 256 |
+
return list(self.d.keys())
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
# For user convenience, we'd like to have the available options described
|
| 260 |
+
# in the docstring. For dev convenience we'd like to generate the docstrings
|
| 261 |
+
# dynamically instead of maintaining them by hand. To this, we use the
|
| 262 |
+
# class below which wraps functions inside a callable, and converts
|
| 263 |
+
# __doc__ into a property function. The doctsrings below are templates
|
| 264 |
+
# using the py2.6+ advanced formatting syntax to plug in a concise list
|
| 265 |
+
# of options, and option descriptions.
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
class CallableDynamicDoc(Generic[T]):
|
| 269 |
+
def __init__(self, func: Callable[..., T], doc_tmpl: str) -> None:
|
| 270 |
+
self.__doc_tmpl__ = doc_tmpl
|
| 271 |
+
self.__func__ = func
|
| 272 |
+
|
| 273 |
+
def __call__(self, *args, **kwds) -> T:
|
| 274 |
+
return self.__func__(*args, **kwds)
|
| 275 |
+
|
| 276 |
+
# error: Signature of "__doc__" incompatible with supertype "object"
|
| 277 |
+
@property
|
| 278 |
+
def __doc__(self) -> str: # type: ignore[override]
|
| 279 |
+
opts_desc = _describe_option("all", _print_desc=False)
|
| 280 |
+
opts_list = pp_options_list(list(_registered_options.keys()))
|
| 281 |
+
return self.__doc_tmpl__.format(opts_desc=opts_desc, opts_list=opts_list)
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
_get_option_tmpl = """
|
| 285 |
+
get_option(pat)
|
| 286 |
+
|
| 287 |
+
Retrieves the value of the specified option.
|
| 288 |
+
|
| 289 |
+
Available options:
|
| 290 |
+
|
| 291 |
+
{opts_list}
|
| 292 |
+
|
| 293 |
+
Parameters
|
| 294 |
+
----------
|
| 295 |
+
pat : str
|
| 296 |
+
Regexp which should match a single option.
|
| 297 |
+
Note: partial matches are supported for convenience, but unless you use the
|
| 298 |
+
full option name (e.g. x.y.z.option_name), your code may break in future
|
| 299 |
+
versions if new options with similar names are introduced.
|
| 300 |
+
|
| 301 |
+
Returns
|
| 302 |
+
-------
|
| 303 |
+
result : the value of the option
|
| 304 |
+
|
| 305 |
+
Raises
|
| 306 |
+
------
|
| 307 |
+
OptionError : if no such option exists
|
| 308 |
+
|
| 309 |
+
Notes
|
| 310 |
+
-----
|
| 311 |
+
Please reference the :ref:`User Guide <options>` for more information.
|
| 312 |
+
|
| 313 |
+
The available options with its descriptions:
|
| 314 |
+
|
| 315 |
+
{opts_desc}
|
| 316 |
+
|
| 317 |
+
Examples
|
| 318 |
+
--------
|
| 319 |
+
>>> pd.get_option('display.max_columns') # doctest: +SKIP
|
| 320 |
+
4
|
| 321 |
+
"""
|
| 322 |
+
|
| 323 |
+
_set_option_tmpl = """
|
| 324 |
+
set_option(pat, value)
|
| 325 |
+
|
| 326 |
+
Sets the value of the specified option.
|
| 327 |
+
|
| 328 |
+
Available options:
|
| 329 |
+
|
| 330 |
+
{opts_list}
|
| 331 |
+
|
| 332 |
+
Parameters
|
| 333 |
+
----------
|
| 334 |
+
pat : str
|
| 335 |
+
Regexp which should match a single option.
|
| 336 |
+
Note: partial matches are supported for convenience, but unless you use the
|
| 337 |
+
full option name (e.g. x.y.z.option_name), your code may break in future
|
| 338 |
+
versions if new options with similar names are introduced.
|
| 339 |
+
value : object
|
| 340 |
+
New value of option.
|
| 341 |
+
|
| 342 |
+
Returns
|
| 343 |
+
-------
|
| 344 |
+
None
|
| 345 |
+
|
| 346 |
+
Raises
|
| 347 |
+
------
|
| 348 |
+
OptionError if no such option exists
|
| 349 |
+
|
| 350 |
+
Notes
|
| 351 |
+
-----
|
| 352 |
+
Please reference the :ref:`User Guide <options>` for more information.
|
| 353 |
+
|
| 354 |
+
The available options with its descriptions:
|
| 355 |
+
|
| 356 |
+
{opts_desc}
|
| 357 |
+
|
| 358 |
+
Examples
|
| 359 |
+
--------
|
| 360 |
+
>>> pd.set_option('display.max_columns', 4)
|
| 361 |
+
>>> df = pd.DataFrame([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
|
| 362 |
+
>>> df
|
| 363 |
+
0 1 ... 3 4
|
| 364 |
+
0 1 2 ... 4 5
|
| 365 |
+
1 6 7 ... 9 10
|
| 366 |
+
[2 rows x 5 columns]
|
| 367 |
+
>>> pd.reset_option('display.max_columns')
|
| 368 |
+
"""
|
| 369 |
+
|
| 370 |
+
_describe_option_tmpl = """
|
| 371 |
+
describe_option(pat, _print_desc=False)
|
| 372 |
+
|
| 373 |
+
Prints the description for one or more registered options.
|
| 374 |
+
|
| 375 |
+
Call with no arguments to get a listing for all registered options.
|
| 376 |
+
|
| 377 |
+
Available options:
|
| 378 |
+
|
| 379 |
+
{opts_list}
|
| 380 |
+
|
| 381 |
+
Parameters
|
| 382 |
+
----------
|
| 383 |
+
pat : str
|
| 384 |
+
Regexp pattern. All matching keys will have their description displayed.
|
| 385 |
+
_print_desc : bool, default True
|
| 386 |
+
If True (default) the description(s) will be printed to stdout.
|
| 387 |
+
Otherwise, the description(s) will be returned as a unicode string
|
| 388 |
+
(for testing).
|
| 389 |
+
|
| 390 |
+
Returns
|
| 391 |
+
-------
|
| 392 |
+
None by default, the description(s) as a unicode string if _print_desc
|
| 393 |
+
is False
|
| 394 |
+
|
| 395 |
+
Notes
|
| 396 |
+
-----
|
| 397 |
+
Please reference the :ref:`User Guide <options>` for more information.
|
| 398 |
+
|
| 399 |
+
The available options with its descriptions:
|
| 400 |
+
|
| 401 |
+
{opts_desc}
|
| 402 |
+
|
| 403 |
+
Examples
|
| 404 |
+
--------
|
| 405 |
+
>>> pd.describe_option('display.max_columns') # doctest: +SKIP
|
| 406 |
+
display.max_columns : int
|
| 407 |
+
If max_cols is exceeded, switch to truncate view...
|
| 408 |
+
"""
|
| 409 |
+
|
| 410 |
+
_reset_option_tmpl = """
|
| 411 |
+
reset_option(pat)
|
| 412 |
+
|
| 413 |
+
Reset one or more options to their default value.
|
| 414 |
+
|
| 415 |
+
Pass "all" as argument to reset all options.
|
| 416 |
+
|
| 417 |
+
Available options:
|
| 418 |
+
|
| 419 |
+
{opts_list}
|
| 420 |
+
|
| 421 |
+
Parameters
|
| 422 |
+
----------
|
| 423 |
+
pat : str/regex
|
| 424 |
+
If specified only options matching `prefix*` will be reset.
|
| 425 |
+
Note: partial matches are supported for convenience, but unless you
|
| 426 |
+
use the full option name (e.g. x.y.z.option_name), your code may break
|
| 427 |
+
in future versions if new options with similar names are introduced.
|
| 428 |
+
|
| 429 |
+
Returns
|
| 430 |
+
-------
|
| 431 |
+
None
|
| 432 |
+
|
| 433 |
+
Notes
|
| 434 |
+
-----
|
| 435 |
+
Please reference the :ref:`User Guide <options>` for more information.
|
| 436 |
+
|
| 437 |
+
The available options with its descriptions:
|
| 438 |
+
|
| 439 |
+
{opts_desc}
|
| 440 |
+
|
| 441 |
+
Examples
|
| 442 |
+
--------
|
| 443 |
+
>>> pd.reset_option('display.max_columns') # doctest: +SKIP
|
| 444 |
+
"""
|
| 445 |
+
|
| 446 |
+
# bind the functions with their docstrings into a Callable
|
| 447 |
+
# and use that as the functions exposed in pd.api
|
| 448 |
+
get_option = CallableDynamicDoc(_get_option, _get_option_tmpl)
|
| 449 |
+
set_option = CallableDynamicDoc(_set_option, _set_option_tmpl)
|
| 450 |
+
reset_option = CallableDynamicDoc(_reset_option, _reset_option_tmpl)
|
| 451 |
+
describe_option = CallableDynamicDoc(_describe_option, _describe_option_tmpl)
|
| 452 |
+
options = DictWrapper(_global_config)
|
| 453 |
+
|
| 454 |
+
#
|
| 455 |
+
# Functions for use by pandas developers, in addition to User - api
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
class option_context(ContextDecorator):
|
| 459 |
+
"""
|
| 460 |
+
Context manager to temporarily set options in the `with` statement context.
|
| 461 |
+
|
| 462 |
+
You need to invoke as ``option_context(pat, val, [(pat, val), ...])``.
|
| 463 |
+
|
| 464 |
+
Examples
|
| 465 |
+
--------
|
| 466 |
+
>>> from pandas import option_context
|
| 467 |
+
>>> with option_context('display.max_rows', 10, 'display.max_columns', 5):
|
| 468 |
+
... pass
|
| 469 |
+
"""
|
| 470 |
+
|
| 471 |
+
def __init__(self, *args) -> None:
|
| 472 |
+
if len(args) % 2 != 0 or len(args) < 2:
|
| 473 |
+
raise ValueError(
|
| 474 |
+
"Need to invoke as option_context(pat, val, [(pat, val), ...])."
|
| 475 |
+
)
|
| 476 |
+
|
| 477 |
+
self.ops = list(zip(args[::2], args[1::2]))
|
| 478 |
+
|
| 479 |
+
def __enter__(self) -> None:
|
| 480 |
+
self.undo = [(pat, _get_option(pat)) for pat, val in self.ops]
|
| 481 |
+
|
| 482 |
+
for pat, val in self.ops:
|
| 483 |
+
_set_option(pat, val, silent=True)
|
| 484 |
+
|
| 485 |
+
def __exit__(self, *args) -> None:
|
| 486 |
+
if self.undo:
|
| 487 |
+
for pat, val in self.undo:
|
| 488 |
+
_set_option(pat, val, silent=True)
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
def register_option(
|
| 492 |
+
key: str,
|
| 493 |
+
defval: object,
|
| 494 |
+
doc: str = "",
|
| 495 |
+
validator: Callable[[object], Any] | None = None,
|
| 496 |
+
cb: Callable[[str], Any] | None = None,
|
| 497 |
+
) -> None:
|
| 498 |
+
"""
|
| 499 |
+
Register an option in the package-wide pandas config object
|
| 500 |
+
|
| 501 |
+
Parameters
|
| 502 |
+
----------
|
| 503 |
+
key : str
|
| 504 |
+
Fully-qualified key, e.g. "x.y.option - z".
|
| 505 |
+
defval : object
|
| 506 |
+
Default value of the option.
|
| 507 |
+
doc : str
|
| 508 |
+
Description of the option.
|
| 509 |
+
validator : Callable, optional
|
| 510 |
+
Function of a single argument, should raise `ValueError` if
|
| 511 |
+
called with a value which is not a legal value for the option.
|
| 512 |
+
cb
|
| 513 |
+
a function of a single argument "key", which is called
|
| 514 |
+
immediately after an option value is set/reset. key is
|
| 515 |
+
the full name of the option.
|
| 516 |
+
|
| 517 |
+
Raises
|
| 518 |
+
------
|
| 519 |
+
ValueError if `validator` is specified and `defval` is not a valid value.
|
| 520 |
+
|
| 521 |
+
"""
|
| 522 |
+
import keyword
|
| 523 |
+
import tokenize
|
| 524 |
+
|
| 525 |
+
key = key.lower()
|
| 526 |
+
|
| 527 |
+
if key in _registered_options:
|
| 528 |
+
raise OptionError(f"Option '{key}' has already been registered")
|
| 529 |
+
if key in _reserved_keys:
|
| 530 |
+
raise OptionError(f"Option '{key}' is a reserved key")
|
| 531 |
+
|
| 532 |
+
# the default value should be legal
|
| 533 |
+
if validator:
|
| 534 |
+
validator(defval)
|
| 535 |
+
|
| 536 |
+
# walk the nested dict, creating dicts as needed along the path
|
| 537 |
+
path = key.split(".")
|
| 538 |
+
|
| 539 |
+
for k in path:
|
| 540 |
+
if not re.match("^" + tokenize.Name + "$", k):
|
| 541 |
+
raise ValueError(f"{k} is not a valid identifier")
|
| 542 |
+
if keyword.iskeyword(k):
|
| 543 |
+
raise ValueError(f"{k} is a python keyword")
|
| 544 |
+
|
| 545 |
+
cursor = _global_config
|
| 546 |
+
msg = "Path prefix to option '{option}' is already an option"
|
| 547 |
+
|
| 548 |
+
for i, p in enumerate(path[:-1]):
|
| 549 |
+
if not isinstance(cursor, dict):
|
| 550 |
+
raise OptionError(msg.format(option=".".join(path[:i])))
|
| 551 |
+
if p not in cursor:
|
| 552 |
+
cursor[p] = {}
|
| 553 |
+
cursor = cursor[p]
|
| 554 |
+
|
| 555 |
+
if not isinstance(cursor, dict):
|
| 556 |
+
raise OptionError(msg.format(option=".".join(path[:-1])))
|
| 557 |
+
|
| 558 |
+
cursor[path[-1]] = defval # initialize
|
| 559 |
+
|
| 560 |
+
# save the option metadata
|
| 561 |
+
_registered_options[key] = RegisteredOption(
|
| 562 |
+
key=key, defval=defval, doc=doc, validator=validator, cb=cb
|
| 563 |
+
)
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
def deprecate_option(
|
| 567 |
+
key: str,
|
| 568 |
+
msg: str | None = None,
|
| 569 |
+
rkey: str | None = None,
|
| 570 |
+
removal_ver: str | None = None,
|
| 571 |
+
) -> None:
|
| 572 |
+
"""
|
| 573 |
+
Mark option `key` as deprecated, if code attempts to access this option,
|
| 574 |
+
a warning will be produced, using `msg` if given, or a default message
|
| 575 |
+
if not.
|
| 576 |
+
if `rkey` is given, any access to the key will be re-routed to `rkey`.
|
| 577 |
+
|
| 578 |
+
Neither the existence of `key` nor that if `rkey` is checked. If they
|
| 579 |
+
do not exist, any subsequence access will fail as usual, after the
|
| 580 |
+
deprecation warning is given.
|
| 581 |
+
|
| 582 |
+
Parameters
|
| 583 |
+
----------
|
| 584 |
+
key : str
|
| 585 |
+
Name of the option to be deprecated.
|
| 586 |
+
must be a fully-qualified option name (e.g "x.y.z.rkey").
|
| 587 |
+
msg : str, optional
|
| 588 |
+
Warning message to output when the key is referenced.
|
| 589 |
+
if no message is given a default message will be emitted.
|
| 590 |
+
rkey : str, optional
|
| 591 |
+
Name of an option to reroute access to.
|
| 592 |
+
If specified, any referenced `key` will be
|
| 593 |
+
re-routed to `rkey` including set/get/reset.
|
| 594 |
+
rkey must be a fully-qualified option name (e.g "x.y.z.rkey").
|
| 595 |
+
used by the default message if no `msg` is specified.
|
| 596 |
+
removal_ver : str, optional
|
| 597 |
+
Specifies the version in which this option will
|
| 598 |
+
be removed. used by the default message if no `msg` is specified.
|
| 599 |
+
|
| 600 |
+
Raises
|
| 601 |
+
------
|
| 602 |
+
OptionError
|
| 603 |
+
If the specified key has already been deprecated.
|
| 604 |
+
"""
|
| 605 |
+
key = key.lower()
|
| 606 |
+
|
| 607 |
+
if key in _deprecated_options:
|
| 608 |
+
raise OptionError(f"Option '{key}' has already been defined as deprecated.")
|
| 609 |
+
|
| 610 |
+
_deprecated_options[key] = DeprecatedOption(key, msg, rkey, removal_ver)
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
#
|
| 614 |
+
# functions internal to the module
|
| 615 |
+
|
| 616 |
+
|
| 617 |
+
def _select_options(pat: str) -> list[str]:
|
| 618 |
+
"""
|
| 619 |
+
returns a list of keys matching `pat`
|
| 620 |
+
|
| 621 |
+
if pat=="all", returns all registered options
|
| 622 |
+
"""
|
| 623 |
+
# short-circuit for exact key
|
| 624 |
+
if pat in _registered_options:
|
| 625 |
+
return [pat]
|
| 626 |
+
|
| 627 |
+
# else look through all of them
|
| 628 |
+
keys = sorted(_registered_options.keys())
|
| 629 |
+
if pat == "all": # reserved key
|
| 630 |
+
return keys
|
| 631 |
+
|
| 632 |
+
return [k for k in keys if re.search(pat, k, re.I)]
|
| 633 |
+
|
| 634 |
+
|
| 635 |
+
def _get_root(key: str) -> tuple[dict[str, Any], str]:
|
| 636 |
+
path = key.split(".")
|
| 637 |
+
cursor = _global_config
|
| 638 |
+
for p in path[:-1]:
|
| 639 |
+
cursor = cursor[p]
|
| 640 |
+
return cursor, path[-1]
|
| 641 |
+
|
| 642 |
+
|
| 643 |
+
def _is_deprecated(key: str) -> bool:
|
| 644 |
+
"""Returns True if the given option has been deprecated"""
|
| 645 |
+
key = key.lower()
|
| 646 |
+
return key in _deprecated_options
|
| 647 |
+
|
| 648 |
+
|
| 649 |
+
def _get_deprecated_option(key: str):
|
| 650 |
+
"""
|
| 651 |
+
Retrieves the metadata for a deprecated option, if `key` is deprecated.
|
| 652 |
+
|
| 653 |
+
Returns
|
| 654 |
+
-------
|
| 655 |
+
DeprecatedOption (namedtuple) if key is deprecated, None otherwise
|
| 656 |
+
"""
|
| 657 |
+
try:
|
| 658 |
+
d = _deprecated_options[key]
|
| 659 |
+
except KeyError:
|
| 660 |
+
return None
|
| 661 |
+
else:
|
| 662 |
+
return d
|
| 663 |
+
|
| 664 |
+
|
| 665 |
+
def _get_registered_option(key: str):
|
| 666 |
+
"""
|
| 667 |
+
Retrieves the option metadata if `key` is a registered option.
|
| 668 |
+
|
| 669 |
+
Returns
|
| 670 |
+
-------
|
| 671 |
+
RegisteredOption (namedtuple) if key is deprecated, None otherwise
|
| 672 |
+
"""
|
| 673 |
+
return _registered_options.get(key)
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
def _translate_key(key: str) -> str:
|
| 677 |
+
"""
|
| 678 |
+
if key id deprecated and a replacement key defined, will return the
|
| 679 |
+
replacement key, otherwise returns `key` as - is
|
| 680 |
+
"""
|
| 681 |
+
d = _get_deprecated_option(key)
|
| 682 |
+
if d:
|
| 683 |
+
return d.rkey or key
|
| 684 |
+
else:
|
| 685 |
+
return key
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
def _warn_if_deprecated(key: str) -> bool:
|
| 689 |
+
"""
|
| 690 |
+
Checks if `key` is a deprecated option and if so, prints a warning.
|
| 691 |
+
|
| 692 |
+
Returns
|
| 693 |
+
-------
|
| 694 |
+
bool - True if `key` is deprecated, False otherwise.
|
| 695 |
+
"""
|
| 696 |
+
d = _get_deprecated_option(key)
|
| 697 |
+
if d:
|
| 698 |
+
if d.msg:
|
| 699 |
+
warnings.warn(
|
| 700 |
+
d.msg,
|
| 701 |
+
FutureWarning,
|
| 702 |
+
stacklevel=find_stack_level(),
|
| 703 |
+
)
|
| 704 |
+
else:
|
| 705 |
+
msg = f"'{key}' is deprecated"
|
| 706 |
+
if d.removal_ver:
|
| 707 |
+
msg += f" and will be removed in {d.removal_ver}"
|
| 708 |
+
if d.rkey:
|
| 709 |
+
msg += f", please use '{d.rkey}' instead."
|
| 710 |
+
else:
|
| 711 |
+
msg += ", please refrain from using it."
|
| 712 |
+
|
| 713 |
+
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())
|
| 714 |
+
return True
|
| 715 |
+
return False
|
| 716 |
+
|
| 717 |
+
|
| 718 |
+
def _build_option_description(k: str) -> str:
|
| 719 |
+
"""Builds a formatted description of a registered option and prints it"""
|
| 720 |
+
o = _get_registered_option(k)
|
| 721 |
+
d = _get_deprecated_option(k)
|
| 722 |
+
|
| 723 |
+
s = f"{k} "
|
| 724 |
+
|
| 725 |
+
if o.doc:
|
| 726 |
+
s += "\n".join(o.doc.strip().split("\n"))
|
| 727 |
+
else:
|
| 728 |
+
s += "No description available."
|
| 729 |
+
|
| 730 |
+
if o:
|
| 731 |
+
s += f"\n [default: {o.defval}] [currently: {_get_option(k, True)}]"
|
| 732 |
+
|
| 733 |
+
if d:
|
| 734 |
+
rkey = d.rkey or ""
|
| 735 |
+
s += "\n (Deprecated"
|
| 736 |
+
s += f", use `{rkey}` instead."
|
| 737 |
+
s += ")"
|
| 738 |
+
|
| 739 |
+
return s
|
| 740 |
+
|
| 741 |
+
|
| 742 |
+
def pp_options_list(keys: Iterable[str], width: int = 80, _print: bool = False):
|
| 743 |
+
"""Builds a concise listing of available options, grouped by prefix"""
|
| 744 |
+
from itertools import groupby
|
| 745 |
+
from textwrap import wrap
|
| 746 |
+
|
| 747 |
+
def pp(name: str, ks: Iterable[str]) -> list[str]:
|
| 748 |
+
pfx = "- " + name + ".[" if name else ""
|
| 749 |
+
ls = wrap(
|
| 750 |
+
", ".join(ks),
|
| 751 |
+
width,
|
| 752 |
+
initial_indent=pfx,
|
| 753 |
+
subsequent_indent=" ",
|
| 754 |
+
break_long_words=False,
|
| 755 |
+
)
|
| 756 |
+
if ls and ls[-1] and name:
|
| 757 |
+
ls[-1] = ls[-1] + "]"
|
| 758 |
+
return ls
|
| 759 |
+
|
| 760 |
+
ls: list[str] = []
|
| 761 |
+
singles = [x for x in sorted(keys) if x.find(".") < 0]
|
| 762 |
+
if singles:
|
| 763 |
+
ls += pp("", singles)
|
| 764 |
+
keys = [x for x in keys if x.find(".") >= 0]
|
| 765 |
+
|
| 766 |
+
for k, g in groupby(sorted(keys), lambda x: x[: x.rfind(".")]):
|
| 767 |
+
ks = [x[len(k) + 1 :] for x in list(g)]
|
| 768 |
+
ls += pp(k, ks)
|
| 769 |
+
s = "\n".join(ls)
|
| 770 |
+
if _print:
|
| 771 |
+
print(s)
|
| 772 |
+
else:
|
| 773 |
+
return s
|
| 774 |
+
|
| 775 |
+
|
| 776 |
+
#
|
| 777 |
+
# helpers
|
| 778 |
+
|
| 779 |
+
|
| 780 |
+
@contextmanager
|
| 781 |
+
def config_prefix(prefix: str) -> Generator[None, None, None]:
|
| 782 |
+
"""
|
| 783 |
+
contextmanager for multiple invocations of API with a common prefix
|
| 784 |
+
|
| 785 |
+
supported API functions: (register / get / set )__option
|
| 786 |
+
|
| 787 |
+
Warning: This is not thread - safe, and won't work properly if you import
|
| 788 |
+
the API functions into your module using the "from x import y" construct.
|
| 789 |
+
|
| 790 |
+
Example
|
| 791 |
+
-------
|
| 792 |
+
import pandas._config.config as cf
|
| 793 |
+
with cf.config_prefix("display.font"):
|
| 794 |
+
cf.register_option("color", "red")
|
| 795 |
+
cf.register_option("size", " 5 pt")
|
| 796 |
+
cf.set_option(size, " 6 pt")
|
| 797 |
+
cf.get_option(size)
|
| 798 |
+
...
|
| 799 |
+
|
| 800 |
+
etc'
|
| 801 |
+
|
| 802 |
+
will register options "display.font.color", "display.font.size", set the
|
| 803 |
+
value of "display.font.size"... and so on.
|
| 804 |
+
"""
|
| 805 |
+
# Note: reset_option relies on set_option, and on key directly
|
| 806 |
+
# it does not fit in to this monkey-patching scheme
|
| 807 |
+
|
| 808 |
+
global register_option, get_option, set_option
|
| 809 |
+
|
| 810 |
+
def wrap(func: F) -> F:
|
| 811 |
+
def inner(key: str, *args, **kwds):
|
| 812 |
+
pkey = f"{prefix}.{key}"
|
| 813 |
+
return func(pkey, *args, **kwds)
|
| 814 |
+
|
| 815 |
+
return cast(F, inner)
|
| 816 |
+
|
| 817 |
+
_register_option = register_option
|
| 818 |
+
_get_option = get_option
|
| 819 |
+
_set_option = set_option
|
| 820 |
+
set_option = wrap(set_option)
|
| 821 |
+
get_option = wrap(get_option)
|
| 822 |
+
register_option = wrap(register_option)
|
| 823 |
+
try:
|
| 824 |
+
yield
|
| 825 |
+
finally:
|
| 826 |
+
set_option = _set_option
|
| 827 |
+
get_option = _get_option
|
| 828 |
+
register_option = _register_option
|
| 829 |
+
|
| 830 |
+
|
| 831 |
+
# These factories and methods are handy for use as the validator
|
| 832 |
+
# arg in register_option
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
def is_type_factory(_type: type[Any]) -> Callable[[Any], None]:
|
| 836 |
+
"""
|
| 837 |
+
|
| 838 |
+
Parameters
|
| 839 |
+
----------
|
| 840 |
+
`_type` - a type to be compared against (e.g. type(x) == `_type`)
|
| 841 |
+
|
| 842 |
+
Returns
|
| 843 |
+
-------
|
| 844 |
+
validator - a function of a single argument x , which raises
|
| 845 |
+
ValueError if type(x) is not equal to `_type`
|
| 846 |
+
|
| 847 |
+
"""
|
| 848 |
+
|
| 849 |
+
def inner(x) -> None:
|
| 850 |
+
if type(x) != _type:
|
| 851 |
+
raise ValueError(f"Value must have type '{_type}'")
|
| 852 |
+
|
| 853 |
+
return inner
|
| 854 |
+
|
| 855 |
+
|
| 856 |
+
def is_instance_factory(_type) -> Callable[[Any], None]:
|
| 857 |
+
"""
|
| 858 |
+
|
| 859 |
+
Parameters
|
| 860 |
+
----------
|
| 861 |
+
`_type` - the type to be checked against
|
| 862 |
+
|
| 863 |
+
Returns
|
| 864 |
+
-------
|
| 865 |
+
validator - a function of a single argument x , which raises
|
| 866 |
+
ValueError if x is not an instance of `_type`
|
| 867 |
+
|
| 868 |
+
"""
|
| 869 |
+
if isinstance(_type, (tuple, list)):
|
| 870 |
+
_type = tuple(_type)
|
| 871 |
+
type_repr = "|".join(map(str, _type))
|
| 872 |
+
else:
|
| 873 |
+
type_repr = f"'{_type}'"
|
| 874 |
+
|
| 875 |
+
def inner(x) -> None:
|
| 876 |
+
if not isinstance(x, _type):
|
| 877 |
+
raise ValueError(f"Value must be an instance of {type_repr}")
|
| 878 |
+
|
| 879 |
+
return inner
|
| 880 |
+
|
| 881 |
+
|
| 882 |
+
def is_one_of_factory(legal_values) -> Callable[[Any], None]:
|
| 883 |
+
callables = [c for c in legal_values if callable(c)]
|
| 884 |
+
legal_values = [c for c in legal_values if not callable(c)]
|
| 885 |
+
|
| 886 |
+
def inner(x) -> None:
|
| 887 |
+
if x not in legal_values:
|
| 888 |
+
if not any(c(x) for c in callables):
|
| 889 |
+
uvals = [str(lval) for lval in legal_values]
|
| 890 |
+
pp_values = "|".join(uvals)
|
| 891 |
+
msg = f"Value must be one of {pp_values}"
|
| 892 |
+
if len(callables):
|
| 893 |
+
msg += " or a callable"
|
| 894 |
+
raise ValueError(msg)
|
| 895 |
+
|
| 896 |
+
return inner
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
def is_nonnegative_int(value: object) -> None:
|
| 900 |
+
"""
|
| 901 |
+
Verify that value is None or a positive int.
|
| 902 |
+
|
| 903 |
+
Parameters
|
| 904 |
+
----------
|
| 905 |
+
value : None or int
|
| 906 |
+
The `value` to be checked.
|
| 907 |
+
|
| 908 |
+
Raises
|
| 909 |
+
------
|
| 910 |
+
ValueError
|
| 911 |
+
When the value is not None or is a negative integer
|
| 912 |
+
"""
|
| 913 |
+
if value is None:
|
| 914 |
+
return
|
| 915 |
+
|
| 916 |
+
elif isinstance(value, int):
|
| 917 |
+
if value >= 0:
|
| 918 |
+
return
|
| 919 |
+
|
| 920 |
+
msg = "Value must be a nonnegative integer or None"
|
| 921 |
+
raise ValueError(msg)
|
| 922 |
+
|
| 923 |
+
|
| 924 |
+
# common type validators, for convenience
|
| 925 |
+
# usage: register_option(... , validator = is_int)
|
| 926 |
+
is_int = is_type_factory(int)
|
| 927 |
+
is_bool = is_type_factory(bool)
|
| 928 |
+
is_float = is_type_factory(float)
|
| 929 |
+
is_str = is_type_factory(str)
|
| 930 |
+
is_text = is_instance_factory((str, bytes))
|
| 931 |
+
|
| 932 |
+
|
| 933 |
+
def is_callable(obj) -> bool:
|
| 934 |
+
"""
|
| 935 |
+
|
| 936 |
+
Parameters
|
| 937 |
+
----------
|
| 938 |
+
`obj` - the object to be checked
|
| 939 |
+
|
| 940 |
+
Returns
|
| 941 |
+
-------
|
| 942 |
+
validator - returns True if object is callable
|
| 943 |
+
raises ValueError otherwise.
|
| 944 |
+
|
| 945 |
+
"""
|
| 946 |
+
if not callable(obj):
|
| 947 |
+
raise ValueError("Value must be a callable")
|
| 948 |
+
return True
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/dates.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
config for datetime formatting
|
| 3 |
+
"""
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
from pandas._config import config as cf
|
| 7 |
+
|
| 8 |
+
pc_date_dayfirst_doc = """
|
| 9 |
+
: boolean
|
| 10 |
+
When True, prints and parses dates with the day first, eg 20/01/2005
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
pc_date_yearfirst_doc = """
|
| 14 |
+
: boolean
|
| 15 |
+
When True, prints and parses dates with the year first, eg 2005/01/20
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
with cf.config_prefix("display"):
|
| 19 |
+
# Needed upstream of `_libs` because these are used in tslibs.parsing
|
| 20 |
+
cf.register_option(
|
| 21 |
+
"date_dayfirst", False, pc_date_dayfirst_doc, validator=cf.is_bool
|
| 22 |
+
)
|
| 23 |
+
cf.register_option(
|
| 24 |
+
"date_yearfirst", False, pc_date_yearfirst_doc, validator=cf.is_bool
|
| 25 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/display.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Unopinionated display configuration.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import locale
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
from pandas._config import config as cf
|
| 11 |
+
|
| 12 |
+
# -----------------------------------------------------------------------------
|
| 13 |
+
# Global formatting options
|
| 14 |
+
_initial_defencoding: str | None = None
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def detect_console_encoding() -> str:
|
| 18 |
+
"""
|
| 19 |
+
Try to find the most capable encoding supported by the console.
|
| 20 |
+
slightly modified from the way IPython handles the same issue.
|
| 21 |
+
"""
|
| 22 |
+
global _initial_defencoding
|
| 23 |
+
|
| 24 |
+
encoding = None
|
| 25 |
+
try:
|
| 26 |
+
encoding = sys.stdout.encoding or sys.stdin.encoding
|
| 27 |
+
except (AttributeError, OSError):
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
# try again for something better
|
| 31 |
+
if not encoding or "ascii" in encoding.lower():
|
| 32 |
+
try:
|
| 33 |
+
encoding = locale.getpreferredencoding()
|
| 34 |
+
except locale.Error:
|
| 35 |
+
# can be raised by locale.setlocale(), which is
|
| 36 |
+
# called by getpreferredencoding
|
| 37 |
+
# (on some systems, see stdlib locale docs)
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
# when all else fails. this will usually be "ascii"
|
| 41 |
+
if not encoding or "ascii" in encoding.lower():
|
| 42 |
+
encoding = sys.getdefaultencoding()
|
| 43 |
+
|
| 44 |
+
# GH#3360, save the reported defencoding at import time
|
| 45 |
+
# MPL backends may change it. Make available for debugging.
|
| 46 |
+
if not _initial_defencoding:
|
| 47 |
+
_initial_defencoding = sys.getdefaultencoding()
|
| 48 |
+
|
| 49 |
+
return encoding
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
pc_encoding_doc = """
|
| 53 |
+
: str/unicode
|
| 54 |
+
Defaults to the detected encoding of the console.
|
| 55 |
+
Specifies the encoding to be used for strings returned by to_string,
|
| 56 |
+
these are generally strings meant to be displayed on the console.
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
with cf.config_prefix("display"):
|
| 60 |
+
cf.register_option(
|
| 61 |
+
"encoding", detect_console_encoding(), pc_encoding_doc, validator=cf.is_text
|
| 62 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_config/localization.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Helpers for configuring locale settings.
|
| 3 |
+
|
| 4 |
+
Name `localization` is chosen to avoid overlap with builtin `locale` module.
|
| 5 |
+
"""
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
from contextlib import contextmanager
|
| 9 |
+
import locale
|
| 10 |
+
import platform
|
| 11 |
+
import re
|
| 12 |
+
import subprocess
|
| 13 |
+
from typing import TYPE_CHECKING
|
| 14 |
+
|
| 15 |
+
from pandas._config.config import options
|
| 16 |
+
|
| 17 |
+
if TYPE_CHECKING:
|
| 18 |
+
from collections.abc import Generator
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@contextmanager
|
| 22 |
+
def set_locale(
|
| 23 |
+
new_locale: str | tuple[str, str], lc_var: int = locale.LC_ALL
|
| 24 |
+
) -> Generator[str | tuple[str, str], None, None]:
|
| 25 |
+
"""
|
| 26 |
+
Context manager for temporarily setting a locale.
|
| 27 |
+
|
| 28 |
+
Parameters
|
| 29 |
+
----------
|
| 30 |
+
new_locale : str or tuple
|
| 31 |
+
A string of the form <language_country>.<encoding>. For example to set
|
| 32 |
+
the current locale to US English with a UTF8 encoding, you would pass
|
| 33 |
+
"en_US.UTF-8".
|
| 34 |
+
lc_var : int, default `locale.LC_ALL`
|
| 35 |
+
The category of the locale being set.
|
| 36 |
+
|
| 37 |
+
Notes
|
| 38 |
+
-----
|
| 39 |
+
This is useful when you want to run a particular block of code under a
|
| 40 |
+
particular locale, without globally setting the locale. This probably isn't
|
| 41 |
+
thread-safe.
|
| 42 |
+
"""
|
| 43 |
+
# getlocale is not always compliant with setlocale, use setlocale. GH#46595
|
| 44 |
+
current_locale = locale.setlocale(lc_var)
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
locale.setlocale(lc_var, new_locale)
|
| 48 |
+
normalized_code, normalized_encoding = locale.getlocale()
|
| 49 |
+
if normalized_code is not None and normalized_encoding is not None:
|
| 50 |
+
yield f"{normalized_code}.{normalized_encoding}"
|
| 51 |
+
else:
|
| 52 |
+
yield new_locale
|
| 53 |
+
finally:
|
| 54 |
+
locale.setlocale(lc_var, current_locale)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def can_set_locale(lc: str, lc_var: int = locale.LC_ALL) -> bool:
|
| 58 |
+
"""
|
| 59 |
+
Check to see if we can set a locale, and subsequently get the locale,
|
| 60 |
+
without raising an Exception.
|
| 61 |
+
|
| 62 |
+
Parameters
|
| 63 |
+
----------
|
| 64 |
+
lc : str
|
| 65 |
+
The locale to attempt to set.
|
| 66 |
+
lc_var : int, default `locale.LC_ALL`
|
| 67 |
+
The category of the locale being set.
|
| 68 |
+
|
| 69 |
+
Returns
|
| 70 |
+
-------
|
| 71 |
+
bool
|
| 72 |
+
Whether the passed locale can be set
|
| 73 |
+
"""
|
| 74 |
+
try:
|
| 75 |
+
with set_locale(lc, lc_var=lc_var):
|
| 76 |
+
pass
|
| 77 |
+
except (ValueError, locale.Error):
|
| 78 |
+
# horrible name for a Exception subclass
|
| 79 |
+
return False
|
| 80 |
+
else:
|
| 81 |
+
return True
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _valid_locales(locales: list[str] | str, normalize: bool) -> list[str]:
|
| 85 |
+
"""
|
| 86 |
+
Return a list of normalized locales that do not throw an ``Exception``
|
| 87 |
+
when set.
|
| 88 |
+
|
| 89 |
+
Parameters
|
| 90 |
+
----------
|
| 91 |
+
locales : str
|
| 92 |
+
A string where each locale is separated by a newline.
|
| 93 |
+
normalize : bool
|
| 94 |
+
Whether to call ``locale.normalize`` on each locale.
|
| 95 |
+
|
| 96 |
+
Returns
|
| 97 |
+
-------
|
| 98 |
+
valid_locales : list
|
| 99 |
+
A list of valid locales.
|
| 100 |
+
"""
|
| 101 |
+
return [
|
| 102 |
+
loc
|
| 103 |
+
for loc in (
|
| 104 |
+
locale.normalize(loc.strip()) if normalize else loc.strip()
|
| 105 |
+
for loc in locales
|
| 106 |
+
)
|
| 107 |
+
if can_set_locale(loc)
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def get_locales(
|
| 112 |
+
prefix: str | None = None,
|
| 113 |
+
normalize: bool = True,
|
| 114 |
+
) -> list[str]:
|
| 115 |
+
"""
|
| 116 |
+
Get all the locales that are available on the system.
|
| 117 |
+
|
| 118 |
+
Parameters
|
| 119 |
+
----------
|
| 120 |
+
prefix : str
|
| 121 |
+
If not ``None`` then return only those locales with the prefix
|
| 122 |
+
provided. For example to get all English language locales (those that
|
| 123 |
+
start with ``"en"``), pass ``prefix="en"``.
|
| 124 |
+
normalize : bool
|
| 125 |
+
Call ``locale.normalize`` on the resulting list of available locales.
|
| 126 |
+
If ``True``, only locales that can be set without throwing an
|
| 127 |
+
``Exception`` are returned.
|
| 128 |
+
|
| 129 |
+
Returns
|
| 130 |
+
-------
|
| 131 |
+
locales : list of strings
|
| 132 |
+
A list of locale strings that can be set with ``locale.setlocale()``.
|
| 133 |
+
For example::
|
| 134 |
+
|
| 135 |
+
locale.setlocale(locale.LC_ALL, locale_string)
|
| 136 |
+
|
| 137 |
+
On error will return an empty list (no locale available, e.g. Windows)
|
| 138 |
+
|
| 139 |
+
"""
|
| 140 |
+
if platform.system() in ("Linux", "Darwin"):
|
| 141 |
+
raw_locales = subprocess.check_output(["locale", "-a"])
|
| 142 |
+
else:
|
| 143 |
+
# Other platforms e.g. windows platforms don't define "locale -a"
|
| 144 |
+
# Note: is_platform_windows causes circular import here
|
| 145 |
+
return []
|
| 146 |
+
|
| 147 |
+
try:
|
| 148 |
+
# raw_locales is "\n" separated list of locales
|
| 149 |
+
# it may contain non-decodable parts, so split
|
| 150 |
+
# extract what we can and then rejoin.
|
| 151 |
+
split_raw_locales = raw_locales.split(b"\n")
|
| 152 |
+
out_locales = []
|
| 153 |
+
for x in split_raw_locales:
|
| 154 |
+
try:
|
| 155 |
+
out_locales.append(str(x, encoding=options.display.encoding))
|
| 156 |
+
except UnicodeError:
|
| 157 |
+
# 'locale -a' is used to populated 'raw_locales' and on
|
| 158 |
+
# Redhat 7 Linux (and maybe others) prints locale names
|
| 159 |
+
# using windows-1252 encoding. Bug only triggered by
|
| 160 |
+
# a few special characters and when there is an
|
| 161 |
+
# extensive list of installed locales.
|
| 162 |
+
out_locales.append(str(x, encoding="windows-1252"))
|
| 163 |
+
|
| 164 |
+
except TypeError:
|
| 165 |
+
pass
|
| 166 |
+
|
| 167 |
+
if prefix is None:
|
| 168 |
+
return _valid_locales(out_locales, normalize)
|
| 169 |
+
|
| 170 |
+
pattern = re.compile(f"{prefix}.*")
|
| 171 |
+
found = pattern.findall("\n".join(out_locales))
|
| 172 |
+
return _valid_locales(found, normalize)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = [
|
| 2 |
+
"NaT",
|
| 3 |
+
"NaTType",
|
| 4 |
+
"OutOfBoundsDatetime",
|
| 5 |
+
"Period",
|
| 6 |
+
"Timedelta",
|
| 7 |
+
"Timestamp",
|
| 8 |
+
"iNaT",
|
| 9 |
+
"Interval",
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Below imports needs to happen first to ensure pandas top level
|
| 14 |
+
# module gets monkeypatched with the pandas_datetime_CAPI
|
| 15 |
+
# see pandas_datetime_exec in pd_datetime.c
|
| 16 |
+
import pandas._libs.pandas_parser # isort: skip # type: ignore[reportUnusedImport]
|
| 17 |
+
import pandas._libs.pandas_datetime # noqa: F401 # isort: skip # type: ignore[reportUnusedImport]
|
| 18 |
+
from pandas._libs.interval import Interval
|
| 19 |
+
from pandas._libs.tslibs import (
|
| 20 |
+
NaT,
|
| 21 |
+
NaTType,
|
| 22 |
+
OutOfBoundsDatetime,
|
| 23 |
+
Period,
|
| 24 |
+
Timedelta,
|
| 25 |
+
Timestamp,
|
| 26 |
+
iNaT,
|
| 27 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/algos.pyi
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
|
| 5 |
+
from pandas._typing import npt
|
| 6 |
+
|
| 7 |
+
class Infinity:
|
| 8 |
+
def __eq__(self, other) -> bool: ...
|
| 9 |
+
def __ne__(self, other) -> bool: ...
|
| 10 |
+
def __lt__(self, other) -> bool: ...
|
| 11 |
+
def __le__(self, other) -> bool: ...
|
| 12 |
+
def __gt__(self, other) -> bool: ...
|
| 13 |
+
def __ge__(self, other) -> bool: ...
|
| 14 |
+
|
| 15 |
+
class NegInfinity:
|
| 16 |
+
def __eq__(self, other) -> bool: ...
|
| 17 |
+
def __ne__(self, other) -> bool: ...
|
| 18 |
+
def __lt__(self, other) -> bool: ...
|
| 19 |
+
def __le__(self, other) -> bool: ...
|
| 20 |
+
def __gt__(self, other) -> bool: ...
|
| 21 |
+
def __ge__(self, other) -> bool: ...
|
| 22 |
+
|
| 23 |
+
def unique_deltas(
|
| 24 |
+
arr: np.ndarray, # const int64_t[:]
|
| 25 |
+
) -> np.ndarray: ... # np.ndarray[np.int64, ndim=1]
|
| 26 |
+
def is_lexsorted(list_of_arrays: list[npt.NDArray[np.int64]]) -> bool: ...
|
| 27 |
+
def groupsort_indexer(
|
| 28 |
+
index: np.ndarray, # const int64_t[:]
|
| 29 |
+
ngroups: int,
|
| 30 |
+
) -> tuple[
|
| 31 |
+
np.ndarray, # ndarray[int64_t, ndim=1]
|
| 32 |
+
np.ndarray, # ndarray[int64_t, ndim=1]
|
| 33 |
+
]: ...
|
| 34 |
+
def kth_smallest(
|
| 35 |
+
arr: np.ndarray, # numeric[:]
|
| 36 |
+
k: int,
|
| 37 |
+
) -> Any: ... # numeric
|
| 38 |
+
|
| 39 |
+
# ----------------------------------------------------------------------
|
| 40 |
+
# Pairwise correlation/covariance
|
| 41 |
+
|
| 42 |
+
def nancorr(
|
| 43 |
+
mat: npt.NDArray[np.float64], # const float64_t[:, :]
|
| 44 |
+
cov: bool = ...,
|
| 45 |
+
minp: int | None = ...,
|
| 46 |
+
) -> npt.NDArray[np.float64]: ... # ndarray[float64_t, ndim=2]
|
| 47 |
+
def nancorr_spearman(
|
| 48 |
+
mat: npt.NDArray[np.float64], # ndarray[float64_t, ndim=2]
|
| 49 |
+
minp: int = ...,
|
| 50 |
+
) -> npt.NDArray[np.float64]: ... # ndarray[float64_t, ndim=2]
|
| 51 |
+
|
| 52 |
+
# ----------------------------------------------------------------------
|
| 53 |
+
|
| 54 |
+
def validate_limit(nobs: int | None, limit=...) -> int: ...
|
| 55 |
+
def get_fill_indexer(
|
| 56 |
+
mask: npt.NDArray[np.bool_],
|
| 57 |
+
limit: int | None = None,
|
| 58 |
+
) -> npt.NDArray[np.intp]: ...
|
| 59 |
+
def pad(
|
| 60 |
+
old: np.ndarray, # ndarray[numeric_object_t]
|
| 61 |
+
new: np.ndarray, # ndarray[numeric_object_t]
|
| 62 |
+
limit=...,
|
| 63 |
+
) -> npt.NDArray[np.intp]: ... # np.ndarray[np.intp, ndim=1]
|
| 64 |
+
def pad_inplace(
|
| 65 |
+
values: np.ndarray, # numeric_object_t[:]
|
| 66 |
+
mask: np.ndarray, # uint8_t[:]
|
| 67 |
+
limit=...,
|
| 68 |
+
) -> None: ...
|
| 69 |
+
def pad_2d_inplace(
|
| 70 |
+
values: np.ndarray, # numeric_object_t[:, :]
|
| 71 |
+
mask: np.ndarray, # const uint8_t[:, :]
|
| 72 |
+
limit=...,
|
| 73 |
+
) -> None: ...
|
| 74 |
+
def backfill(
|
| 75 |
+
old: np.ndarray, # ndarray[numeric_object_t]
|
| 76 |
+
new: np.ndarray, # ndarray[numeric_object_t]
|
| 77 |
+
limit=...,
|
| 78 |
+
) -> npt.NDArray[np.intp]: ... # np.ndarray[np.intp, ndim=1]
|
| 79 |
+
def backfill_inplace(
|
| 80 |
+
values: np.ndarray, # numeric_object_t[:]
|
| 81 |
+
mask: np.ndarray, # uint8_t[:]
|
| 82 |
+
limit=...,
|
| 83 |
+
) -> None: ...
|
| 84 |
+
def backfill_2d_inplace(
|
| 85 |
+
values: np.ndarray, # numeric_object_t[:, :]
|
| 86 |
+
mask: np.ndarray, # const uint8_t[:, :]
|
| 87 |
+
limit=...,
|
| 88 |
+
) -> None: ...
|
| 89 |
+
def is_monotonic(
|
| 90 |
+
arr: np.ndarray, # ndarray[numeric_object_t, ndim=1]
|
| 91 |
+
timelike: bool,
|
| 92 |
+
) -> tuple[bool, bool, bool]: ...
|
| 93 |
+
|
| 94 |
+
# ----------------------------------------------------------------------
|
| 95 |
+
# rank_1d, rank_2d
|
| 96 |
+
# ----------------------------------------------------------------------
|
| 97 |
+
|
| 98 |
+
def rank_1d(
|
| 99 |
+
values: np.ndarray, # ndarray[numeric_object_t, ndim=1]
|
| 100 |
+
labels: np.ndarray | None = ..., # const int64_t[:]=None
|
| 101 |
+
is_datetimelike: bool = ...,
|
| 102 |
+
ties_method=...,
|
| 103 |
+
ascending: bool = ...,
|
| 104 |
+
pct: bool = ...,
|
| 105 |
+
na_option=...,
|
| 106 |
+
mask: npt.NDArray[np.bool_] | None = ...,
|
| 107 |
+
) -> np.ndarray: ... # np.ndarray[float64_t, ndim=1]
|
| 108 |
+
def rank_2d(
|
| 109 |
+
in_arr: np.ndarray, # ndarray[numeric_object_t, ndim=2]
|
| 110 |
+
axis: int = ...,
|
| 111 |
+
is_datetimelike: bool = ...,
|
| 112 |
+
ties_method=...,
|
| 113 |
+
ascending: bool = ...,
|
| 114 |
+
na_option=...,
|
| 115 |
+
pct: bool = ...,
|
| 116 |
+
) -> np.ndarray: ... # np.ndarray[float64_t, ndim=1]
|
| 117 |
+
def diff_2d(
|
| 118 |
+
arr: np.ndarray, # ndarray[diff_t, ndim=2]
|
| 119 |
+
out: np.ndarray, # ndarray[out_t, ndim=2]
|
| 120 |
+
periods: int,
|
| 121 |
+
axis: int,
|
| 122 |
+
datetimelike: bool = ...,
|
| 123 |
+
) -> None: ...
|
| 124 |
+
def ensure_platform_int(arr: object) -> npt.NDArray[np.intp]: ...
|
| 125 |
+
def ensure_object(arr: object) -> npt.NDArray[np.object_]: ...
|
| 126 |
+
def ensure_float64(arr: object) -> npt.NDArray[np.float64]: ...
|
| 127 |
+
def ensure_int8(arr: object) -> npt.NDArray[np.int8]: ...
|
| 128 |
+
def ensure_int16(arr: object) -> npt.NDArray[np.int16]: ...
|
| 129 |
+
def ensure_int32(arr: object) -> npt.NDArray[np.int32]: ...
|
| 130 |
+
def ensure_int64(arr: object) -> npt.NDArray[np.int64]: ...
|
| 131 |
+
def ensure_uint64(arr: object) -> npt.NDArray[np.uint64]: ...
|
| 132 |
+
def take_1d_int8_int8(
|
| 133 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 134 |
+
) -> None: ...
|
| 135 |
+
def take_1d_int8_int32(
|
| 136 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 137 |
+
) -> None: ...
|
| 138 |
+
def take_1d_int8_int64(
|
| 139 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 140 |
+
) -> None: ...
|
| 141 |
+
def take_1d_int8_float64(
|
| 142 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 143 |
+
) -> None: ...
|
| 144 |
+
def take_1d_int16_int16(
|
| 145 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 146 |
+
) -> None: ...
|
| 147 |
+
def take_1d_int16_int32(
|
| 148 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 149 |
+
) -> None: ...
|
| 150 |
+
def take_1d_int16_int64(
|
| 151 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 152 |
+
) -> None: ...
|
| 153 |
+
def take_1d_int16_float64(
|
| 154 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 155 |
+
) -> None: ...
|
| 156 |
+
def take_1d_int32_int32(
|
| 157 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 158 |
+
) -> None: ...
|
| 159 |
+
def take_1d_int32_int64(
|
| 160 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 161 |
+
) -> None: ...
|
| 162 |
+
def take_1d_int32_float64(
|
| 163 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 164 |
+
) -> None: ...
|
| 165 |
+
def take_1d_int64_int64(
|
| 166 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 167 |
+
) -> None: ...
|
| 168 |
+
def take_1d_int64_float64(
|
| 169 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 170 |
+
) -> None: ...
|
| 171 |
+
def take_1d_float32_float32(
|
| 172 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 173 |
+
) -> None: ...
|
| 174 |
+
def take_1d_float32_float64(
|
| 175 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 176 |
+
) -> None: ...
|
| 177 |
+
def take_1d_float64_float64(
|
| 178 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 179 |
+
) -> None: ...
|
| 180 |
+
def take_1d_object_object(
|
| 181 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 182 |
+
) -> None: ...
|
| 183 |
+
def take_1d_bool_bool(
|
| 184 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 185 |
+
) -> None: ...
|
| 186 |
+
def take_1d_bool_object(
|
| 187 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 188 |
+
) -> None: ...
|
| 189 |
+
def take_2d_axis0_int8_int8(
|
| 190 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 191 |
+
) -> None: ...
|
| 192 |
+
def take_2d_axis0_int8_int32(
|
| 193 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 194 |
+
) -> None: ...
|
| 195 |
+
def take_2d_axis0_int8_int64(
|
| 196 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 197 |
+
) -> None: ...
|
| 198 |
+
def take_2d_axis0_int8_float64(
|
| 199 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 200 |
+
) -> None: ...
|
| 201 |
+
def take_2d_axis0_int16_int16(
|
| 202 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 203 |
+
) -> None: ...
|
| 204 |
+
def take_2d_axis0_int16_int32(
|
| 205 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 206 |
+
) -> None: ...
|
| 207 |
+
def take_2d_axis0_int16_int64(
|
| 208 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 209 |
+
) -> None: ...
|
| 210 |
+
def take_2d_axis0_int16_float64(
|
| 211 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 212 |
+
) -> None: ...
|
| 213 |
+
def take_2d_axis0_int32_int32(
|
| 214 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 215 |
+
) -> None: ...
|
| 216 |
+
def take_2d_axis0_int32_int64(
|
| 217 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 218 |
+
) -> None: ...
|
| 219 |
+
def take_2d_axis0_int32_float64(
|
| 220 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 221 |
+
) -> None: ...
|
| 222 |
+
def take_2d_axis0_int64_int64(
|
| 223 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 224 |
+
) -> None: ...
|
| 225 |
+
def take_2d_axis0_int64_float64(
|
| 226 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 227 |
+
) -> None: ...
|
| 228 |
+
def take_2d_axis0_float32_float32(
|
| 229 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 230 |
+
) -> None: ...
|
| 231 |
+
def take_2d_axis0_float32_float64(
|
| 232 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 233 |
+
) -> None: ...
|
| 234 |
+
def take_2d_axis0_float64_float64(
|
| 235 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 236 |
+
) -> None: ...
|
| 237 |
+
def take_2d_axis0_object_object(
|
| 238 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 239 |
+
) -> None: ...
|
| 240 |
+
def take_2d_axis0_bool_bool(
|
| 241 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 242 |
+
) -> None: ...
|
| 243 |
+
def take_2d_axis0_bool_object(
|
| 244 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 245 |
+
) -> None: ...
|
| 246 |
+
def take_2d_axis1_int8_int8(
|
| 247 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 248 |
+
) -> None: ...
|
| 249 |
+
def take_2d_axis1_int8_int32(
|
| 250 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 251 |
+
) -> None: ...
|
| 252 |
+
def take_2d_axis1_int8_int64(
|
| 253 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 254 |
+
) -> None: ...
|
| 255 |
+
def take_2d_axis1_int8_float64(
|
| 256 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 257 |
+
) -> None: ...
|
| 258 |
+
def take_2d_axis1_int16_int16(
|
| 259 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 260 |
+
) -> None: ...
|
| 261 |
+
def take_2d_axis1_int16_int32(
|
| 262 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 263 |
+
) -> None: ...
|
| 264 |
+
def take_2d_axis1_int16_int64(
|
| 265 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 266 |
+
) -> None: ...
|
| 267 |
+
def take_2d_axis1_int16_float64(
|
| 268 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 269 |
+
) -> None: ...
|
| 270 |
+
def take_2d_axis1_int32_int32(
|
| 271 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 272 |
+
) -> None: ...
|
| 273 |
+
def take_2d_axis1_int32_int64(
|
| 274 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 275 |
+
) -> None: ...
|
| 276 |
+
def take_2d_axis1_int32_float64(
|
| 277 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 278 |
+
) -> None: ...
|
| 279 |
+
def take_2d_axis1_int64_int64(
|
| 280 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 281 |
+
) -> None: ...
|
| 282 |
+
def take_2d_axis1_int64_float64(
|
| 283 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 284 |
+
) -> None: ...
|
| 285 |
+
def take_2d_axis1_float32_float32(
|
| 286 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 287 |
+
) -> None: ...
|
| 288 |
+
def take_2d_axis1_float32_float64(
|
| 289 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 290 |
+
) -> None: ...
|
| 291 |
+
def take_2d_axis1_float64_float64(
|
| 292 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 293 |
+
) -> None: ...
|
| 294 |
+
def take_2d_axis1_object_object(
|
| 295 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 296 |
+
) -> None: ...
|
| 297 |
+
def take_2d_axis1_bool_bool(
|
| 298 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 299 |
+
) -> None: ...
|
| 300 |
+
def take_2d_axis1_bool_object(
|
| 301 |
+
values: np.ndarray, indexer: npt.NDArray[np.intp], out: np.ndarray, fill_value=...
|
| 302 |
+
) -> None: ...
|
| 303 |
+
def take_2d_multi_int8_int8(
|
| 304 |
+
values: np.ndarray,
|
| 305 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 306 |
+
out: np.ndarray,
|
| 307 |
+
fill_value=...,
|
| 308 |
+
) -> None: ...
|
| 309 |
+
def take_2d_multi_int8_int32(
|
| 310 |
+
values: np.ndarray,
|
| 311 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 312 |
+
out: np.ndarray,
|
| 313 |
+
fill_value=...,
|
| 314 |
+
) -> None: ...
|
| 315 |
+
def take_2d_multi_int8_int64(
|
| 316 |
+
values: np.ndarray,
|
| 317 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 318 |
+
out: np.ndarray,
|
| 319 |
+
fill_value=...,
|
| 320 |
+
) -> None: ...
|
| 321 |
+
def take_2d_multi_int8_float64(
|
| 322 |
+
values: np.ndarray,
|
| 323 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 324 |
+
out: np.ndarray,
|
| 325 |
+
fill_value=...,
|
| 326 |
+
) -> None: ...
|
| 327 |
+
def take_2d_multi_int16_int16(
|
| 328 |
+
values: np.ndarray,
|
| 329 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 330 |
+
out: np.ndarray,
|
| 331 |
+
fill_value=...,
|
| 332 |
+
) -> None: ...
|
| 333 |
+
def take_2d_multi_int16_int32(
|
| 334 |
+
values: np.ndarray,
|
| 335 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 336 |
+
out: np.ndarray,
|
| 337 |
+
fill_value=...,
|
| 338 |
+
) -> None: ...
|
| 339 |
+
def take_2d_multi_int16_int64(
|
| 340 |
+
values: np.ndarray,
|
| 341 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 342 |
+
out: np.ndarray,
|
| 343 |
+
fill_value=...,
|
| 344 |
+
) -> None: ...
|
| 345 |
+
def take_2d_multi_int16_float64(
|
| 346 |
+
values: np.ndarray,
|
| 347 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 348 |
+
out: np.ndarray,
|
| 349 |
+
fill_value=...,
|
| 350 |
+
) -> None: ...
|
| 351 |
+
def take_2d_multi_int32_int32(
|
| 352 |
+
values: np.ndarray,
|
| 353 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 354 |
+
out: np.ndarray,
|
| 355 |
+
fill_value=...,
|
| 356 |
+
) -> None: ...
|
| 357 |
+
def take_2d_multi_int32_int64(
|
| 358 |
+
values: np.ndarray,
|
| 359 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 360 |
+
out: np.ndarray,
|
| 361 |
+
fill_value=...,
|
| 362 |
+
) -> None: ...
|
| 363 |
+
def take_2d_multi_int32_float64(
|
| 364 |
+
values: np.ndarray,
|
| 365 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 366 |
+
out: np.ndarray,
|
| 367 |
+
fill_value=...,
|
| 368 |
+
) -> None: ...
|
| 369 |
+
def take_2d_multi_int64_float64(
|
| 370 |
+
values: np.ndarray,
|
| 371 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 372 |
+
out: np.ndarray,
|
| 373 |
+
fill_value=...,
|
| 374 |
+
) -> None: ...
|
| 375 |
+
def take_2d_multi_float32_float32(
|
| 376 |
+
values: np.ndarray,
|
| 377 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 378 |
+
out: np.ndarray,
|
| 379 |
+
fill_value=...,
|
| 380 |
+
) -> None: ...
|
| 381 |
+
def take_2d_multi_float32_float64(
|
| 382 |
+
values: np.ndarray,
|
| 383 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 384 |
+
out: np.ndarray,
|
| 385 |
+
fill_value=...,
|
| 386 |
+
) -> None: ...
|
| 387 |
+
def take_2d_multi_float64_float64(
|
| 388 |
+
values: np.ndarray,
|
| 389 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 390 |
+
out: np.ndarray,
|
| 391 |
+
fill_value=...,
|
| 392 |
+
) -> None: ...
|
| 393 |
+
def take_2d_multi_object_object(
|
| 394 |
+
values: np.ndarray,
|
| 395 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 396 |
+
out: np.ndarray,
|
| 397 |
+
fill_value=...,
|
| 398 |
+
) -> None: ...
|
| 399 |
+
def take_2d_multi_bool_bool(
|
| 400 |
+
values: np.ndarray,
|
| 401 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 402 |
+
out: np.ndarray,
|
| 403 |
+
fill_value=...,
|
| 404 |
+
) -> None: ...
|
| 405 |
+
def take_2d_multi_bool_object(
|
| 406 |
+
values: np.ndarray,
|
| 407 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 408 |
+
out: np.ndarray,
|
| 409 |
+
fill_value=...,
|
| 410 |
+
) -> None: ...
|
| 411 |
+
def take_2d_multi_int64_int64(
|
| 412 |
+
values: np.ndarray,
|
| 413 |
+
indexer: tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]],
|
| 414 |
+
out: np.ndarray,
|
| 415 |
+
fill_value=...,
|
| 416 |
+
) -> None: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/arrays.pyi
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Sequence
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from pandas._typing import (
|
| 6 |
+
AxisInt,
|
| 7 |
+
DtypeObj,
|
| 8 |
+
Self,
|
| 9 |
+
Shape,
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
class NDArrayBacked:
|
| 13 |
+
_dtype: DtypeObj
|
| 14 |
+
_ndarray: np.ndarray
|
| 15 |
+
def __init__(self, values: np.ndarray, dtype: DtypeObj) -> None: ...
|
| 16 |
+
@classmethod
|
| 17 |
+
def _simple_new(cls, values: np.ndarray, dtype: DtypeObj): ...
|
| 18 |
+
def _from_backing_data(self, values: np.ndarray): ...
|
| 19 |
+
def __setstate__(self, state): ...
|
| 20 |
+
def __len__(self) -> int: ...
|
| 21 |
+
@property
|
| 22 |
+
def shape(self) -> Shape: ...
|
| 23 |
+
@property
|
| 24 |
+
def ndim(self) -> int: ...
|
| 25 |
+
@property
|
| 26 |
+
def size(self) -> int: ...
|
| 27 |
+
@property
|
| 28 |
+
def nbytes(self) -> int: ...
|
| 29 |
+
def copy(self, order=...): ...
|
| 30 |
+
def delete(self, loc, axis=...): ...
|
| 31 |
+
def swapaxes(self, axis1, axis2): ...
|
| 32 |
+
def repeat(self, repeats: int | Sequence[int], axis: int | None = ...): ...
|
| 33 |
+
def reshape(self, *args, **kwargs): ...
|
| 34 |
+
def ravel(self, order=...): ...
|
| 35 |
+
@property
|
| 36 |
+
def T(self): ...
|
| 37 |
+
@classmethod
|
| 38 |
+
def _concat_same_type(
|
| 39 |
+
cls, to_concat: Sequence[Self], axis: AxisInt = ...
|
| 40 |
+
) -> Self: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/byteswap.cpython-312-x86_64-linux-gnu.so
ADDED
|
Binary file (61.7 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/byteswap.pyi
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def read_float_with_byteswap(data: bytes, offset: int, byteswap: bool) -> float: ...
|
| 2 |
+
def read_double_with_byteswap(data: bytes, offset: int, byteswap: bool) -> float: ...
|
| 3 |
+
def read_uint16_with_byteswap(data: bytes, offset: int, byteswap: bool) -> int: ...
|
| 4 |
+
def read_uint32_with_byteswap(data: bytes, offset: int, byteswap: bool) -> int: ...
|
| 5 |
+
def read_uint64_with_byteswap(data: bytes, offset: int, byteswap: bool) -> int: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/groupby.pyi
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Literal
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from pandas._typing import npt
|
| 6 |
+
|
| 7 |
+
def group_median_float64(
|
| 8 |
+
out: np.ndarray, # ndarray[float64_t, ndim=2]
|
| 9 |
+
counts: npt.NDArray[np.int64],
|
| 10 |
+
values: np.ndarray, # ndarray[float64_t, ndim=2]
|
| 11 |
+
labels: npt.NDArray[np.int64],
|
| 12 |
+
min_count: int = ..., # Py_ssize_t
|
| 13 |
+
mask: np.ndarray | None = ...,
|
| 14 |
+
result_mask: np.ndarray | None = ...,
|
| 15 |
+
) -> None: ...
|
| 16 |
+
def group_cumprod(
|
| 17 |
+
out: np.ndarray, # float64_t[:, ::1]
|
| 18 |
+
values: np.ndarray, # const float64_t[:, :]
|
| 19 |
+
labels: np.ndarray, # const int64_t[:]
|
| 20 |
+
ngroups: int,
|
| 21 |
+
is_datetimelike: bool,
|
| 22 |
+
skipna: bool = ...,
|
| 23 |
+
mask: np.ndarray | None = ...,
|
| 24 |
+
result_mask: np.ndarray | None = ...,
|
| 25 |
+
) -> None: ...
|
| 26 |
+
def group_cumsum(
|
| 27 |
+
out: np.ndarray, # int64float_t[:, ::1]
|
| 28 |
+
values: np.ndarray, # ndarray[int64float_t, ndim=2]
|
| 29 |
+
labels: np.ndarray, # const int64_t[:]
|
| 30 |
+
ngroups: int,
|
| 31 |
+
is_datetimelike: bool,
|
| 32 |
+
skipna: bool = ...,
|
| 33 |
+
mask: np.ndarray | None = ...,
|
| 34 |
+
result_mask: np.ndarray | None = ...,
|
| 35 |
+
) -> None: ...
|
| 36 |
+
def group_shift_indexer(
|
| 37 |
+
out: np.ndarray, # int64_t[::1]
|
| 38 |
+
labels: np.ndarray, # const int64_t[:]
|
| 39 |
+
ngroups: int,
|
| 40 |
+
periods: int,
|
| 41 |
+
) -> None: ...
|
| 42 |
+
def group_fillna_indexer(
|
| 43 |
+
out: np.ndarray, # ndarray[intp_t]
|
| 44 |
+
labels: np.ndarray, # ndarray[int64_t]
|
| 45 |
+
sorted_labels: npt.NDArray[np.intp],
|
| 46 |
+
mask: npt.NDArray[np.uint8],
|
| 47 |
+
limit: int, # int64_t
|
| 48 |
+
dropna: bool,
|
| 49 |
+
) -> None: ...
|
| 50 |
+
def group_any_all(
|
| 51 |
+
out: np.ndarray, # uint8_t[::1]
|
| 52 |
+
values: np.ndarray, # const uint8_t[::1]
|
| 53 |
+
labels: np.ndarray, # const int64_t[:]
|
| 54 |
+
mask: np.ndarray, # const uint8_t[::1]
|
| 55 |
+
val_test: Literal["any", "all"],
|
| 56 |
+
skipna: bool,
|
| 57 |
+
result_mask: np.ndarray | None,
|
| 58 |
+
) -> None: ...
|
| 59 |
+
def group_sum(
|
| 60 |
+
out: np.ndarray, # complexfloatingintuint_t[:, ::1]
|
| 61 |
+
counts: np.ndarray, # int64_t[::1]
|
| 62 |
+
values: np.ndarray, # ndarray[complexfloatingintuint_t, ndim=2]
|
| 63 |
+
labels: np.ndarray, # const intp_t[:]
|
| 64 |
+
mask: np.ndarray | None,
|
| 65 |
+
result_mask: np.ndarray | None = ...,
|
| 66 |
+
min_count: int = ...,
|
| 67 |
+
is_datetimelike: bool = ...,
|
| 68 |
+
) -> None: ...
|
| 69 |
+
def group_prod(
|
| 70 |
+
out: np.ndarray, # int64float_t[:, ::1]
|
| 71 |
+
counts: np.ndarray, # int64_t[::1]
|
| 72 |
+
values: np.ndarray, # ndarray[int64float_t, ndim=2]
|
| 73 |
+
labels: np.ndarray, # const intp_t[:]
|
| 74 |
+
mask: np.ndarray | None,
|
| 75 |
+
result_mask: np.ndarray | None = ...,
|
| 76 |
+
min_count: int = ...,
|
| 77 |
+
) -> None: ...
|
| 78 |
+
def group_var(
|
| 79 |
+
out: np.ndarray, # floating[:, ::1]
|
| 80 |
+
counts: np.ndarray, # int64_t[::1]
|
| 81 |
+
values: np.ndarray, # ndarray[floating, ndim=2]
|
| 82 |
+
labels: np.ndarray, # const intp_t[:]
|
| 83 |
+
min_count: int = ..., # Py_ssize_t
|
| 84 |
+
ddof: int = ..., # int64_t
|
| 85 |
+
mask: np.ndarray | None = ...,
|
| 86 |
+
result_mask: np.ndarray | None = ...,
|
| 87 |
+
is_datetimelike: bool = ...,
|
| 88 |
+
name: str = ...,
|
| 89 |
+
) -> None: ...
|
| 90 |
+
def group_skew(
|
| 91 |
+
out: np.ndarray, # float64_t[:, ::1]
|
| 92 |
+
counts: np.ndarray, # int64_t[::1]
|
| 93 |
+
values: np.ndarray, # ndarray[float64_T, ndim=2]
|
| 94 |
+
labels: np.ndarray, # const intp_t[::1]
|
| 95 |
+
mask: np.ndarray | None = ...,
|
| 96 |
+
result_mask: np.ndarray | None = ...,
|
| 97 |
+
skipna: bool = ...,
|
| 98 |
+
) -> None: ...
|
| 99 |
+
def group_mean(
|
| 100 |
+
out: np.ndarray, # floating[:, ::1]
|
| 101 |
+
counts: np.ndarray, # int64_t[::1]
|
| 102 |
+
values: np.ndarray, # ndarray[floating, ndim=2]
|
| 103 |
+
labels: np.ndarray, # const intp_t[:]
|
| 104 |
+
min_count: int = ..., # Py_ssize_t
|
| 105 |
+
is_datetimelike: bool = ..., # bint
|
| 106 |
+
mask: np.ndarray | None = ...,
|
| 107 |
+
result_mask: np.ndarray | None = ...,
|
| 108 |
+
) -> None: ...
|
| 109 |
+
def group_ohlc(
|
| 110 |
+
out: np.ndarray, # floatingintuint_t[:, ::1]
|
| 111 |
+
counts: np.ndarray, # int64_t[::1]
|
| 112 |
+
values: np.ndarray, # ndarray[floatingintuint_t, ndim=2]
|
| 113 |
+
labels: np.ndarray, # const intp_t[:]
|
| 114 |
+
min_count: int = ...,
|
| 115 |
+
mask: np.ndarray | None = ...,
|
| 116 |
+
result_mask: np.ndarray | None = ...,
|
| 117 |
+
) -> None: ...
|
| 118 |
+
def group_quantile(
|
| 119 |
+
out: npt.NDArray[np.float64],
|
| 120 |
+
values: np.ndarray, # ndarray[numeric, ndim=1]
|
| 121 |
+
labels: npt.NDArray[np.intp],
|
| 122 |
+
mask: npt.NDArray[np.uint8],
|
| 123 |
+
qs: npt.NDArray[np.float64], # const
|
| 124 |
+
starts: npt.NDArray[np.int64],
|
| 125 |
+
ends: npt.NDArray[np.int64],
|
| 126 |
+
interpolation: Literal["linear", "lower", "higher", "nearest", "midpoint"],
|
| 127 |
+
result_mask: np.ndarray | None,
|
| 128 |
+
is_datetimelike: bool,
|
| 129 |
+
) -> None: ...
|
| 130 |
+
def group_last(
|
| 131 |
+
out: np.ndarray, # rank_t[:, ::1]
|
| 132 |
+
counts: np.ndarray, # int64_t[::1]
|
| 133 |
+
values: np.ndarray, # ndarray[rank_t, ndim=2]
|
| 134 |
+
labels: np.ndarray, # const int64_t[:]
|
| 135 |
+
mask: npt.NDArray[np.bool_] | None,
|
| 136 |
+
result_mask: npt.NDArray[np.bool_] | None = ...,
|
| 137 |
+
min_count: int = ..., # Py_ssize_t
|
| 138 |
+
is_datetimelike: bool = ...,
|
| 139 |
+
skipna: bool = ...,
|
| 140 |
+
) -> None: ...
|
| 141 |
+
def group_nth(
|
| 142 |
+
out: np.ndarray, # rank_t[:, ::1]
|
| 143 |
+
counts: np.ndarray, # int64_t[::1]
|
| 144 |
+
values: np.ndarray, # ndarray[rank_t, ndim=2]
|
| 145 |
+
labels: np.ndarray, # const int64_t[:]
|
| 146 |
+
mask: npt.NDArray[np.bool_] | None,
|
| 147 |
+
result_mask: npt.NDArray[np.bool_] | None = ...,
|
| 148 |
+
min_count: int = ..., # int64_t
|
| 149 |
+
rank: int = ..., # int64_t
|
| 150 |
+
is_datetimelike: bool = ...,
|
| 151 |
+
skipna: bool = ...,
|
| 152 |
+
) -> None: ...
|
| 153 |
+
def group_rank(
|
| 154 |
+
out: np.ndarray, # float64_t[:, ::1]
|
| 155 |
+
values: np.ndarray, # ndarray[rank_t, ndim=2]
|
| 156 |
+
labels: np.ndarray, # const int64_t[:]
|
| 157 |
+
ngroups: int,
|
| 158 |
+
is_datetimelike: bool,
|
| 159 |
+
ties_method: Literal["average", "min", "max", "first", "dense"] = ...,
|
| 160 |
+
ascending: bool = ...,
|
| 161 |
+
pct: bool = ...,
|
| 162 |
+
na_option: Literal["keep", "top", "bottom"] = ...,
|
| 163 |
+
mask: npt.NDArray[np.bool_] | None = ...,
|
| 164 |
+
) -> None: ...
|
| 165 |
+
def group_max(
|
| 166 |
+
out: np.ndarray, # groupby_t[:, ::1]
|
| 167 |
+
counts: np.ndarray, # int64_t[::1]
|
| 168 |
+
values: np.ndarray, # ndarray[groupby_t, ndim=2]
|
| 169 |
+
labels: np.ndarray, # const int64_t[:]
|
| 170 |
+
min_count: int = ...,
|
| 171 |
+
is_datetimelike: bool = ...,
|
| 172 |
+
mask: np.ndarray | None = ...,
|
| 173 |
+
result_mask: np.ndarray | None = ...,
|
| 174 |
+
) -> None: ...
|
| 175 |
+
def group_min(
|
| 176 |
+
out: np.ndarray, # groupby_t[:, ::1]
|
| 177 |
+
counts: np.ndarray, # int64_t[::1]
|
| 178 |
+
values: np.ndarray, # ndarray[groupby_t, ndim=2]
|
| 179 |
+
labels: np.ndarray, # const int64_t[:]
|
| 180 |
+
min_count: int = ...,
|
| 181 |
+
is_datetimelike: bool = ...,
|
| 182 |
+
mask: np.ndarray | None = ...,
|
| 183 |
+
result_mask: np.ndarray | None = ...,
|
| 184 |
+
) -> None: ...
|
| 185 |
+
def group_idxmin_idxmax(
|
| 186 |
+
out: npt.NDArray[np.intp],
|
| 187 |
+
counts: npt.NDArray[np.int64],
|
| 188 |
+
values: np.ndarray, # ndarray[groupby_t, ndim=2]
|
| 189 |
+
labels: npt.NDArray[np.intp],
|
| 190 |
+
min_count: int = ...,
|
| 191 |
+
is_datetimelike: bool = ...,
|
| 192 |
+
mask: np.ndarray | None = ...,
|
| 193 |
+
name: str = ...,
|
| 194 |
+
skipna: bool = ...,
|
| 195 |
+
result_mask: np.ndarray | None = ...,
|
| 196 |
+
) -> None: ...
|
| 197 |
+
def group_cummin(
|
| 198 |
+
out: np.ndarray, # groupby_t[:, ::1]
|
| 199 |
+
values: np.ndarray, # ndarray[groupby_t, ndim=2]
|
| 200 |
+
labels: np.ndarray, # const int64_t[:]
|
| 201 |
+
ngroups: int,
|
| 202 |
+
is_datetimelike: bool,
|
| 203 |
+
mask: np.ndarray | None = ...,
|
| 204 |
+
result_mask: np.ndarray | None = ...,
|
| 205 |
+
skipna: bool = ...,
|
| 206 |
+
) -> None: ...
|
| 207 |
+
def group_cummax(
|
| 208 |
+
out: np.ndarray, # groupby_t[:, ::1]
|
| 209 |
+
values: np.ndarray, # ndarray[groupby_t, ndim=2]
|
| 210 |
+
labels: np.ndarray, # const int64_t[:]
|
| 211 |
+
ngroups: int,
|
| 212 |
+
is_datetimelike: bool,
|
| 213 |
+
mask: np.ndarray | None = ...,
|
| 214 |
+
result_mask: np.ndarray | None = ...,
|
| 215 |
+
skipna: bool = ...,
|
| 216 |
+
) -> None: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/hashing.pyi
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from pandas._typing import npt
|
| 4 |
+
|
| 5 |
+
def hash_object_array(
|
| 6 |
+
arr: npt.NDArray[np.object_],
|
| 7 |
+
key: str,
|
| 8 |
+
encoding: str = ...,
|
| 9 |
+
) -> npt.NDArray[np.uint64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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import (
|
| 2 |
+
Any,
|
| 3 |
+
Hashable,
|
| 4 |
+
Literal,
|
| 5 |
+
)
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
from pandas._typing import npt
|
| 10 |
+
|
| 11 |
+
def unique_label_indices(
|
| 12 |
+
labels: np.ndarray, # const int64_t[:]
|
| 13 |
+
) -> np.ndarray: ...
|
| 14 |
+
|
| 15 |
+
class Factorizer:
|
| 16 |
+
count: int
|
| 17 |
+
uniques: Any
|
| 18 |
+
def __init__(self, size_hint: int) -> None: ...
|
| 19 |
+
def get_count(self) -> int: ...
|
| 20 |
+
def factorize(
|
| 21 |
+
self,
|
| 22 |
+
values: np.ndarray,
|
| 23 |
+
na_sentinel=...,
|
| 24 |
+
na_value=...,
|
| 25 |
+
mask=...,
|
| 26 |
+
) -> npt.NDArray[np.intp]: ...
|
| 27 |
+
|
| 28 |
+
class ObjectFactorizer(Factorizer):
|
| 29 |
+
table: PyObjectHashTable
|
| 30 |
+
uniques: ObjectVector
|
| 31 |
+
|
| 32 |
+
class Int64Factorizer(Factorizer):
|
| 33 |
+
table: Int64HashTable
|
| 34 |
+
uniques: Int64Vector
|
| 35 |
+
|
| 36 |
+
class UInt64Factorizer(Factorizer):
|
| 37 |
+
table: UInt64HashTable
|
| 38 |
+
uniques: UInt64Vector
|
| 39 |
+
|
| 40 |
+
class Int32Factorizer(Factorizer):
|
| 41 |
+
table: Int32HashTable
|
| 42 |
+
uniques: Int32Vector
|
| 43 |
+
|
| 44 |
+
class UInt32Factorizer(Factorizer):
|
| 45 |
+
table: UInt32HashTable
|
| 46 |
+
uniques: UInt32Vector
|
| 47 |
+
|
| 48 |
+
class Int16Factorizer(Factorizer):
|
| 49 |
+
table: Int16HashTable
|
| 50 |
+
uniques: Int16Vector
|
| 51 |
+
|
| 52 |
+
class UInt16Factorizer(Factorizer):
|
| 53 |
+
table: UInt16HashTable
|
| 54 |
+
uniques: UInt16Vector
|
| 55 |
+
|
| 56 |
+
class Int8Factorizer(Factorizer):
|
| 57 |
+
table: Int8HashTable
|
| 58 |
+
uniques: Int8Vector
|
| 59 |
+
|
| 60 |
+
class UInt8Factorizer(Factorizer):
|
| 61 |
+
table: UInt8HashTable
|
| 62 |
+
uniques: UInt8Vector
|
| 63 |
+
|
| 64 |
+
class Float64Factorizer(Factorizer):
|
| 65 |
+
table: Float64HashTable
|
| 66 |
+
uniques: Float64Vector
|
| 67 |
+
|
| 68 |
+
class Float32Factorizer(Factorizer):
|
| 69 |
+
table: Float32HashTable
|
| 70 |
+
uniques: Float32Vector
|
| 71 |
+
|
| 72 |
+
class Complex64Factorizer(Factorizer):
|
| 73 |
+
table: Complex64HashTable
|
| 74 |
+
uniques: Complex64Vector
|
| 75 |
+
|
| 76 |
+
class Complex128Factorizer(Factorizer):
|
| 77 |
+
table: Complex128HashTable
|
| 78 |
+
uniques: Complex128Vector
|
| 79 |
+
|
| 80 |
+
class Int64Vector:
|
| 81 |
+
def __init__(self, *args) -> None: ...
|
| 82 |
+
def __len__(self) -> int: ...
|
| 83 |
+
def to_array(self) -> npt.NDArray[np.int64]: ...
|
| 84 |
+
|
| 85 |
+
class Int32Vector:
|
| 86 |
+
def __init__(self, *args) -> None: ...
|
| 87 |
+
def __len__(self) -> int: ...
|
| 88 |
+
def to_array(self) -> npt.NDArray[np.int32]: ...
|
| 89 |
+
|
| 90 |
+
class Int16Vector:
|
| 91 |
+
def __init__(self, *args) -> None: ...
|
| 92 |
+
def __len__(self) -> int: ...
|
| 93 |
+
def to_array(self) -> npt.NDArray[np.int16]: ...
|
| 94 |
+
|
| 95 |
+
class Int8Vector:
|
| 96 |
+
def __init__(self, *args) -> None: ...
|
| 97 |
+
def __len__(self) -> int: ...
|
| 98 |
+
def to_array(self) -> npt.NDArray[np.int8]: ...
|
| 99 |
+
|
| 100 |
+
class UInt64Vector:
|
| 101 |
+
def __init__(self, *args) -> None: ...
|
| 102 |
+
def __len__(self) -> int: ...
|
| 103 |
+
def to_array(self) -> npt.NDArray[np.uint64]: ...
|
| 104 |
+
|
| 105 |
+
class UInt32Vector:
|
| 106 |
+
def __init__(self, *args) -> None: ...
|
| 107 |
+
def __len__(self) -> int: ...
|
| 108 |
+
def to_array(self) -> npt.NDArray[np.uint32]: ...
|
| 109 |
+
|
| 110 |
+
class UInt16Vector:
|
| 111 |
+
def __init__(self, *args) -> None: ...
|
| 112 |
+
def __len__(self) -> int: ...
|
| 113 |
+
def to_array(self) -> npt.NDArray[np.uint16]: ...
|
| 114 |
+
|
| 115 |
+
class UInt8Vector:
|
| 116 |
+
def __init__(self, *args) -> None: ...
|
| 117 |
+
def __len__(self) -> int: ...
|
| 118 |
+
def to_array(self) -> npt.NDArray[np.uint8]: ...
|
| 119 |
+
|
| 120 |
+
class Float64Vector:
|
| 121 |
+
def __init__(self, *args) -> None: ...
|
| 122 |
+
def __len__(self) -> int: ...
|
| 123 |
+
def to_array(self) -> npt.NDArray[np.float64]: ...
|
| 124 |
+
|
| 125 |
+
class Float32Vector:
|
| 126 |
+
def __init__(self, *args) -> None: ...
|
| 127 |
+
def __len__(self) -> int: ...
|
| 128 |
+
def to_array(self) -> npt.NDArray[np.float32]: ...
|
| 129 |
+
|
| 130 |
+
class Complex128Vector:
|
| 131 |
+
def __init__(self, *args) -> None: ...
|
| 132 |
+
def __len__(self) -> int: ...
|
| 133 |
+
def to_array(self) -> npt.NDArray[np.complex128]: ...
|
| 134 |
+
|
| 135 |
+
class Complex64Vector:
|
| 136 |
+
def __init__(self, *args) -> None: ...
|
| 137 |
+
def __len__(self) -> int: ...
|
| 138 |
+
def to_array(self) -> npt.NDArray[np.complex64]: ...
|
| 139 |
+
|
| 140 |
+
class StringVector:
|
| 141 |
+
def __init__(self, *args) -> None: ...
|
| 142 |
+
def __len__(self) -> int: ...
|
| 143 |
+
def to_array(self) -> npt.NDArray[np.object_]: ...
|
| 144 |
+
|
| 145 |
+
class ObjectVector:
|
| 146 |
+
def __init__(self, *args) -> None: ...
|
| 147 |
+
def __len__(self) -> int: ...
|
| 148 |
+
def to_array(self) -> npt.NDArray[np.object_]: ...
|
| 149 |
+
|
| 150 |
+
class HashTable:
|
| 151 |
+
# NB: The base HashTable class does _not_ actually have these methods;
|
| 152 |
+
# we are putting them here for the sake of mypy to avoid
|
| 153 |
+
# reproducing them in each subclass below.
|
| 154 |
+
def __init__(self, size_hint: int = ..., uses_mask: bool = ...) -> None: ...
|
| 155 |
+
def __len__(self) -> int: ...
|
| 156 |
+
def __contains__(self, key: Hashable) -> bool: ...
|
| 157 |
+
def sizeof(self, deep: bool = ...) -> int: ...
|
| 158 |
+
def get_state(self) -> dict[str, int]: ...
|
| 159 |
+
# TODO: `val/key` type is subclass-specific
|
| 160 |
+
def get_item(self, val): ... # TODO: return type?
|
| 161 |
+
def set_item(self, key, val) -> None: ...
|
| 162 |
+
def get_na(self): ... # TODO: return type?
|
| 163 |
+
def set_na(self, val) -> None: ...
|
| 164 |
+
def map_locations(
|
| 165 |
+
self,
|
| 166 |
+
values: np.ndarray, # np.ndarray[subclass-specific]
|
| 167 |
+
mask: npt.NDArray[np.bool_] | None = ...,
|
| 168 |
+
) -> None: ...
|
| 169 |
+
def lookup(
|
| 170 |
+
self,
|
| 171 |
+
values: np.ndarray, # np.ndarray[subclass-specific]
|
| 172 |
+
mask: npt.NDArray[np.bool_] | None = ...,
|
| 173 |
+
) -> npt.NDArray[np.intp]: ...
|
| 174 |
+
def get_labels(
|
| 175 |
+
self,
|
| 176 |
+
values: np.ndarray, # np.ndarray[subclass-specific]
|
| 177 |
+
uniques, # SubclassTypeVector
|
| 178 |
+
count_prior: int = ...,
|
| 179 |
+
na_sentinel: int = ...,
|
| 180 |
+
na_value: object = ...,
|
| 181 |
+
mask=...,
|
| 182 |
+
) -> npt.NDArray[np.intp]: ...
|
| 183 |
+
def unique(
|
| 184 |
+
self,
|
| 185 |
+
values: np.ndarray, # np.ndarray[subclass-specific]
|
| 186 |
+
return_inverse: bool = ...,
|
| 187 |
+
mask=...,
|
| 188 |
+
) -> (
|
| 189 |
+
tuple[
|
| 190 |
+
np.ndarray, # np.ndarray[subclass-specific]
|
| 191 |
+
npt.NDArray[np.intp],
|
| 192 |
+
]
|
| 193 |
+
| np.ndarray
|
| 194 |
+
): ... # np.ndarray[subclass-specific]
|
| 195 |
+
def factorize(
|
| 196 |
+
self,
|
| 197 |
+
values: np.ndarray, # np.ndarray[subclass-specific]
|
| 198 |
+
na_sentinel: int = ...,
|
| 199 |
+
na_value: object = ...,
|
| 200 |
+
mask=...,
|
| 201 |
+
ignore_na: bool = True,
|
| 202 |
+
) -> tuple[np.ndarray, npt.NDArray[np.intp]]: ... # np.ndarray[subclass-specific]
|
| 203 |
+
|
| 204 |
+
class Complex128HashTable(HashTable): ...
|
| 205 |
+
class Complex64HashTable(HashTable): ...
|
| 206 |
+
class Float64HashTable(HashTable): ...
|
| 207 |
+
class Float32HashTable(HashTable): ...
|
| 208 |
+
|
| 209 |
+
class Int64HashTable(HashTable):
|
| 210 |
+
# Only Int64HashTable has get_labels_groupby, map_keys_to_values
|
| 211 |
+
def get_labels_groupby(
|
| 212 |
+
self,
|
| 213 |
+
values: npt.NDArray[np.int64], # const int64_t[:]
|
| 214 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.int64]]: ...
|
| 215 |
+
def map_keys_to_values(
|
| 216 |
+
self,
|
| 217 |
+
keys: npt.NDArray[np.int64],
|
| 218 |
+
values: npt.NDArray[np.int64], # const int64_t[:]
|
| 219 |
+
) -> None: ...
|
| 220 |
+
|
| 221 |
+
class Int32HashTable(HashTable): ...
|
| 222 |
+
class Int16HashTable(HashTable): ...
|
| 223 |
+
class Int8HashTable(HashTable): ...
|
| 224 |
+
class UInt64HashTable(HashTable): ...
|
| 225 |
+
class UInt32HashTable(HashTable): ...
|
| 226 |
+
class UInt16HashTable(HashTable): ...
|
| 227 |
+
class UInt8HashTable(HashTable): ...
|
| 228 |
+
class StringHashTable(HashTable): ...
|
| 229 |
+
class PyObjectHashTable(HashTable): ...
|
| 230 |
+
class IntpHashTable(HashTable): ...
|
| 231 |
+
|
| 232 |
+
def duplicated(
|
| 233 |
+
values: np.ndarray,
|
| 234 |
+
keep: Literal["last", "first", False] = ...,
|
| 235 |
+
mask: npt.NDArray[np.bool_] | None = ...,
|
| 236 |
+
) -> npt.NDArray[np.bool_]: ...
|
| 237 |
+
def mode(
|
| 238 |
+
values: np.ndarray, dropna: bool, mask: npt.NDArray[np.bool_] | None = ...
|
| 239 |
+
) -> np.ndarray: ...
|
| 240 |
+
def value_count(
|
| 241 |
+
values: np.ndarray,
|
| 242 |
+
dropna: bool,
|
| 243 |
+
mask: npt.NDArray[np.bool_] | None = ...,
|
| 244 |
+
) -> tuple[np.ndarray, npt.NDArray[np.int64], int]: ... # np.ndarray[same-as-values]
|
| 245 |
+
|
| 246 |
+
# arr and values should have same dtype
|
| 247 |
+
def ismember(
|
| 248 |
+
arr: np.ndarray,
|
| 249 |
+
values: np.ndarray,
|
| 250 |
+
) -> npt.NDArray[np.bool_]: ...
|
| 251 |
+
def object_hash(obj) -> int: ...
|
| 252 |
+
def objects_are_equal(a, b) -> bool: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/index.pyi
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from pandas._typing import npt
|
| 4 |
+
|
| 5 |
+
from pandas import MultiIndex
|
| 6 |
+
from pandas.core.arrays import ExtensionArray
|
| 7 |
+
|
| 8 |
+
multiindex_nulls_shift: int
|
| 9 |
+
|
| 10 |
+
class IndexEngine:
|
| 11 |
+
over_size_threshold: bool
|
| 12 |
+
def __init__(self, values: np.ndarray) -> None: ...
|
| 13 |
+
def __contains__(self, val: object) -> bool: ...
|
| 14 |
+
|
| 15 |
+
# -> int | slice | np.ndarray[bool]
|
| 16 |
+
def get_loc(self, val: object) -> int | slice | np.ndarray: ...
|
| 17 |
+
def sizeof(self, deep: bool = ...) -> int: ...
|
| 18 |
+
def __sizeof__(self) -> int: ...
|
| 19 |
+
@property
|
| 20 |
+
def is_unique(self) -> bool: ...
|
| 21 |
+
@property
|
| 22 |
+
def is_monotonic_increasing(self) -> bool: ...
|
| 23 |
+
@property
|
| 24 |
+
def is_monotonic_decreasing(self) -> bool: ...
|
| 25 |
+
@property
|
| 26 |
+
def is_mapping_populated(self) -> bool: ...
|
| 27 |
+
def clear_mapping(self): ...
|
| 28 |
+
def get_indexer(self, values: np.ndarray) -> npt.NDArray[np.intp]: ...
|
| 29 |
+
def get_indexer_non_unique(
|
| 30 |
+
self,
|
| 31 |
+
targets: np.ndarray,
|
| 32 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 33 |
+
|
| 34 |
+
class MaskedIndexEngine(IndexEngine):
|
| 35 |
+
def __init__(self, values: object) -> None: ...
|
| 36 |
+
def get_indexer_non_unique(
|
| 37 |
+
self, targets: object
|
| 38 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 39 |
+
|
| 40 |
+
class Float64Engine(IndexEngine): ...
|
| 41 |
+
class Float32Engine(IndexEngine): ...
|
| 42 |
+
class Complex128Engine(IndexEngine): ...
|
| 43 |
+
class Complex64Engine(IndexEngine): ...
|
| 44 |
+
class Int64Engine(IndexEngine): ...
|
| 45 |
+
class Int32Engine(IndexEngine): ...
|
| 46 |
+
class Int16Engine(IndexEngine): ...
|
| 47 |
+
class Int8Engine(IndexEngine): ...
|
| 48 |
+
class UInt64Engine(IndexEngine): ...
|
| 49 |
+
class UInt32Engine(IndexEngine): ...
|
| 50 |
+
class UInt16Engine(IndexEngine): ...
|
| 51 |
+
class UInt8Engine(IndexEngine): ...
|
| 52 |
+
class ObjectEngine(IndexEngine): ...
|
| 53 |
+
class DatetimeEngine(Int64Engine): ...
|
| 54 |
+
class TimedeltaEngine(DatetimeEngine): ...
|
| 55 |
+
class PeriodEngine(Int64Engine): ...
|
| 56 |
+
class BoolEngine(UInt8Engine): ...
|
| 57 |
+
class MaskedFloat64Engine(MaskedIndexEngine): ...
|
| 58 |
+
class MaskedFloat32Engine(MaskedIndexEngine): ...
|
| 59 |
+
class MaskedComplex128Engine(MaskedIndexEngine): ...
|
| 60 |
+
class MaskedComplex64Engine(MaskedIndexEngine): ...
|
| 61 |
+
class MaskedInt64Engine(MaskedIndexEngine): ...
|
| 62 |
+
class MaskedInt32Engine(MaskedIndexEngine): ...
|
| 63 |
+
class MaskedInt16Engine(MaskedIndexEngine): ...
|
| 64 |
+
class MaskedInt8Engine(MaskedIndexEngine): ...
|
| 65 |
+
class MaskedUInt64Engine(MaskedIndexEngine): ...
|
| 66 |
+
class MaskedUInt32Engine(MaskedIndexEngine): ...
|
| 67 |
+
class MaskedUInt16Engine(MaskedIndexEngine): ...
|
| 68 |
+
class MaskedUInt8Engine(MaskedIndexEngine): ...
|
| 69 |
+
class MaskedBoolEngine(MaskedUInt8Engine): ...
|
| 70 |
+
|
| 71 |
+
class BaseMultiIndexCodesEngine:
|
| 72 |
+
levels: list[np.ndarray]
|
| 73 |
+
offsets: np.ndarray # ndarray[uint64_t, ndim=1]
|
| 74 |
+
|
| 75 |
+
def __init__(
|
| 76 |
+
self,
|
| 77 |
+
levels: list[np.ndarray], # all entries hashable
|
| 78 |
+
labels: list[np.ndarray], # all entries integer-dtyped
|
| 79 |
+
offsets: np.ndarray, # np.ndarray[np.uint64, ndim=1]
|
| 80 |
+
) -> None: ...
|
| 81 |
+
def get_indexer(self, target: npt.NDArray[np.object_]) -> npt.NDArray[np.intp]: ...
|
| 82 |
+
def _extract_level_codes(self, target: MultiIndex) -> np.ndarray: ...
|
| 83 |
+
|
| 84 |
+
class ExtensionEngine:
|
| 85 |
+
def __init__(self, values: ExtensionArray) -> None: ...
|
| 86 |
+
def __contains__(self, val: object) -> bool: ...
|
| 87 |
+
def get_loc(self, val: object) -> int | slice | np.ndarray: ...
|
| 88 |
+
def get_indexer(self, values: np.ndarray) -> npt.NDArray[np.intp]: ...
|
| 89 |
+
def get_indexer_non_unique(
|
| 90 |
+
self,
|
| 91 |
+
targets: np.ndarray,
|
| 92 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 93 |
+
@property
|
| 94 |
+
def is_unique(self) -> bool: ...
|
| 95 |
+
@property
|
| 96 |
+
def is_monotonic_increasing(self) -> bool: ...
|
| 97 |
+
@property
|
| 98 |
+
def is_monotonic_decreasing(self) -> bool: ...
|
| 99 |
+
def sizeof(self, deep: bool = ...) -> int: ...
|
| 100 |
+
def clear_mapping(self): ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/indexing.cpython-312-x86_64-linux-gnu.so
ADDED
|
Binary file (70.7 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/indexing.pyi
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import (
|
| 2 |
+
Generic,
|
| 3 |
+
TypeVar,
|
| 4 |
+
)
|
| 5 |
+
|
| 6 |
+
from pandas.core.indexing import IndexingMixin
|
| 7 |
+
|
| 8 |
+
_IndexingMixinT = TypeVar("_IndexingMixinT", bound=IndexingMixin)
|
| 9 |
+
|
| 10 |
+
class NDFrameIndexerBase(Generic[_IndexingMixinT]):
|
| 11 |
+
name: str
|
| 12 |
+
# in practice obj is either a DataFrame or a Series
|
| 13 |
+
obj: _IndexingMixinT
|
| 14 |
+
|
| 15 |
+
def __init__(self, name: str, obj: _IndexingMixinT) -> None: ...
|
| 16 |
+
@property
|
| 17 |
+
def ndim(self) -> int: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/internals.pyi
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import (
|
| 2 |
+
Iterator,
|
| 3 |
+
Sequence,
|
| 4 |
+
final,
|
| 5 |
+
overload,
|
| 6 |
+
)
|
| 7 |
+
import weakref
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
|
| 11 |
+
from pandas._typing import (
|
| 12 |
+
ArrayLike,
|
| 13 |
+
Self,
|
| 14 |
+
npt,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
from pandas import Index
|
| 18 |
+
from pandas.core.internals.blocks import Block as B
|
| 19 |
+
|
| 20 |
+
def slice_len(slc: slice, objlen: int = ...) -> int: ...
|
| 21 |
+
def get_concat_blkno_indexers(
|
| 22 |
+
blknos_list: list[npt.NDArray[np.intp]],
|
| 23 |
+
) -> list[tuple[npt.NDArray[np.intp], BlockPlacement]]: ...
|
| 24 |
+
def get_blkno_indexers(
|
| 25 |
+
blknos: np.ndarray, # int64_t[:]
|
| 26 |
+
group: bool = ...,
|
| 27 |
+
) -> list[tuple[int, slice | np.ndarray]]: ...
|
| 28 |
+
def get_blkno_placements(
|
| 29 |
+
blknos: np.ndarray,
|
| 30 |
+
group: bool = ...,
|
| 31 |
+
) -> Iterator[tuple[int, BlockPlacement]]: ...
|
| 32 |
+
def update_blklocs_and_blknos(
|
| 33 |
+
blklocs: npt.NDArray[np.intp],
|
| 34 |
+
blknos: npt.NDArray[np.intp],
|
| 35 |
+
loc: int,
|
| 36 |
+
nblocks: int,
|
| 37 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 38 |
+
@final
|
| 39 |
+
class BlockPlacement:
|
| 40 |
+
def __init__(self, val: int | slice | np.ndarray) -> None: ...
|
| 41 |
+
@property
|
| 42 |
+
def indexer(self) -> np.ndarray | slice: ...
|
| 43 |
+
@property
|
| 44 |
+
def as_array(self) -> np.ndarray: ...
|
| 45 |
+
@property
|
| 46 |
+
def as_slice(self) -> slice: ...
|
| 47 |
+
@property
|
| 48 |
+
def is_slice_like(self) -> bool: ...
|
| 49 |
+
@overload
|
| 50 |
+
def __getitem__(
|
| 51 |
+
self, loc: slice | Sequence[int] | npt.NDArray[np.intp]
|
| 52 |
+
) -> BlockPlacement: ...
|
| 53 |
+
@overload
|
| 54 |
+
def __getitem__(self, loc: int) -> int: ...
|
| 55 |
+
def __iter__(self) -> Iterator[int]: ...
|
| 56 |
+
def __len__(self) -> int: ...
|
| 57 |
+
def delete(self, loc) -> BlockPlacement: ...
|
| 58 |
+
def add(self, other) -> BlockPlacement: ...
|
| 59 |
+
def append(self, others: list[BlockPlacement]) -> BlockPlacement: ...
|
| 60 |
+
def tile_for_unstack(self, factor: int) -> npt.NDArray[np.intp]: ...
|
| 61 |
+
|
| 62 |
+
class Block:
|
| 63 |
+
_mgr_locs: BlockPlacement
|
| 64 |
+
ndim: int
|
| 65 |
+
values: ArrayLike
|
| 66 |
+
refs: BlockValuesRefs
|
| 67 |
+
def __init__(
|
| 68 |
+
self,
|
| 69 |
+
values: ArrayLike,
|
| 70 |
+
placement: BlockPlacement,
|
| 71 |
+
ndim: int,
|
| 72 |
+
refs: BlockValuesRefs | None = ...,
|
| 73 |
+
) -> None: ...
|
| 74 |
+
def slice_block_rows(self, slicer: slice) -> Self: ...
|
| 75 |
+
|
| 76 |
+
class BlockManager:
|
| 77 |
+
blocks: tuple[B, ...]
|
| 78 |
+
axes: list[Index]
|
| 79 |
+
_known_consolidated: bool
|
| 80 |
+
_is_consolidated: bool
|
| 81 |
+
_blknos: np.ndarray
|
| 82 |
+
_blklocs: np.ndarray
|
| 83 |
+
def __init__(
|
| 84 |
+
self, blocks: tuple[B, ...], axes: list[Index], verify_integrity=...
|
| 85 |
+
) -> None: ...
|
| 86 |
+
def get_slice(self, slobj: slice, axis: int = ...) -> Self: ...
|
| 87 |
+
def _rebuild_blknos_and_blklocs(self) -> None: ...
|
| 88 |
+
|
| 89 |
+
class BlockValuesRefs:
|
| 90 |
+
referenced_blocks: list[weakref.ref]
|
| 91 |
+
def __init__(self, blk: Block | None = ...) -> None: ...
|
| 92 |
+
def add_reference(self, blk: Block) -> None: ...
|
| 93 |
+
def add_index_reference(self, index: Index) -> None: ...
|
| 94 |
+
def has_reference(self) -> bool: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/interval.pyi
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
import numpy.typing as npt
|
| 10 |
+
|
| 11 |
+
from pandas._typing import (
|
| 12 |
+
IntervalClosedType,
|
| 13 |
+
Timedelta,
|
| 14 |
+
Timestamp,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
VALID_CLOSED: frozenset[str]
|
| 18 |
+
|
| 19 |
+
_OrderableScalarT = TypeVar("_OrderableScalarT", int, float)
|
| 20 |
+
_OrderableTimesT = TypeVar("_OrderableTimesT", Timestamp, Timedelta)
|
| 21 |
+
_OrderableT = TypeVar("_OrderableT", int, float, Timestamp, Timedelta)
|
| 22 |
+
|
| 23 |
+
class _LengthDescriptor:
|
| 24 |
+
@overload
|
| 25 |
+
def __get__(
|
| 26 |
+
self, instance: Interval[_OrderableScalarT], owner: Any
|
| 27 |
+
) -> _OrderableScalarT: ...
|
| 28 |
+
@overload
|
| 29 |
+
def __get__(
|
| 30 |
+
self, instance: Interval[_OrderableTimesT], owner: Any
|
| 31 |
+
) -> Timedelta: ...
|
| 32 |
+
|
| 33 |
+
class _MidDescriptor:
|
| 34 |
+
@overload
|
| 35 |
+
def __get__(self, instance: Interval[_OrderableScalarT], owner: Any) -> float: ...
|
| 36 |
+
@overload
|
| 37 |
+
def __get__(
|
| 38 |
+
self, instance: Interval[_OrderableTimesT], owner: Any
|
| 39 |
+
) -> _OrderableTimesT: ...
|
| 40 |
+
|
| 41 |
+
class IntervalMixin:
|
| 42 |
+
@property
|
| 43 |
+
def closed_left(self) -> bool: ...
|
| 44 |
+
@property
|
| 45 |
+
def closed_right(self) -> bool: ...
|
| 46 |
+
@property
|
| 47 |
+
def open_left(self) -> bool: ...
|
| 48 |
+
@property
|
| 49 |
+
def open_right(self) -> bool: ...
|
| 50 |
+
@property
|
| 51 |
+
def is_empty(self) -> bool: ...
|
| 52 |
+
def _check_closed_matches(self, other: IntervalMixin, name: str = ...) -> None: ...
|
| 53 |
+
|
| 54 |
+
class Interval(IntervalMixin, Generic[_OrderableT]):
|
| 55 |
+
@property
|
| 56 |
+
def left(self: Interval[_OrderableT]) -> _OrderableT: ...
|
| 57 |
+
@property
|
| 58 |
+
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
|
| 59 |
+
@property
|
| 60 |
+
def closed(self) -> IntervalClosedType: ...
|
| 61 |
+
mid: _MidDescriptor
|
| 62 |
+
length: _LengthDescriptor
|
| 63 |
+
def __init__(
|
| 64 |
+
self,
|
| 65 |
+
left: _OrderableT,
|
| 66 |
+
right: _OrderableT,
|
| 67 |
+
closed: IntervalClosedType = ...,
|
| 68 |
+
) -> None: ...
|
| 69 |
+
def __hash__(self) -> int: ...
|
| 70 |
+
@overload
|
| 71 |
+
def __contains__(
|
| 72 |
+
self: Interval[Timedelta], key: Timedelta | Interval[Timedelta]
|
| 73 |
+
) -> bool: ...
|
| 74 |
+
@overload
|
| 75 |
+
def __contains__(
|
| 76 |
+
self: Interval[Timestamp], key: Timestamp | Interval[Timestamp]
|
| 77 |
+
) -> bool: ...
|
| 78 |
+
@overload
|
| 79 |
+
def __contains__(
|
| 80 |
+
self: Interval[_OrderableScalarT],
|
| 81 |
+
key: _OrderableScalarT | Interval[_OrderableScalarT],
|
| 82 |
+
) -> bool: ...
|
| 83 |
+
@overload
|
| 84 |
+
def __add__(
|
| 85 |
+
self: Interval[_OrderableTimesT], y: Timedelta
|
| 86 |
+
) -> Interval[_OrderableTimesT]: ...
|
| 87 |
+
@overload
|
| 88 |
+
def __add__(
|
| 89 |
+
self: Interval[int], y: _OrderableScalarT
|
| 90 |
+
) -> Interval[_OrderableScalarT]: ...
|
| 91 |
+
@overload
|
| 92 |
+
def __add__(self: Interval[float], y: float) -> Interval[float]: ...
|
| 93 |
+
@overload
|
| 94 |
+
def __radd__(
|
| 95 |
+
self: Interval[_OrderableTimesT], y: Timedelta
|
| 96 |
+
) -> Interval[_OrderableTimesT]: ...
|
| 97 |
+
@overload
|
| 98 |
+
def __radd__(
|
| 99 |
+
self: Interval[int], y: _OrderableScalarT
|
| 100 |
+
) -> Interval[_OrderableScalarT]: ...
|
| 101 |
+
@overload
|
| 102 |
+
def __radd__(self: Interval[float], y: float) -> Interval[float]: ...
|
| 103 |
+
@overload
|
| 104 |
+
def __sub__(
|
| 105 |
+
self: Interval[_OrderableTimesT], y: Timedelta
|
| 106 |
+
) -> Interval[_OrderableTimesT]: ...
|
| 107 |
+
@overload
|
| 108 |
+
def __sub__(
|
| 109 |
+
self: Interval[int], y: _OrderableScalarT
|
| 110 |
+
) -> Interval[_OrderableScalarT]: ...
|
| 111 |
+
@overload
|
| 112 |
+
def __sub__(self: Interval[float], y: float) -> Interval[float]: ...
|
| 113 |
+
@overload
|
| 114 |
+
def __rsub__(
|
| 115 |
+
self: Interval[_OrderableTimesT], y: Timedelta
|
| 116 |
+
) -> Interval[_OrderableTimesT]: ...
|
| 117 |
+
@overload
|
| 118 |
+
def __rsub__(
|
| 119 |
+
self: Interval[int], y: _OrderableScalarT
|
| 120 |
+
) -> Interval[_OrderableScalarT]: ...
|
| 121 |
+
@overload
|
| 122 |
+
def __rsub__(self: Interval[float], y: float) -> Interval[float]: ...
|
| 123 |
+
@overload
|
| 124 |
+
def __mul__(
|
| 125 |
+
self: Interval[int], y: _OrderableScalarT
|
| 126 |
+
) -> Interval[_OrderableScalarT]: ...
|
| 127 |
+
@overload
|
| 128 |
+
def __mul__(self: Interval[float], y: float) -> Interval[float]: ...
|
| 129 |
+
@overload
|
| 130 |
+
def __rmul__(
|
| 131 |
+
self: Interval[int], y: _OrderableScalarT
|
| 132 |
+
) -> Interval[_OrderableScalarT]: ...
|
| 133 |
+
@overload
|
| 134 |
+
def __rmul__(self: Interval[float], y: float) -> Interval[float]: ...
|
| 135 |
+
@overload
|
| 136 |
+
def __truediv__(
|
| 137 |
+
self: Interval[int], y: _OrderableScalarT
|
| 138 |
+
) -> Interval[_OrderableScalarT]: ...
|
| 139 |
+
@overload
|
| 140 |
+
def __truediv__(self: Interval[float], y: float) -> Interval[float]: ...
|
| 141 |
+
@overload
|
| 142 |
+
def __floordiv__(
|
| 143 |
+
self: Interval[int], y: _OrderableScalarT
|
| 144 |
+
) -> Interval[_OrderableScalarT]: ...
|
| 145 |
+
@overload
|
| 146 |
+
def __floordiv__(self: Interval[float], y: float) -> Interval[float]: ...
|
| 147 |
+
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...
|
| 148 |
+
|
| 149 |
+
def intervals_to_interval_bounds(
|
| 150 |
+
intervals: np.ndarray, validate_closed: bool = ...
|
| 151 |
+
) -> tuple[np.ndarray, np.ndarray, IntervalClosedType]: ...
|
| 152 |
+
|
| 153 |
+
class IntervalTree(IntervalMixin):
|
| 154 |
+
def __init__(
|
| 155 |
+
self,
|
| 156 |
+
left: np.ndarray,
|
| 157 |
+
right: np.ndarray,
|
| 158 |
+
closed: IntervalClosedType = ...,
|
| 159 |
+
leaf_size: int = ...,
|
| 160 |
+
) -> None: ...
|
| 161 |
+
@property
|
| 162 |
+
def mid(self) -> np.ndarray: ...
|
| 163 |
+
@property
|
| 164 |
+
def length(self) -> np.ndarray: ...
|
| 165 |
+
def get_indexer(self, target) -> npt.NDArray[np.intp]: ...
|
| 166 |
+
def get_indexer_non_unique(
|
| 167 |
+
self, target
|
| 168 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 169 |
+
_na_count: int
|
| 170 |
+
@property
|
| 171 |
+
def is_overlapping(self) -> bool: ...
|
| 172 |
+
@property
|
| 173 |
+
def is_monotonic_increasing(self) -> bool: ...
|
| 174 |
+
def clear_mapping(self) -> None: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/join.pyi
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from pandas._typing import npt
|
| 4 |
+
|
| 5 |
+
def inner_join(
|
| 6 |
+
left: np.ndarray, # const intp_t[:]
|
| 7 |
+
right: np.ndarray, # const intp_t[:]
|
| 8 |
+
max_groups: int,
|
| 9 |
+
sort: bool = ...,
|
| 10 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 11 |
+
def left_outer_join(
|
| 12 |
+
left: np.ndarray, # const intp_t[:]
|
| 13 |
+
right: np.ndarray, # const intp_t[:]
|
| 14 |
+
max_groups: int,
|
| 15 |
+
sort: bool = ...,
|
| 16 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 17 |
+
def full_outer_join(
|
| 18 |
+
left: np.ndarray, # const intp_t[:]
|
| 19 |
+
right: np.ndarray, # const intp_t[:]
|
| 20 |
+
max_groups: int,
|
| 21 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 22 |
+
def ffill_indexer(
|
| 23 |
+
indexer: np.ndarray, # const intp_t[:]
|
| 24 |
+
) -> npt.NDArray[np.intp]: ...
|
| 25 |
+
def left_join_indexer_unique(
|
| 26 |
+
left: np.ndarray, # ndarray[join_t]
|
| 27 |
+
right: np.ndarray, # ndarray[join_t]
|
| 28 |
+
) -> npt.NDArray[np.intp]: ...
|
| 29 |
+
def left_join_indexer(
|
| 30 |
+
left: np.ndarray, # ndarray[join_t]
|
| 31 |
+
right: np.ndarray, # ndarray[join_t]
|
| 32 |
+
) -> tuple[
|
| 33 |
+
np.ndarray, # np.ndarray[join_t]
|
| 34 |
+
npt.NDArray[np.intp],
|
| 35 |
+
npt.NDArray[np.intp],
|
| 36 |
+
]: ...
|
| 37 |
+
def inner_join_indexer(
|
| 38 |
+
left: np.ndarray, # ndarray[join_t]
|
| 39 |
+
right: np.ndarray, # ndarray[join_t]
|
| 40 |
+
) -> tuple[
|
| 41 |
+
np.ndarray, # np.ndarray[join_t]
|
| 42 |
+
npt.NDArray[np.intp],
|
| 43 |
+
npt.NDArray[np.intp],
|
| 44 |
+
]: ...
|
| 45 |
+
def outer_join_indexer(
|
| 46 |
+
left: np.ndarray, # ndarray[join_t]
|
| 47 |
+
right: np.ndarray, # ndarray[join_t]
|
| 48 |
+
) -> tuple[
|
| 49 |
+
np.ndarray, # np.ndarray[join_t]
|
| 50 |
+
npt.NDArray[np.intp],
|
| 51 |
+
npt.NDArray[np.intp],
|
| 52 |
+
]: ...
|
| 53 |
+
def asof_join_backward_on_X_by_Y(
|
| 54 |
+
left_values: np.ndarray, # ndarray[numeric_t]
|
| 55 |
+
right_values: np.ndarray, # ndarray[numeric_t]
|
| 56 |
+
left_by_values: np.ndarray, # const int64_t[:]
|
| 57 |
+
right_by_values: np.ndarray, # const int64_t[:]
|
| 58 |
+
allow_exact_matches: bool = ...,
|
| 59 |
+
tolerance: np.number | float | None = ...,
|
| 60 |
+
use_hashtable: bool = ...,
|
| 61 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 62 |
+
def asof_join_forward_on_X_by_Y(
|
| 63 |
+
left_values: np.ndarray, # ndarray[numeric_t]
|
| 64 |
+
right_values: np.ndarray, # ndarray[numeric_t]
|
| 65 |
+
left_by_values: np.ndarray, # const int64_t[:]
|
| 66 |
+
right_by_values: np.ndarray, # const int64_t[:]
|
| 67 |
+
allow_exact_matches: bool = ...,
|
| 68 |
+
tolerance: np.number | float | None = ...,
|
| 69 |
+
use_hashtable: bool = ...,
|
| 70 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
| 71 |
+
def asof_join_nearest_on_X_by_Y(
|
| 72 |
+
left_values: np.ndarray, # ndarray[numeric_t]
|
| 73 |
+
right_values: np.ndarray, # ndarray[numeric_t]
|
| 74 |
+
left_by_values: np.ndarray, # const int64_t[:]
|
| 75 |
+
right_by_values: np.ndarray, # const int64_t[:]
|
| 76 |
+
allow_exact_matches: bool = ...,
|
| 77 |
+
tolerance: np.number | float | None = ...,
|
| 78 |
+
use_hashtable: bool = ...,
|
| 79 |
+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/json.cpython-312-x86_64-linux-gnu.so
ADDED
|
Binary file (64.3 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/json.pyi
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import (
|
| 2 |
+
Any,
|
| 3 |
+
Callable,
|
| 4 |
+
)
|
| 5 |
+
|
| 6 |
+
def ujson_dumps(
|
| 7 |
+
obj: Any,
|
| 8 |
+
ensure_ascii: bool = ...,
|
| 9 |
+
double_precision: int = ...,
|
| 10 |
+
indent: int = ...,
|
| 11 |
+
orient: str = ...,
|
| 12 |
+
date_unit: str = ...,
|
| 13 |
+
iso_dates: bool = ...,
|
| 14 |
+
default_handler: None
|
| 15 |
+
| Callable[[Any], str | float | bool | list | dict | None] = ...,
|
| 16 |
+
) -> str: ...
|
| 17 |
+
def ujson_loads(
|
| 18 |
+
s: str,
|
| 19 |
+
precise_float: bool = ...,
|
| 20 |
+
numpy: bool = ...,
|
| 21 |
+
dtype: None = ...,
|
| 22 |
+
labelled: bool = ...,
|
| 23 |
+
) -> Any: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/lib.pyi
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# TODO(npdtypes): Many types specified here can be made more specific/accurate;
|
| 2 |
+
# the more specific versions are specified in comments
|
| 3 |
+
from decimal import Decimal
|
| 4 |
+
from typing import (
|
| 5 |
+
Any,
|
| 6 |
+
Callable,
|
| 7 |
+
Final,
|
| 8 |
+
Generator,
|
| 9 |
+
Hashable,
|
| 10 |
+
Literal,
|
| 11 |
+
TypeAlias,
|
| 12 |
+
overload,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
import numpy as np
|
| 16 |
+
|
| 17 |
+
from pandas._libs.interval import Interval
|
| 18 |
+
from pandas._libs.tslibs import Period
|
| 19 |
+
from pandas._typing import (
|
| 20 |
+
ArrayLike,
|
| 21 |
+
DtypeObj,
|
| 22 |
+
TypeGuard,
|
| 23 |
+
npt,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# placeholder until we can specify np.ndarray[object, ndim=2]
|
| 27 |
+
ndarray_obj_2d = np.ndarray
|
| 28 |
+
|
| 29 |
+
from enum import Enum
|
| 30 |
+
|
| 31 |
+
class _NoDefault(Enum):
|
| 32 |
+
no_default = ...
|
| 33 |
+
|
| 34 |
+
no_default: Final = _NoDefault.no_default
|
| 35 |
+
NoDefault: TypeAlias = Literal[_NoDefault.no_default]
|
| 36 |
+
|
| 37 |
+
i8max: int
|
| 38 |
+
u8max: int
|
| 39 |
+
|
| 40 |
+
def is_np_dtype(dtype: object, kinds: str | None = ...) -> TypeGuard[np.dtype]: ...
|
| 41 |
+
def item_from_zerodim(val: object) -> object: ...
|
| 42 |
+
def infer_dtype(value: object, skipna: bool = ...) -> str: ...
|
| 43 |
+
def is_iterator(obj: object) -> bool: ...
|
| 44 |
+
def is_scalar(val: object) -> bool: ...
|
| 45 |
+
def is_list_like(obj: object, allow_sets: bool = ...) -> bool: ...
|
| 46 |
+
def is_pyarrow_array(obj: object) -> bool: ...
|
| 47 |
+
def is_period(val: object) -> TypeGuard[Period]: ...
|
| 48 |
+
def is_interval(obj: object) -> TypeGuard[Interval]: ...
|
| 49 |
+
def is_decimal(obj: object) -> TypeGuard[Decimal]: ...
|
| 50 |
+
def is_complex(obj: object) -> TypeGuard[complex]: ...
|
| 51 |
+
def is_bool(obj: object) -> TypeGuard[bool | np.bool_]: ...
|
| 52 |
+
def is_integer(obj: object) -> TypeGuard[int | np.integer]: ...
|
| 53 |
+
def is_int_or_none(obj) -> bool: ...
|
| 54 |
+
def is_float(obj: object) -> TypeGuard[float]: ...
|
| 55 |
+
def is_interval_array(values: np.ndarray) -> bool: ...
|
| 56 |
+
def is_datetime64_array(values: np.ndarray, skipna: bool = True) -> bool: ...
|
| 57 |
+
def is_timedelta_or_timedelta64_array(
|
| 58 |
+
values: np.ndarray, skipna: bool = True
|
| 59 |
+
) -> bool: ...
|
| 60 |
+
def is_datetime_with_singletz_array(values: np.ndarray) -> bool: ...
|
| 61 |
+
def is_time_array(values: np.ndarray, skipna: bool = ...): ...
|
| 62 |
+
def is_date_array(values: np.ndarray, skipna: bool = ...): ...
|
| 63 |
+
def is_datetime_array(values: np.ndarray, skipna: bool = ...): ...
|
| 64 |
+
def is_string_array(values: np.ndarray, skipna: bool = ...): ...
|
| 65 |
+
def is_float_array(values: np.ndarray): ...
|
| 66 |
+
def is_integer_array(values: np.ndarray, skipna: bool = ...): ...
|
| 67 |
+
def is_bool_array(values: np.ndarray, skipna: bool = ...): ...
|
| 68 |
+
def fast_multiget(
|
| 69 |
+
mapping: dict,
|
| 70 |
+
keys: np.ndarray, # object[:]
|
| 71 |
+
default=...,
|
| 72 |
+
) -> np.ndarray: ...
|
| 73 |
+
def fast_unique_multiple_list_gen(gen: Generator, sort: bool = ...) -> list: ...
|
| 74 |
+
def fast_unique_multiple_list(lists: list, sort: bool | None = ...) -> list: ...
|
| 75 |
+
def map_infer(
|
| 76 |
+
arr: np.ndarray,
|
| 77 |
+
f: Callable[[Any], Any],
|
| 78 |
+
convert: bool = ...,
|
| 79 |
+
ignore_na: bool = ...,
|
| 80 |
+
) -> np.ndarray: ...
|
| 81 |
+
@overload
|
| 82 |
+
def maybe_convert_objects(
|
| 83 |
+
objects: npt.NDArray[np.object_],
|
| 84 |
+
*,
|
| 85 |
+
try_float: bool = ...,
|
| 86 |
+
safe: bool = ...,
|
| 87 |
+
convert_numeric: bool = ...,
|
| 88 |
+
convert_non_numeric: Literal[False] = ...,
|
| 89 |
+
convert_to_nullable_dtype: Literal[False] = ...,
|
| 90 |
+
dtype_if_all_nat: DtypeObj | None = ...,
|
| 91 |
+
) -> npt.NDArray[np.object_ | np.number]: ...
|
| 92 |
+
@overload
|
| 93 |
+
def maybe_convert_objects(
|
| 94 |
+
objects: npt.NDArray[np.object_],
|
| 95 |
+
*,
|
| 96 |
+
try_float: bool = ...,
|
| 97 |
+
safe: bool = ...,
|
| 98 |
+
convert_numeric: bool = ...,
|
| 99 |
+
convert_non_numeric: bool = ...,
|
| 100 |
+
convert_to_nullable_dtype: Literal[True] = ...,
|
| 101 |
+
dtype_if_all_nat: DtypeObj | None = ...,
|
| 102 |
+
) -> ArrayLike: ...
|
| 103 |
+
@overload
|
| 104 |
+
def maybe_convert_objects(
|
| 105 |
+
objects: npt.NDArray[np.object_],
|
| 106 |
+
*,
|
| 107 |
+
try_float: bool = ...,
|
| 108 |
+
safe: bool = ...,
|
| 109 |
+
convert_numeric: bool = ...,
|
| 110 |
+
convert_non_numeric: bool = ...,
|
| 111 |
+
convert_to_nullable_dtype: bool = ...,
|
| 112 |
+
dtype_if_all_nat: DtypeObj | None = ...,
|
| 113 |
+
) -> ArrayLike: ...
|
| 114 |
+
@overload
|
| 115 |
+
def maybe_convert_numeric(
|
| 116 |
+
values: npt.NDArray[np.object_],
|
| 117 |
+
na_values: set,
|
| 118 |
+
convert_empty: bool = ...,
|
| 119 |
+
coerce_numeric: bool = ...,
|
| 120 |
+
convert_to_masked_nullable: Literal[False] = ...,
|
| 121 |
+
) -> tuple[np.ndarray, None]: ...
|
| 122 |
+
@overload
|
| 123 |
+
def maybe_convert_numeric(
|
| 124 |
+
values: npt.NDArray[np.object_],
|
| 125 |
+
na_values: set,
|
| 126 |
+
convert_empty: bool = ...,
|
| 127 |
+
coerce_numeric: bool = ...,
|
| 128 |
+
*,
|
| 129 |
+
convert_to_masked_nullable: Literal[True],
|
| 130 |
+
) -> tuple[np.ndarray, np.ndarray]: ...
|
| 131 |
+
|
| 132 |
+
# TODO: restrict `arr`?
|
| 133 |
+
def ensure_string_array(
|
| 134 |
+
arr,
|
| 135 |
+
na_value: object = ...,
|
| 136 |
+
convert_na_value: bool = ...,
|
| 137 |
+
copy: bool = ...,
|
| 138 |
+
skipna: bool = ...,
|
| 139 |
+
) -> npt.NDArray[np.object_]: ...
|
| 140 |
+
def convert_nans_to_NA(
|
| 141 |
+
arr: npt.NDArray[np.object_],
|
| 142 |
+
) -> npt.NDArray[np.object_]: ...
|
| 143 |
+
def fast_zip(ndarrays: list) -> npt.NDArray[np.object_]: ...
|
| 144 |
+
|
| 145 |
+
# TODO: can we be more specific about rows?
|
| 146 |
+
def to_object_array_tuples(rows: object) -> ndarray_obj_2d: ...
|
| 147 |
+
def tuples_to_object_array(
|
| 148 |
+
tuples: npt.NDArray[np.object_],
|
| 149 |
+
) -> ndarray_obj_2d: ...
|
| 150 |
+
|
| 151 |
+
# TODO: can we be more specific about rows?
|
| 152 |
+
def to_object_array(rows: object, min_width: int = ...) -> ndarray_obj_2d: ...
|
| 153 |
+
def dicts_to_array(dicts: list, columns: list) -> ndarray_obj_2d: ...
|
| 154 |
+
def maybe_booleans_to_slice(
|
| 155 |
+
mask: npt.NDArray[np.uint8],
|
| 156 |
+
) -> slice | npt.NDArray[np.uint8]: ...
|
| 157 |
+
def maybe_indices_to_slice(
|
| 158 |
+
indices: npt.NDArray[np.intp],
|
| 159 |
+
max_len: int,
|
| 160 |
+
) -> slice | npt.NDArray[np.intp]: ...
|
| 161 |
+
def is_all_arraylike(obj: list) -> bool: ...
|
| 162 |
+
|
| 163 |
+
# -----------------------------------------------------------------
|
| 164 |
+
# Functions which in reality take memoryviews
|
| 165 |
+
|
| 166 |
+
def memory_usage_of_objects(arr: np.ndarray) -> int: ... # object[:] # np.int64
|
| 167 |
+
def map_infer_mask(
|
| 168 |
+
arr: np.ndarray,
|
| 169 |
+
f: Callable[[Any], Any],
|
| 170 |
+
mask: np.ndarray, # const uint8_t[:]
|
| 171 |
+
convert: bool = ...,
|
| 172 |
+
na_value: Any = ...,
|
| 173 |
+
dtype: np.dtype = ...,
|
| 174 |
+
) -> np.ndarray: ...
|
| 175 |
+
def indices_fast(
|
| 176 |
+
index: npt.NDArray[np.intp],
|
| 177 |
+
labels: np.ndarray, # const int64_t[:]
|
| 178 |
+
keys: list,
|
| 179 |
+
sorted_labels: list[npt.NDArray[np.int64]],
|
| 180 |
+
) -> dict[Hashable, npt.NDArray[np.intp]]: ...
|
| 181 |
+
def generate_slices(
|
| 182 |
+
labels: np.ndarray, ngroups: int # const intp_t[:]
|
| 183 |
+
) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: ...
|
| 184 |
+
def count_level_2d(
|
| 185 |
+
mask: np.ndarray, # ndarray[uint8_t, ndim=2, cast=True],
|
| 186 |
+
labels: np.ndarray, # const intp_t[:]
|
| 187 |
+
max_bin: int,
|
| 188 |
+
) -> np.ndarray: ... # np.ndarray[np.int64, ndim=2]
|
| 189 |
+
def get_level_sorter(
|
| 190 |
+
codes: np.ndarray, # const int64_t[:]
|
| 191 |
+
starts: np.ndarray, # const intp_t[:]
|
| 192 |
+
) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1]
|
| 193 |
+
def generate_bins_dt64(
|
| 194 |
+
values: npt.NDArray[np.int64],
|
| 195 |
+
binner: np.ndarray, # const int64_t[:]
|
| 196 |
+
closed: object = ...,
|
| 197 |
+
hasnans: bool = ...,
|
| 198 |
+
) -> np.ndarray: ... # np.ndarray[np.int64, ndim=1]
|
| 199 |
+
def array_equivalent_object(
|
| 200 |
+
left: npt.NDArray[np.object_],
|
| 201 |
+
right: npt.NDArray[np.object_],
|
| 202 |
+
) -> bool: ...
|
| 203 |
+
def has_infs(arr: np.ndarray) -> bool: ... # const floating[:]
|
| 204 |
+
def has_only_ints_or_nan(arr: np.ndarray) -> bool: ... # const floating[:]
|
| 205 |
+
def get_reverse_indexer(
|
| 206 |
+
indexer: np.ndarray, # const intp_t[:]
|
| 207 |
+
length: int,
|
| 208 |
+
) -> npt.NDArray[np.intp]: ...
|
| 209 |
+
def is_bool_list(obj: list) -> bool: ...
|
| 210 |
+
def dtypes_all_equal(types: list[DtypeObj]) -> bool: ...
|
| 211 |
+
def is_range_indexer(
|
| 212 |
+
left: np.ndarray, n: int # np.ndarray[np.int64, ndim=1]
|
| 213 |
+
) -> bool: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/missing.pyi
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from numpy import typing as npt
|
| 3 |
+
|
| 4 |
+
class NAType:
|
| 5 |
+
def __new__(cls, *args, **kwargs): ...
|
| 6 |
+
|
| 7 |
+
NA: NAType
|
| 8 |
+
|
| 9 |
+
def is_matching_na(
|
| 10 |
+
left: object, right: object, nan_matches_none: bool = ...
|
| 11 |
+
) -> bool: ...
|
| 12 |
+
def isposinf_scalar(val: object) -> bool: ...
|
| 13 |
+
def isneginf_scalar(val: object) -> bool: ...
|
| 14 |
+
def checknull(val: object, inf_as_na: bool = ...) -> bool: ...
|
| 15 |
+
def isnaobj(arr: np.ndarray, inf_as_na: bool = ...) -> npt.NDArray[np.bool_]: ...
|
| 16 |
+
def is_numeric_na(values: np.ndarray) -> npt.NDArray[np.bool_]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/ops.pyi
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import (
|
| 2 |
+
Any,
|
| 3 |
+
Callable,
|
| 4 |
+
Iterable,
|
| 5 |
+
Literal,
|
| 6 |
+
TypeAlias,
|
| 7 |
+
overload,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
from pandas._typing import npt
|
| 13 |
+
|
| 14 |
+
_BinOp: TypeAlias = Callable[[Any, Any], Any]
|
| 15 |
+
_BoolOp: TypeAlias = Callable[[Any, Any], bool]
|
| 16 |
+
|
| 17 |
+
def scalar_compare(
|
| 18 |
+
values: np.ndarray, # object[:]
|
| 19 |
+
val: object,
|
| 20 |
+
op: _BoolOp, # {operator.eq, operator.ne, ...}
|
| 21 |
+
) -> npt.NDArray[np.bool_]: ...
|
| 22 |
+
def vec_compare(
|
| 23 |
+
left: npt.NDArray[np.object_],
|
| 24 |
+
right: npt.NDArray[np.object_],
|
| 25 |
+
op: _BoolOp, # {operator.eq, operator.ne, ...}
|
| 26 |
+
) -> npt.NDArray[np.bool_]: ...
|
| 27 |
+
def scalar_binop(
|
| 28 |
+
values: np.ndarray, # object[:]
|
| 29 |
+
val: object,
|
| 30 |
+
op: _BinOp, # binary operator
|
| 31 |
+
) -> np.ndarray: ...
|
| 32 |
+
def vec_binop(
|
| 33 |
+
left: np.ndarray, # object[:]
|
| 34 |
+
right: np.ndarray, # object[:]
|
| 35 |
+
op: _BinOp, # binary operator
|
| 36 |
+
) -> np.ndarray: ...
|
| 37 |
+
@overload
|
| 38 |
+
def maybe_convert_bool(
|
| 39 |
+
arr: npt.NDArray[np.object_],
|
| 40 |
+
true_values: Iterable | None = None,
|
| 41 |
+
false_values: Iterable | None = None,
|
| 42 |
+
convert_to_masked_nullable: Literal[False] = ...,
|
| 43 |
+
) -> tuple[np.ndarray, None]: ...
|
| 44 |
+
@overload
|
| 45 |
+
def maybe_convert_bool(
|
| 46 |
+
arr: npt.NDArray[np.object_],
|
| 47 |
+
true_values: Iterable = ...,
|
| 48 |
+
false_values: Iterable = ...,
|
| 49 |
+
*,
|
| 50 |
+
convert_to_masked_nullable: Literal[True],
|
| 51 |
+
) -> tuple[np.ndarray, np.ndarray]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/ops_dispatch.cpython-312-x86_64-linux-gnu.so
ADDED
|
Binary file (65.8 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/ops_dispatch.pyi
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
def maybe_dispatch_ufunc_to_dunder_op(
|
| 4 |
+
self, ufunc: np.ufunc, method: str, *inputs, **kwargs
|
| 5 |
+
): ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/pandas_datetime.cpython-312-x86_64-linux-gnu.so
ADDED
|
Binary file (39.3 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/pandas_parser.cpython-312-x86_64-linux-gnu.so
ADDED
|
Binary file (43.4 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/parsers.pyi
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import (
|
| 2 |
+
Hashable,
|
| 3 |
+
Literal,
|
| 4 |
+
)
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
from pandas._typing import (
|
| 9 |
+
ArrayLike,
|
| 10 |
+
Dtype,
|
| 11 |
+
npt,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
STR_NA_VALUES: set[str]
|
| 15 |
+
DEFAULT_BUFFER_HEURISTIC: int
|
| 16 |
+
|
| 17 |
+
def sanitize_objects(
|
| 18 |
+
values: npt.NDArray[np.object_],
|
| 19 |
+
na_values: set,
|
| 20 |
+
) -> int: ...
|
| 21 |
+
|
| 22 |
+
class TextReader:
|
| 23 |
+
unnamed_cols: set[str]
|
| 24 |
+
table_width: int # int64_t
|
| 25 |
+
leading_cols: int # int64_t
|
| 26 |
+
header: list[list[int]] # non-negative integers
|
| 27 |
+
def __init__(
|
| 28 |
+
self,
|
| 29 |
+
source,
|
| 30 |
+
delimiter: bytes | str = ..., # single-character only
|
| 31 |
+
header=...,
|
| 32 |
+
header_start: int = ..., # int64_t
|
| 33 |
+
header_end: int = ..., # uint64_t
|
| 34 |
+
index_col=...,
|
| 35 |
+
names=...,
|
| 36 |
+
tokenize_chunksize: int = ..., # int64_t
|
| 37 |
+
delim_whitespace: bool = ...,
|
| 38 |
+
converters=...,
|
| 39 |
+
skipinitialspace: bool = ...,
|
| 40 |
+
escapechar: bytes | str | None = ..., # single-character only
|
| 41 |
+
doublequote: bool = ...,
|
| 42 |
+
quotechar: str | bytes | None = ..., # at most 1 character
|
| 43 |
+
quoting: int = ...,
|
| 44 |
+
lineterminator: bytes | str | None = ..., # at most 1 character
|
| 45 |
+
comment=...,
|
| 46 |
+
decimal: bytes | str = ..., # single-character only
|
| 47 |
+
thousands: bytes | str | None = ..., # single-character only
|
| 48 |
+
dtype: Dtype | dict[Hashable, Dtype] = ...,
|
| 49 |
+
usecols=...,
|
| 50 |
+
error_bad_lines: bool = ...,
|
| 51 |
+
warn_bad_lines: bool = ...,
|
| 52 |
+
na_filter: bool = ...,
|
| 53 |
+
na_values=...,
|
| 54 |
+
na_fvalues=...,
|
| 55 |
+
keep_default_na: bool = ...,
|
| 56 |
+
true_values=...,
|
| 57 |
+
false_values=...,
|
| 58 |
+
allow_leading_cols: bool = ...,
|
| 59 |
+
skiprows=...,
|
| 60 |
+
skipfooter: int = ..., # int64_t
|
| 61 |
+
verbose: bool = ...,
|
| 62 |
+
float_precision: Literal["round_trip", "legacy", "high"] | None = ...,
|
| 63 |
+
skip_blank_lines: bool = ...,
|
| 64 |
+
encoding_errors: bytes | str = ...,
|
| 65 |
+
) -> None: ...
|
| 66 |
+
def set_noconvert(self, i: int) -> None: ...
|
| 67 |
+
def remove_noconvert(self, i: int) -> None: ...
|
| 68 |
+
def close(self) -> None: ...
|
| 69 |
+
def read(self, rows: int | None = ...) -> dict[int, ArrayLike]: ...
|
| 70 |
+
def read_low_memory(self, rows: int | None) -> list[dict[int, ArrayLike]]: ...
|
| 71 |
+
|
| 72 |
+
# _maybe_upcast, na_values are only exposed for testing
|
| 73 |
+
na_values: dict
|
| 74 |
+
|
| 75 |
+
def _maybe_upcast(
|
| 76 |
+
arr, use_dtype_backend: bool = ..., dtype_backend: str = ...
|
| 77 |
+
) -> np.ndarray: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/properties.cpython-312-x86_64-linux-gnu.so
ADDED
|
Binary file (96 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/properties.pyi
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import (
|
| 2 |
+
Sequence,
|
| 3 |
+
overload,
|
| 4 |
+
)
|
| 5 |
+
|
| 6 |
+
from pandas._typing import (
|
| 7 |
+
AnyArrayLike,
|
| 8 |
+
DataFrame,
|
| 9 |
+
Index,
|
| 10 |
+
Series,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# note: this is a lie to make type checkers happy (they special
|
| 14 |
+
# case property). cache_readonly uses attribute names similar to
|
| 15 |
+
# property (fget) but it does not provide fset and fdel.
|
| 16 |
+
cache_readonly = property
|
| 17 |
+
|
| 18 |
+
class AxisProperty:
|
| 19 |
+
axis: int
|
| 20 |
+
def __init__(self, axis: int = ..., doc: str = ...) -> None: ...
|
| 21 |
+
@overload
|
| 22 |
+
def __get__(self, obj: DataFrame | Series, type) -> Index: ...
|
| 23 |
+
@overload
|
| 24 |
+
def __get__(self, obj: None, type) -> AxisProperty: ...
|
| 25 |
+
def __set__(
|
| 26 |
+
self, obj: DataFrame | Series, value: AnyArrayLike | Sequence
|
| 27 |
+
) -> None: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/reshape.pyi
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from pandas._typing import npt
|
| 4 |
+
|
| 5 |
+
def unstack(
|
| 6 |
+
values: np.ndarray, # reshape_t[:, :]
|
| 7 |
+
mask: np.ndarray, # const uint8_t[:]
|
| 8 |
+
stride: int,
|
| 9 |
+
length: int,
|
| 10 |
+
width: int,
|
| 11 |
+
new_values: np.ndarray, # reshape_t[:, :]
|
| 12 |
+
new_mask: np.ndarray, # uint8_t[:, :]
|
| 13 |
+
) -> None: ...
|
| 14 |
+
def explode(
|
| 15 |
+
values: npt.NDArray[np.object_],
|
| 16 |
+
) -> tuple[npt.NDArray[np.object_], npt.NDArray[np.int64]]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/sas.pyi
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pandas.io.sas.sas7bdat import SAS7BDATReader
|
| 2 |
+
|
| 3 |
+
class Parser:
|
| 4 |
+
def __init__(self, parser: SAS7BDATReader) -> None: ...
|
| 5 |
+
def read(self, nrows: int) -> None: ...
|
| 6 |
+
|
| 7 |
+
def get_subheader_index(signature: bytes) -> int: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/sparse.pyi
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Sequence
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from pandas._typing import (
|
| 6 |
+
Self,
|
| 7 |
+
npt,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
class SparseIndex:
|
| 11 |
+
length: int
|
| 12 |
+
npoints: int
|
| 13 |
+
def __init__(self) -> None: ...
|
| 14 |
+
@property
|
| 15 |
+
def ngaps(self) -> int: ...
|
| 16 |
+
@property
|
| 17 |
+
def nbytes(self) -> int: ...
|
| 18 |
+
@property
|
| 19 |
+
def indices(self) -> npt.NDArray[np.int32]: ...
|
| 20 |
+
def equals(self, other) -> bool: ...
|
| 21 |
+
def lookup(self, index: int) -> np.int32: ...
|
| 22 |
+
def lookup_array(self, indexer: npt.NDArray[np.int32]) -> npt.NDArray[np.int32]: ...
|
| 23 |
+
def to_int_index(self) -> IntIndex: ...
|
| 24 |
+
def to_block_index(self) -> BlockIndex: ...
|
| 25 |
+
def intersect(self, y_: SparseIndex) -> Self: ...
|
| 26 |
+
def make_union(self, y_: SparseIndex) -> Self: ...
|
| 27 |
+
|
| 28 |
+
class IntIndex(SparseIndex):
|
| 29 |
+
indices: npt.NDArray[np.int32]
|
| 30 |
+
def __init__(
|
| 31 |
+
self, length: int, indices: Sequence[int], check_integrity: bool = ...
|
| 32 |
+
) -> None: ...
|
| 33 |
+
|
| 34 |
+
class BlockIndex(SparseIndex):
|
| 35 |
+
nblocks: int
|
| 36 |
+
blocs: np.ndarray
|
| 37 |
+
blengths: np.ndarray
|
| 38 |
+
def __init__(
|
| 39 |
+
self, length: int, blocs: np.ndarray, blengths: np.ndarray
|
| 40 |
+
) -> None: ...
|
| 41 |
+
|
| 42 |
+
# Override to have correct parameters
|
| 43 |
+
def intersect(self, other: SparseIndex) -> Self: ...
|
| 44 |
+
def make_union(self, y: SparseIndex) -> Self: ...
|
| 45 |
+
|
| 46 |
+
def make_mask_object_ndarray(
|
| 47 |
+
arr: npt.NDArray[np.object_], fill_value
|
| 48 |
+
) -> npt.NDArray[np.bool_]: ...
|
| 49 |
+
def get_blocks(
|
| 50 |
+
indices: npt.NDArray[np.int32],
|
| 51 |
+
) -> tuple[npt.NDArray[np.int32], npt.NDArray[np.int32]]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/testing.pyi
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def assert_dict_equal(a, b, compare_keys: bool = ...): ...
|
| 2 |
+
def assert_almost_equal(
|
| 3 |
+
a,
|
| 4 |
+
b,
|
| 5 |
+
rtol: float = ...,
|
| 6 |
+
atol: float = ...,
|
| 7 |
+
check_dtype: bool = ...,
|
| 8 |
+
obj=...,
|
| 9 |
+
lobj=...,
|
| 10 |
+
robj=...,
|
| 11 |
+
index_values=...,
|
| 12 |
+
): ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/tslib.pyi
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import tzinfo
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from pandas._typing import npt
|
| 6 |
+
|
| 7 |
+
def format_array_from_datetime(
|
| 8 |
+
values: npt.NDArray[np.int64],
|
| 9 |
+
tz: tzinfo | None = ...,
|
| 10 |
+
format: str | None = ...,
|
| 11 |
+
na_rep: str | float = ...,
|
| 12 |
+
reso: int = ..., # NPY_DATETIMEUNIT
|
| 13 |
+
) -> npt.NDArray[np.object_]: ...
|
| 14 |
+
def array_with_unit_to_datetime(
|
| 15 |
+
values: npt.NDArray[np.object_],
|
| 16 |
+
unit: str,
|
| 17 |
+
errors: str = ...,
|
| 18 |
+
) -> tuple[np.ndarray, tzinfo | None]: ...
|
| 19 |
+
def first_non_null(values: np.ndarray) -> int: ...
|
| 20 |
+
def array_to_datetime(
|
| 21 |
+
values: npt.NDArray[np.object_],
|
| 22 |
+
errors: str = ...,
|
| 23 |
+
dayfirst: bool = ...,
|
| 24 |
+
yearfirst: bool = ...,
|
| 25 |
+
utc: bool = ...,
|
| 26 |
+
creso: int = ...,
|
| 27 |
+
) -> tuple[np.ndarray, tzinfo | None]: ...
|
| 28 |
+
|
| 29 |
+
# returned ndarray may be object dtype or datetime64[ns]
|
| 30 |
+
|
| 31 |
+
def array_to_datetime_with_tz(
|
| 32 |
+
values: npt.NDArray[np.object_],
|
| 33 |
+
tz: tzinfo,
|
| 34 |
+
dayfirst: bool,
|
| 35 |
+
yearfirst: bool,
|
| 36 |
+
creso: int,
|
| 37 |
+
) -> npt.NDArray[np.int64]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/_libs/writers.pyi
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from pandas._typing import ArrayLike
|
| 4 |
+
|
| 5 |
+
def write_csv_rows(
|
| 6 |
+
data: list[ArrayLike],
|
| 7 |
+
data_index: np.ndarray,
|
| 8 |
+
nlevels: int,
|
| 9 |
+
cols: np.ndarray,
|
| 10 |
+
writer: object, # _csv.writer
|
| 11 |
+
) -> None: ...
|
| 12 |
+
def convert_json_to_lines(arr: str) -> str: ...
|
| 13 |
+
def max_len_string_array(
|
| 14 |
+
arr: np.ndarray, # pandas_string[:]
|
| 15 |
+
) -> int: ...
|
| 16 |
+
def word_len(val: object) -> int: ...
|
| 17 |
+
def string_array_replace_from_nan_rep(
|
| 18 |
+
arr: np.ndarray, # np.ndarray[object, ndim=1]
|
| 19 |
+
nan_rep: object,
|
| 20 |
+
) -> None: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/api/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" public toolkit API """
|
| 2 |
+
from pandas.api import (
|
| 3 |
+
extensions,
|
| 4 |
+
indexers,
|
| 5 |
+
interchange,
|
| 6 |
+
types,
|
| 7 |
+
typing,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
__all__ = [
|
| 11 |
+
"interchange",
|
| 12 |
+
"extensions",
|
| 13 |
+
"indexers",
|
| 14 |
+
"types",
|
| 15 |
+
"typing",
|
| 16 |
+
]
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/__init__.py
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
compat
|
| 3 |
+
======
|
| 4 |
+
|
| 5 |
+
Cross-compatible functions for different versions of Python.
|
| 6 |
+
|
| 7 |
+
Other items:
|
| 8 |
+
* platform checker
|
| 9 |
+
"""
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
import platform
|
| 14 |
+
import sys
|
| 15 |
+
from typing import TYPE_CHECKING
|
| 16 |
+
|
| 17 |
+
from pandas.compat._constants import (
|
| 18 |
+
IS64,
|
| 19 |
+
ISMUSL,
|
| 20 |
+
PY310,
|
| 21 |
+
PY311,
|
| 22 |
+
PY312,
|
| 23 |
+
PYPY,
|
| 24 |
+
)
|
| 25 |
+
import pandas.compat.compressors
|
| 26 |
+
from pandas.compat.numpy import is_numpy_dev
|
| 27 |
+
from pandas.compat.pyarrow import (
|
| 28 |
+
pa_version_under10p1,
|
| 29 |
+
pa_version_under11p0,
|
| 30 |
+
pa_version_under13p0,
|
| 31 |
+
pa_version_under14p0,
|
| 32 |
+
pa_version_under14p1,
|
| 33 |
+
pa_version_under16p0,
|
| 34 |
+
pa_version_under17p0,
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if TYPE_CHECKING:
|
| 38 |
+
from pandas._typing import F
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def set_function_name(f: F, name: str, cls: type) -> F:
|
| 42 |
+
"""
|
| 43 |
+
Bind the name/qualname attributes of the function.
|
| 44 |
+
"""
|
| 45 |
+
f.__name__ = name
|
| 46 |
+
f.__qualname__ = f"{cls.__name__}.{name}"
|
| 47 |
+
f.__module__ = cls.__module__
|
| 48 |
+
return f
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def is_platform_little_endian() -> bool:
|
| 52 |
+
"""
|
| 53 |
+
Checking if the running platform is little endian.
|
| 54 |
+
|
| 55 |
+
Returns
|
| 56 |
+
-------
|
| 57 |
+
bool
|
| 58 |
+
True if the running platform is little endian.
|
| 59 |
+
"""
|
| 60 |
+
return sys.byteorder == "little"
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def is_platform_windows() -> bool:
|
| 64 |
+
"""
|
| 65 |
+
Checking if the running platform is windows.
|
| 66 |
+
|
| 67 |
+
Returns
|
| 68 |
+
-------
|
| 69 |
+
bool
|
| 70 |
+
True if the running platform is windows.
|
| 71 |
+
"""
|
| 72 |
+
return sys.platform in ["win32", "cygwin"]
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def is_platform_linux() -> bool:
|
| 76 |
+
"""
|
| 77 |
+
Checking if the running platform is linux.
|
| 78 |
+
|
| 79 |
+
Returns
|
| 80 |
+
-------
|
| 81 |
+
bool
|
| 82 |
+
True if the running platform is linux.
|
| 83 |
+
"""
|
| 84 |
+
return sys.platform == "linux"
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def is_platform_mac() -> bool:
|
| 88 |
+
"""
|
| 89 |
+
Checking if the running platform is mac.
|
| 90 |
+
|
| 91 |
+
Returns
|
| 92 |
+
-------
|
| 93 |
+
bool
|
| 94 |
+
True if the running platform is mac.
|
| 95 |
+
"""
|
| 96 |
+
return sys.platform == "darwin"
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def is_platform_arm() -> bool:
|
| 100 |
+
"""
|
| 101 |
+
Checking if the running platform use ARM architecture.
|
| 102 |
+
|
| 103 |
+
Returns
|
| 104 |
+
-------
|
| 105 |
+
bool
|
| 106 |
+
True if the running platform uses ARM architecture.
|
| 107 |
+
"""
|
| 108 |
+
return platform.machine() in ("arm64", "aarch64") or platform.machine().startswith(
|
| 109 |
+
"armv"
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def is_platform_power() -> bool:
|
| 114 |
+
"""
|
| 115 |
+
Checking if the running platform use Power architecture.
|
| 116 |
+
|
| 117 |
+
Returns
|
| 118 |
+
-------
|
| 119 |
+
bool
|
| 120 |
+
True if the running platform uses ARM architecture.
|
| 121 |
+
"""
|
| 122 |
+
return platform.machine() in ("ppc64", "ppc64le")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def is_ci_environment() -> bool:
|
| 126 |
+
"""
|
| 127 |
+
Checking if running in a continuous integration environment by checking
|
| 128 |
+
the PANDAS_CI environment variable.
|
| 129 |
+
|
| 130 |
+
Returns
|
| 131 |
+
-------
|
| 132 |
+
bool
|
| 133 |
+
True if the running in a continuous integration environment.
|
| 134 |
+
"""
|
| 135 |
+
return os.environ.get("PANDAS_CI", "0") == "1"
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def get_lzma_file() -> type[pandas.compat.compressors.LZMAFile]:
|
| 139 |
+
"""
|
| 140 |
+
Importing the `LZMAFile` class from the `lzma` module.
|
| 141 |
+
|
| 142 |
+
Returns
|
| 143 |
+
-------
|
| 144 |
+
class
|
| 145 |
+
The `LZMAFile` class from the `lzma` module.
|
| 146 |
+
|
| 147 |
+
Raises
|
| 148 |
+
------
|
| 149 |
+
RuntimeError
|
| 150 |
+
If the `lzma` module was not imported correctly, or didn't exist.
|
| 151 |
+
"""
|
| 152 |
+
if not pandas.compat.compressors.has_lzma:
|
| 153 |
+
raise RuntimeError(
|
| 154 |
+
"lzma module not available. "
|
| 155 |
+
"A Python re-install with the proper dependencies, "
|
| 156 |
+
"might be required to solve this issue."
|
| 157 |
+
)
|
| 158 |
+
return pandas.compat.compressors.LZMAFile
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def get_bz2_file() -> type[pandas.compat.compressors.BZ2File]:
|
| 162 |
+
"""
|
| 163 |
+
Importing the `BZ2File` class from the `bz2` module.
|
| 164 |
+
|
| 165 |
+
Returns
|
| 166 |
+
-------
|
| 167 |
+
class
|
| 168 |
+
The `BZ2File` class from the `bz2` module.
|
| 169 |
+
|
| 170 |
+
Raises
|
| 171 |
+
------
|
| 172 |
+
RuntimeError
|
| 173 |
+
If the `bz2` module was not imported correctly, or didn't exist.
|
| 174 |
+
"""
|
| 175 |
+
if not pandas.compat.compressors.has_bz2:
|
| 176 |
+
raise RuntimeError(
|
| 177 |
+
"bz2 module not available. "
|
| 178 |
+
"A Python re-install with the proper dependencies, "
|
| 179 |
+
"might be required to solve this issue."
|
| 180 |
+
)
|
| 181 |
+
return pandas.compat.compressors.BZ2File
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
__all__ = [
|
| 185 |
+
"is_numpy_dev",
|
| 186 |
+
"pa_version_under10p1",
|
| 187 |
+
"pa_version_under11p0",
|
| 188 |
+
"pa_version_under13p0",
|
| 189 |
+
"pa_version_under14p0",
|
| 190 |
+
"pa_version_under14p1",
|
| 191 |
+
"pa_version_under16p0",
|
| 192 |
+
"pa_version_under17p0",
|
| 193 |
+
"IS64",
|
| 194 |
+
"ISMUSL",
|
| 195 |
+
"PY310",
|
| 196 |
+
"PY311",
|
| 197 |
+
"PY312",
|
| 198 |
+
"PYPY",
|
| 199 |
+
]
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/_constants.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
_constants
|
| 3 |
+
======
|
| 4 |
+
|
| 5 |
+
Constants relevant for the Python implementation.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import platform
|
| 11 |
+
import sys
|
| 12 |
+
import sysconfig
|
| 13 |
+
|
| 14 |
+
IS64 = sys.maxsize > 2**32
|
| 15 |
+
|
| 16 |
+
PY310 = sys.version_info >= (3, 10)
|
| 17 |
+
PY311 = sys.version_info >= (3, 11)
|
| 18 |
+
PY312 = sys.version_info >= (3, 12)
|
| 19 |
+
PYPY = platform.python_implementation() == "PyPy"
|
| 20 |
+
ISMUSL = "musl" in (sysconfig.get_config_var("HOST_GNU_TYPE") or "")
|
| 21 |
+
REF_COUNT = 2 if PY311 else 3
|
| 22 |
+
|
| 23 |
+
__all__ = [
|
| 24 |
+
"IS64",
|
| 25 |
+
"ISMUSL",
|
| 26 |
+
"PY310",
|
| 27 |
+
"PY311",
|
| 28 |
+
"PY312",
|
| 29 |
+
"PYPY",
|
| 30 |
+
]
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/_optional.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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import find_stack_level
|
| 9 |
+
|
| 10 |
+
from pandas.util.version import Version
|
| 11 |
+
|
| 12 |
+
if TYPE_CHECKING:
|
| 13 |
+
import types
|
| 14 |
+
|
| 15 |
+
# Update install.rst & setup.cfg when updating versions!
|
| 16 |
+
|
| 17 |
+
VERSIONS = {
|
| 18 |
+
"adbc-driver-postgresql": "0.8.0",
|
| 19 |
+
"adbc-driver-sqlite": "0.8.0",
|
| 20 |
+
"bs4": "4.11.2",
|
| 21 |
+
"blosc": "1.21.3",
|
| 22 |
+
"bottleneck": "1.3.6",
|
| 23 |
+
"dataframe-api-compat": "0.1.7",
|
| 24 |
+
"fastparquet": "2022.12.0",
|
| 25 |
+
"fsspec": "2022.11.0",
|
| 26 |
+
"html5lib": "1.1",
|
| 27 |
+
"hypothesis": "6.46.1",
|
| 28 |
+
"gcsfs": "2022.11.0",
|
| 29 |
+
"jinja2": "3.1.2",
|
| 30 |
+
"lxml.etree": "4.9.2",
|
| 31 |
+
"matplotlib": "3.6.3",
|
| 32 |
+
"numba": "0.56.4",
|
| 33 |
+
"numexpr": "2.8.4",
|
| 34 |
+
"odfpy": "1.4.1",
|
| 35 |
+
"openpyxl": "3.1.0",
|
| 36 |
+
"pandas_gbq": "0.19.0",
|
| 37 |
+
"psycopg2": "2.9.6", # (dt dec pq3 ext lo64)
|
| 38 |
+
"pymysql": "1.0.2",
|
| 39 |
+
"pyarrow": "10.0.1",
|
| 40 |
+
"pyreadstat": "1.2.0",
|
| 41 |
+
"pytest": "7.3.2",
|
| 42 |
+
"python-calamine": "0.1.7",
|
| 43 |
+
"pyxlsb": "1.0.10",
|
| 44 |
+
"s3fs": "2022.11.0",
|
| 45 |
+
"scipy": "1.10.0",
|
| 46 |
+
"sqlalchemy": "2.0.0",
|
| 47 |
+
"tables": "3.8.0",
|
| 48 |
+
"tabulate": "0.9.0",
|
| 49 |
+
"xarray": "2022.12.0",
|
| 50 |
+
"xlrd": "2.0.1",
|
| 51 |
+
"xlsxwriter": "3.0.5",
|
| 52 |
+
"zstandard": "0.19.0",
|
| 53 |
+
"tzdata": "2022.7",
|
| 54 |
+
"qtpy": "2.3.0",
|
| 55 |
+
"pyqt5": "5.15.9",
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
# A mapping from import name to package name (on PyPI) for packages where
|
| 59 |
+
# these two names are different.
|
| 60 |
+
|
| 61 |
+
INSTALL_MAPPING = {
|
| 62 |
+
"bs4": "beautifulsoup4",
|
| 63 |
+
"bottleneck": "Bottleneck",
|
| 64 |
+
"jinja2": "Jinja2",
|
| 65 |
+
"lxml.etree": "lxml",
|
| 66 |
+
"odf": "odfpy",
|
| 67 |
+
"pandas_gbq": "pandas-gbq",
|
| 68 |
+
"python_calamine": "python-calamine",
|
| 69 |
+
"sqlalchemy": "SQLAlchemy",
|
| 70 |
+
"tables": "pytables",
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def get_version(module: types.ModuleType) -> str:
|
| 75 |
+
version = getattr(module, "__version__", None)
|
| 76 |
+
|
| 77 |
+
if version is None:
|
| 78 |
+
raise ImportError(f"Can't determine version for {module.__name__}")
|
| 79 |
+
if module.__name__ == "psycopg2":
|
| 80 |
+
# psycopg2 appends " (dt dec pq3 ext lo64)" to it's version
|
| 81 |
+
version = version.split()[0]
|
| 82 |
+
return version
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def import_optional_dependency(
|
| 86 |
+
name: str,
|
| 87 |
+
extra: str = "",
|
| 88 |
+
errors: str = "raise",
|
| 89 |
+
min_version: str | None = None,
|
| 90 |
+
):
|
| 91 |
+
"""
|
| 92 |
+
Import an optional dependency.
|
| 93 |
+
|
| 94 |
+
By default, if a dependency is missing an ImportError with a nice
|
| 95 |
+
message will be raised. If a dependency is present, but too old,
|
| 96 |
+
we raise.
|
| 97 |
+
|
| 98 |
+
Parameters
|
| 99 |
+
----------
|
| 100 |
+
name : str
|
| 101 |
+
The module name.
|
| 102 |
+
extra : str
|
| 103 |
+
Additional text to include in the ImportError message.
|
| 104 |
+
errors : str {'raise', 'warn', 'ignore'}
|
| 105 |
+
What to do when a dependency is not found or its version is too old.
|
| 106 |
+
|
| 107 |
+
* raise : Raise an ImportError
|
| 108 |
+
* warn : Only applicable when a module's version is to old.
|
| 109 |
+
Warns that the version is too old and returns None
|
| 110 |
+
* ignore: If the module is not installed, return None, otherwise,
|
| 111 |
+
return the module, even if the version is too old.
|
| 112 |
+
It's expected that users validate the version locally when
|
| 113 |
+
using ``errors="ignore"`` (see. ``io/html.py``)
|
| 114 |
+
min_version : str, default None
|
| 115 |
+
Specify a minimum version that is different from the global pandas
|
| 116 |
+
minimum version required.
|
| 117 |
+
Returns
|
| 118 |
+
-------
|
| 119 |
+
maybe_module : Optional[ModuleType]
|
| 120 |
+
The imported module, when found and the version is correct.
|
| 121 |
+
None is returned when the package is not found and `errors`
|
| 122 |
+
is False, or when the package's version is too old and `errors`
|
| 123 |
+
is ``'warn'`` or ``'ignore'``.
|
| 124 |
+
"""
|
| 125 |
+
assert errors in {"warn", "raise", "ignore"}
|
| 126 |
+
|
| 127 |
+
package_name = INSTALL_MAPPING.get(name)
|
| 128 |
+
install_name = package_name if package_name is not None else name
|
| 129 |
+
|
| 130 |
+
msg = (
|
| 131 |
+
f"Missing optional dependency '{install_name}'. {extra} "
|
| 132 |
+
f"Use pip or conda to install {install_name}."
|
| 133 |
+
)
|
| 134 |
+
try:
|
| 135 |
+
module = importlib.import_module(name)
|
| 136 |
+
except ImportError:
|
| 137 |
+
if errors == "raise":
|
| 138 |
+
raise ImportError(msg)
|
| 139 |
+
return None
|
| 140 |
+
|
| 141 |
+
# Handle submodules: if we have submodule, grab parent module from sys.modules
|
| 142 |
+
parent = name.split(".")[0]
|
| 143 |
+
if parent != name:
|
| 144 |
+
install_name = parent
|
| 145 |
+
module_to_get = sys.modules[install_name]
|
| 146 |
+
else:
|
| 147 |
+
module_to_get = module
|
| 148 |
+
minimum_version = min_version if min_version is not None else VERSIONS.get(parent)
|
| 149 |
+
if minimum_version:
|
| 150 |
+
version = get_version(module_to_get)
|
| 151 |
+
if version and Version(version) < Version(minimum_version):
|
| 152 |
+
msg = (
|
| 153 |
+
f"Pandas requires version '{minimum_version}' or newer of '{parent}' "
|
| 154 |
+
f"(version '{version}' currently installed)."
|
| 155 |
+
)
|
| 156 |
+
if errors == "warn":
|
| 157 |
+
warnings.warn(
|
| 158 |
+
msg,
|
| 159 |
+
UserWarning,
|
| 160 |
+
stacklevel=find_stack_level(),
|
| 161 |
+
)
|
| 162 |
+
return None
|
| 163 |
+
elif errors == "raise":
|
| 164 |
+
raise ImportError(msg)
|
| 165 |
+
else:
|
| 166 |
+
return None
|
| 167 |
+
|
| 168 |
+
return module
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/compressors.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Patched ``BZ2File`` and ``LZMAFile`` to handle pickle protocol 5.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
from pickle import PickleBuffer
|
| 8 |
+
|
| 9 |
+
from pandas.compat._constants import PY310
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
import bz2
|
| 13 |
+
|
| 14 |
+
has_bz2 = True
|
| 15 |
+
except ImportError:
|
| 16 |
+
has_bz2 = False
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
import lzma
|
| 20 |
+
|
| 21 |
+
has_lzma = True
|
| 22 |
+
except ImportError:
|
| 23 |
+
has_lzma = False
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def flatten_buffer(
|
| 27 |
+
b: bytes | bytearray | memoryview | PickleBuffer,
|
| 28 |
+
) -> bytes | bytearray | memoryview:
|
| 29 |
+
"""
|
| 30 |
+
Return some 1-D `uint8` typed buffer.
|
| 31 |
+
|
| 32 |
+
Coerces anything that does not match that description to one that does
|
| 33 |
+
without copying if possible (otherwise will copy).
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
if isinstance(b, (bytes, bytearray)):
|
| 37 |
+
return b
|
| 38 |
+
|
| 39 |
+
if not isinstance(b, PickleBuffer):
|
| 40 |
+
b = PickleBuffer(b)
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
# coerce to 1-D `uint8` C-contiguous `memoryview` zero-copy
|
| 44 |
+
return b.raw()
|
| 45 |
+
except BufferError:
|
| 46 |
+
# perform in-memory copy if buffer is not contiguous
|
| 47 |
+
return memoryview(b).tobytes("A")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if has_bz2:
|
| 51 |
+
|
| 52 |
+
class BZ2File(bz2.BZ2File):
|
| 53 |
+
if not PY310:
|
| 54 |
+
|
| 55 |
+
def write(self, b) -> int:
|
| 56 |
+
# Workaround issue where `bz2.BZ2File` expects `len`
|
| 57 |
+
# to return the number of bytes in `b` by converting
|
| 58 |
+
# `b` into something that meets that constraint with
|
| 59 |
+
# minimal copying.
|
| 60 |
+
#
|
| 61 |
+
# Note: This is fixed in Python 3.10.
|
| 62 |
+
return super().write(flatten_buffer(b))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
if has_lzma:
|
| 66 |
+
|
| 67 |
+
class LZMAFile(lzma.LZMAFile):
|
| 68 |
+
if not PY310:
|
| 69 |
+
|
| 70 |
+
def write(self, b) -> int:
|
| 71 |
+
# Workaround issue where `lzma.LZMAFile` expects `len`
|
| 72 |
+
# to return the number of bytes in `b` by converting
|
| 73 |
+
# `b` into something that meets that constraint with
|
| 74 |
+
# minimal copying.
|
| 75 |
+
#
|
| 76 |
+
# Note: This is fixed in Python 3.10.
|
| 77 |
+
return super().write(flatten_buffer(b))
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/pickle_compat.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 5 |
+
|
| 6 |
+
import contextlib
|
| 7 |
+
import copy
|
| 8 |
+
import io
|
| 9 |
+
import pickle as pkl
|
| 10 |
+
from typing import TYPE_CHECKING
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
|
| 14 |
+
from pandas._libs.arrays import NDArrayBacked
|
| 15 |
+
from pandas._libs.tslibs import BaseOffset
|
| 16 |
+
|
| 17 |
+
from pandas import Index
|
| 18 |
+
from pandas.core.arrays import (
|
| 19 |
+
DatetimeArray,
|
| 20 |
+
PeriodArray,
|
| 21 |
+
TimedeltaArray,
|
| 22 |
+
)
|
| 23 |
+
from pandas.core.internals import BlockManager
|
| 24 |
+
|
| 25 |
+
if TYPE_CHECKING:
|
| 26 |
+
from collections.abc import Generator
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def load_reduce(self) -> None:
|
| 30 |
+
stack = self.stack
|
| 31 |
+
args = stack.pop()
|
| 32 |
+
func = stack[-1]
|
| 33 |
+
|
| 34 |
+
try:
|
| 35 |
+
stack[-1] = func(*args)
|
| 36 |
+
return
|
| 37 |
+
except TypeError as err:
|
| 38 |
+
# If we have a deprecated function,
|
| 39 |
+
# try to replace and try again.
|
| 40 |
+
|
| 41 |
+
msg = "_reconstruct: First argument must be a sub-type of ndarray"
|
| 42 |
+
|
| 43 |
+
if msg in str(err):
|
| 44 |
+
try:
|
| 45 |
+
cls = args[0]
|
| 46 |
+
stack[-1] = object.__new__(cls)
|
| 47 |
+
return
|
| 48 |
+
except TypeError:
|
| 49 |
+
pass
|
| 50 |
+
elif args and isinstance(args[0], type) and issubclass(args[0], BaseOffset):
|
| 51 |
+
# TypeError: object.__new__(Day) is not safe, use Day.__new__()
|
| 52 |
+
cls = args[0]
|
| 53 |
+
stack[-1] = cls.__new__(*args)
|
| 54 |
+
return
|
| 55 |
+
elif args and issubclass(args[0], PeriodArray):
|
| 56 |
+
cls = args[0]
|
| 57 |
+
stack[-1] = NDArrayBacked.__new__(*args)
|
| 58 |
+
return
|
| 59 |
+
|
| 60 |
+
raise
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# If classes are moved, provide compat here.
|
| 64 |
+
_class_locations_map = {
|
| 65 |
+
("pandas.core.sparse.array", "SparseArray"): ("pandas.core.arrays", "SparseArray"),
|
| 66 |
+
# 15477
|
| 67 |
+
("pandas.core.base", "FrozenNDArray"): ("numpy", "ndarray"),
|
| 68 |
+
# Re-routing unpickle block logic to go through _unpickle_block instead
|
| 69 |
+
# for pandas <= 1.3.5
|
| 70 |
+
("pandas.core.internals.blocks", "new_block"): (
|
| 71 |
+
"pandas._libs.internals",
|
| 72 |
+
"_unpickle_block",
|
| 73 |
+
),
|
| 74 |
+
("pandas.core.indexes.frozen", "FrozenNDArray"): ("numpy", "ndarray"),
|
| 75 |
+
("pandas.core.base", "FrozenList"): ("pandas.core.indexes.frozen", "FrozenList"),
|
| 76 |
+
# 10890
|
| 77 |
+
("pandas.core.series", "TimeSeries"): ("pandas.core.series", "Series"),
|
| 78 |
+
("pandas.sparse.series", "SparseTimeSeries"): (
|
| 79 |
+
"pandas.core.sparse.series",
|
| 80 |
+
"SparseSeries",
|
| 81 |
+
),
|
| 82 |
+
# 12588, extensions moving
|
| 83 |
+
("pandas._sparse", "BlockIndex"): ("pandas._libs.sparse", "BlockIndex"),
|
| 84 |
+
("pandas.tslib", "Timestamp"): ("pandas._libs.tslib", "Timestamp"),
|
| 85 |
+
# 18543 moving period
|
| 86 |
+
("pandas._period", "Period"): ("pandas._libs.tslibs.period", "Period"),
|
| 87 |
+
("pandas._libs.period", "Period"): ("pandas._libs.tslibs.period", "Period"),
|
| 88 |
+
# 18014 moved __nat_unpickle from _libs.tslib-->_libs.tslibs.nattype
|
| 89 |
+
("pandas.tslib", "__nat_unpickle"): (
|
| 90 |
+
"pandas._libs.tslibs.nattype",
|
| 91 |
+
"__nat_unpickle",
|
| 92 |
+
),
|
| 93 |
+
("pandas._libs.tslib", "__nat_unpickle"): (
|
| 94 |
+
"pandas._libs.tslibs.nattype",
|
| 95 |
+
"__nat_unpickle",
|
| 96 |
+
),
|
| 97 |
+
# 15998 top-level dirs moving
|
| 98 |
+
("pandas.sparse.array", "SparseArray"): (
|
| 99 |
+
"pandas.core.arrays.sparse",
|
| 100 |
+
"SparseArray",
|
| 101 |
+
),
|
| 102 |
+
("pandas.indexes.base", "_new_Index"): ("pandas.core.indexes.base", "_new_Index"),
|
| 103 |
+
("pandas.indexes.base", "Index"): ("pandas.core.indexes.base", "Index"),
|
| 104 |
+
("pandas.indexes.numeric", "Int64Index"): (
|
| 105 |
+
"pandas.core.indexes.base",
|
| 106 |
+
"Index", # updated in 50775
|
| 107 |
+
),
|
| 108 |
+
("pandas.indexes.range", "RangeIndex"): ("pandas.core.indexes.range", "RangeIndex"),
|
| 109 |
+
("pandas.indexes.multi", "MultiIndex"): ("pandas.core.indexes.multi", "MultiIndex"),
|
| 110 |
+
("pandas.tseries.index", "_new_DatetimeIndex"): (
|
| 111 |
+
"pandas.core.indexes.datetimes",
|
| 112 |
+
"_new_DatetimeIndex",
|
| 113 |
+
),
|
| 114 |
+
("pandas.tseries.index", "DatetimeIndex"): (
|
| 115 |
+
"pandas.core.indexes.datetimes",
|
| 116 |
+
"DatetimeIndex",
|
| 117 |
+
),
|
| 118 |
+
("pandas.tseries.period", "PeriodIndex"): (
|
| 119 |
+
"pandas.core.indexes.period",
|
| 120 |
+
"PeriodIndex",
|
| 121 |
+
),
|
| 122 |
+
# 19269, arrays moving
|
| 123 |
+
("pandas.core.categorical", "Categorical"): ("pandas.core.arrays", "Categorical"),
|
| 124 |
+
# 19939, add timedeltaindex, float64index compat from 15998 move
|
| 125 |
+
("pandas.tseries.tdi", "TimedeltaIndex"): (
|
| 126 |
+
"pandas.core.indexes.timedeltas",
|
| 127 |
+
"TimedeltaIndex",
|
| 128 |
+
),
|
| 129 |
+
("pandas.indexes.numeric", "Float64Index"): (
|
| 130 |
+
"pandas.core.indexes.base",
|
| 131 |
+
"Index", # updated in 50775
|
| 132 |
+
),
|
| 133 |
+
# 50775, remove Int64Index, UInt64Index & Float64Index from codabase
|
| 134 |
+
("pandas.core.indexes.numeric", "Int64Index"): (
|
| 135 |
+
"pandas.core.indexes.base",
|
| 136 |
+
"Index",
|
| 137 |
+
),
|
| 138 |
+
("pandas.core.indexes.numeric", "UInt64Index"): (
|
| 139 |
+
"pandas.core.indexes.base",
|
| 140 |
+
"Index",
|
| 141 |
+
),
|
| 142 |
+
("pandas.core.indexes.numeric", "Float64Index"): (
|
| 143 |
+
"pandas.core.indexes.base",
|
| 144 |
+
"Index",
|
| 145 |
+
),
|
| 146 |
+
("pandas.core.arrays.sparse.dtype", "SparseDtype"): (
|
| 147 |
+
"pandas.core.dtypes.dtypes",
|
| 148 |
+
"SparseDtype",
|
| 149 |
+
),
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
# our Unpickler sub-class to override methods and some dispatcher
|
| 154 |
+
# functions for compat and uses a non-public class of the pickle module.
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
class Unpickler(pkl._Unpickler):
|
| 158 |
+
def find_class(self, module, name):
|
| 159 |
+
# override superclass
|
| 160 |
+
key = (module, name)
|
| 161 |
+
module, name = _class_locations_map.get(key, key)
|
| 162 |
+
return super().find_class(module, name)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
Unpickler.dispatch = copy.copy(Unpickler.dispatch)
|
| 166 |
+
Unpickler.dispatch[pkl.REDUCE[0]] = load_reduce
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def load_newobj(self) -> None:
|
| 170 |
+
args = self.stack.pop()
|
| 171 |
+
cls = self.stack[-1]
|
| 172 |
+
|
| 173 |
+
# compat
|
| 174 |
+
if issubclass(cls, Index):
|
| 175 |
+
obj = object.__new__(cls)
|
| 176 |
+
elif issubclass(cls, DatetimeArray) and not args:
|
| 177 |
+
arr = np.array([], dtype="M8[ns]")
|
| 178 |
+
obj = cls.__new__(cls, arr, arr.dtype)
|
| 179 |
+
elif issubclass(cls, TimedeltaArray) and not args:
|
| 180 |
+
arr = np.array([], dtype="m8[ns]")
|
| 181 |
+
obj = cls.__new__(cls, arr, arr.dtype)
|
| 182 |
+
elif cls is BlockManager and not args:
|
| 183 |
+
obj = cls.__new__(cls, (), [], False)
|
| 184 |
+
else:
|
| 185 |
+
obj = cls.__new__(cls, *args)
|
| 186 |
+
|
| 187 |
+
self.stack[-1] = obj
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
Unpickler.dispatch[pkl.NEWOBJ[0]] = load_newobj
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def load_newobj_ex(self) -> None:
|
| 194 |
+
kwargs = self.stack.pop()
|
| 195 |
+
args = self.stack.pop()
|
| 196 |
+
cls = self.stack.pop()
|
| 197 |
+
|
| 198 |
+
# compat
|
| 199 |
+
if issubclass(cls, Index):
|
| 200 |
+
obj = object.__new__(cls)
|
| 201 |
+
else:
|
| 202 |
+
obj = cls.__new__(cls, *args, **kwargs)
|
| 203 |
+
self.append(obj)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
try:
|
| 207 |
+
Unpickler.dispatch[pkl.NEWOBJ_EX[0]] = load_newobj_ex
|
| 208 |
+
except (AttributeError, KeyError):
|
| 209 |
+
pass
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def load(fh, encoding: str | None = None, is_verbose: bool = False):
|
| 213 |
+
"""
|
| 214 |
+
Load a pickle, with a provided encoding,
|
| 215 |
+
|
| 216 |
+
Parameters
|
| 217 |
+
----------
|
| 218 |
+
fh : a filelike object
|
| 219 |
+
encoding : an optional encoding
|
| 220 |
+
is_verbose : show exception output
|
| 221 |
+
"""
|
| 222 |
+
try:
|
| 223 |
+
fh.seek(0)
|
| 224 |
+
if encoding is not None:
|
| 225 |
+
up = Unpickler(fh, encoding=encoding)
|
| 226 |
+
else:
|
| 227 |
+
up = Unpickler(fh)
|
| 228 |
+
# "Unpickler" has no attribute "is_verbose" [attr-defined]
|
| 229 |
+
up.is_verbose = is_verbose # type: ignore[attr-defined]
|
| 230 |
+
|
| 231 |
+
return up.load()
|
| 232 |
+
except (ValueError, TypeError):
|
| 233 |
+
raise
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def loads(
|
| 237 |
+
bytes_object: bytes,
|
| 238 |
+
*,
|
| 239 |
+
fix_imports: bool = True,
|
| 240 |
+
encoding: str = "ASCII",
|
| 241 |
+
errors: str = "strict",
|
| 242 |
+
):
|
| 243 |
+
"""
|
| 244 |
+
Analogous to pickle._loads.
|
| 245 |
+
"""
|
| 246 |
+
fd = io.BytesIO(bytes_object)
|
| 247 |
+
return Unpickler(
|
| 248 |
+
fd, fix_imports=fix_imports, encoding=encoding, errors=errors
|
| 249 |
+
).load()
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
@contextlib.contextmanager
|
| 253 |
+
def patch_pickle() -> Generator[None, None, None]:
|
| 254 |
+
"""
|
| 255 |
+
Temporarily patch pickle to use our unpickler.
|
| 256 |
+
"""
|
| 257 |
+
orig_loads = pkl.loads
|
| 258 |
+
try:
|
| 259 |
+
setattr(pkl, "loads", loads)
|
| 260 |
+
yield
|
| 261 |
+
finally:
|
| 262 |
+
setattr(pkl, "loads", orig_loads)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/compat/pyarrow.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" support pyarrow compatibility across versions """
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from pandas.util.version import Version
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
import pyarrow as pa
|
| 9 |
+
|
| 10 |
+
_palv = Version(Version(pa.__version__).base_version)
|
| 11 |
+
pa_version_under10p1 = _palv < Version("10.0.1")
|
| 12 |
+
pa_version_under11p0 = _palv < Version("11.0.0")
|
| 13 |
+
pa_version_under12p0 = _palv < Version("12.0.0")
|
| 14 |
+
pa_version_under13p0 = _palv < Version("13.0.0")
|
| 15 |
+
pa_version_under14p0 = _palv < Version("14.0.0")
|
| 16 |
+
pa_version_under14p1 = _palv < Version("14.0.1")
|
| 17 |
+
pa_version_under15p0 = _palv < Version("15.0.0")
|
| 18 |
+
pa_version_under16p0 = _palv < Version("16.0.0")
|
| 19 |
+
pa_version_under17p0 = _palv < Version("17.0.0")
|
| 20 |
+
except ImportError:
|
| 21 |
+
pa_version_under10p1 = True
|
| 22 |
+
pa_version_under11p0 = True
|
| 23 |
+
pa_version_under12p0 = True
|
| 24 |
+
pa_version_under13p0 = True
|
| 25 |
+
pa_version_under14p0 = True
|
| 26 |
+
pa_version_under14p1 = True
|
| 27 |
+
pa_version_under15p0 = True
|
| 28 |
+
pa_version_under16p0 = True
|
| 29 |
+
pa_version_under17p0 = True
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/__init__.py
ADDED
|
File without changes
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/accessor.py
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
|
| 3 |
+
accessor.py contains base classes for implementing accessor properties
|
| 4 |
+
that can be mixed into or pinned onto other pandas classes.
|
| 5 |
+
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
from typing import (
|
| 10 |
+
Callable,
|
| 11 |
+
final,
|
| 12 |
+
)
|
| 13 |
+
import warnings
|
| 14 |
+
|
| 15 |
+
from pandas.util._decorators import doc
|
| 16 |
+
from pandas.util._exceptions import find_stack_level
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class DirNamesMixin:
|
| 20 |
+
_accessors: set[str] = set()
|
| 21 |
+
_hidden_attrs: frozenset[str] = frozenset()
|
| 22 |
+
|
| 23 |
+
@final
|
| 24 |
+
def _dir_deletions(self) -> set[str]:
|
| 25 |
+
"""
|
| 26 |
+
Delete unwanted __dir__ for this object.
|
| 27 |
+
"""
|
| 28 |
+
return self._accessors | self._hidden_attrs
|
| 29 |
+
|
| 30 |
+
def _dir_additions(self) -> set[str]:
|
| 31 |
+
"""
|
| 32 |
+
Add additional __dir__ for this object.
|
| 33 |
+
"""
|
| 34 |
+
return {accessor for accessor in self._accessors if hasattr(self, accessor)}
|
| 35 |
+
|
| 36 |
+
def __dir__(self) -> list[str]:
|
| 37 |
+
"""
|
| 38 |
+
Provide method name lookup and completion.
|
| 39 |
+
|
| 40 |
+
Notes
|
| 41 |
+
-----
|
| 42 |
+
Only provide 'public' methods.
|
| 43 |
+
"""
|
| 44 |
+
rv = set(super().__dir__())
|
| 45 |
+
rv = (rv - self._dir_deletions()) | self._dir_additions()
|
| 46 |
+
return sorted(rv)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class PandasDelegate:
|
| 50 |
+
"""
|
| 51 |
+
Abstract base class for delegating methods/properties.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
def _delegate_property_get(self, name: str, *args, **kwargs):
|
| 55 |
+
raise TypeError(f"You cannot access the property {name}")
|
| 56 |
+
|
| 57 |
+
def _delegate_property_set(self, name: str, value, *args, **kwargs):
|
| 58 |
+
raise TypeError(f"The property {name} cannot be set")
|
| 59 |
+
|
| 60 |
+
def _delegate_method(self, name: str, *args, **kwargs):
|
| 61 |
+
raise TypeError(f"You cannot call method {name}")
|
| 62 |
+
|
| 63 |
+
@classmethod
|
| 64 |
+
def _add_delegate_accessors(
|
| 65 |
+
cls,
|
| 66 |
+
delegate,
|
| 67 |
+
accessors: list[str],
|
| 68 |
+
typ: str,
|
| 69 |
+
overwrite: bool = False,
|
| 70 |
+
accessor_mapping: Callable[[str], str] = lambda x: x,
|
| 71 |
+
raise_on_missing: bool = True,
|
| 72 |
+
) -> None:
|
| 73 |
+
"""
|
| 74 |
+
Add accessors to cls from the delegate class.
|
| 75 |
+
|
| 76 |
+
Parameters
|
| 77 |
+
----------
|
| 78 |
+
cls
|
| 79 |
+
Class to add the methods/properties to.
|
| 80 |
+
delegate
|
| 81 |
+
Class to get methods/properties and doc-strings.
|
| 82 |
+
accessors : list of str
|
| 83 |
+
List of accessors to add.
|
| 84 |
+
typ : {'property', 'method'}
|
| 85 |
+
overwrite : bool, default False
|
| 86 |
+
Overwrite the method/property in the target class if it exists.
|
| 87 |
+
accessor_mapping: Callable, default lambda x: x
|
| 88 |
+
Callable to map the delegate's function to the cls' function.
|
| 89 |
+
raise_on_missing: bool, default True
|
| 90 |
+
Raise if an accessor does not exist on delegate.
|
| 91 |
+
False skips the missing accessor.
|
| 92 |
+
"""
|
| 93 |
+
|
| 94 |
+
def _create_delegator_property(name: str):
|
| 95 |
+
def _getter(self):
|
| 96 |
+
return self._delegate_property_get(name)
|
| 97 |
+
|
| 98 |
+
def _setter(self, new_values):
|
| 99 |
+
return self._delegate_property_set(name, new_values)
|
| 100 |
+
|
| 101 |
+
_getter.__name__ = name
|
| 102 |
+
_setter.__name__ = name
|
| 103 |
+
|
| 104 |
+
return property(
|
| 105 |
+
fget=_getter,
|
| 106 |
+
fset=_setter,
|
| 107 |
+
doc=getattr(delegate, accessor_mapping(name)).__doc__,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
def _create_delegator_method(name: str):
|
| 111 |
+
def f(self, *args, **kwargs):
|
| 112 |
+
return self._delegate_method(name, *args, **kwargs)
|
| 113 |
+
|
| 114 |
+
f.__name__ = name
|
| 115 |
+
f.__doc__ = getattr(delegate, accessor_mapping(name)).__doc__
|
| 116 |
+
|
| 117 |
+
return f
|
| 118 |
+
|
| 119 |
+
for name in accessors:
|
| 120 |
+
if (
|
| 121 |
+
not raise_on_missing
|
| 122 |
+
and getattr(delegate, accessor_mapping(name), None) is None
|
| 123 |
+
):
|
| 124 |
+
continue
|
| 125 |
+
|
| 126 |
+
if typ == "property":
|
| 127 |
+
f = _create_delegator_property(name)
|
| 128 |
+
else:
|
| 129 |
+
f = _create_delegator_method(name)
|
| 130 |
+
|
| 131 |
+
# don't overwrite existing methods/properties
|
| 132 |
+
if overwrite or not hasattr(cls, name):
|
| 133 |
+
setattr(cls, name, f)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def delegate_names(
|
| 137 |
+
delegate,
|
| 138 |
+
accessors: list[str],
|
| 139 |
+
typ: str,
|
| 140 |
+
overwrite: bool = False,
|
| 141 |
+
accessor_mapping: Callable[[str], str] = lambda x: x,
|
| 142 |
+
raise_on_missing: bool = True,
|
| 143 |
+
):
|
| 144 |
+
"""
|
| 145 |
+
Add delegated names to a class using a class decorator. This provides
|
| 146 |
+
an alternative usage to directly calling `_add_delegate_accessors`
|
| 147 |
+
below a class definition.
|
| 148 |
+
|
| 149 |
+
Parameters
|
| 150 |
+
----------
|
| 151 |
+
delegate : object
|
| 152 |
+
The class to get methods/properties & doc-strings.
|
| 153 |
+
accessors : Sequence[str]
|
| 154 |
+
List of accessor to add.
|
| 155 |
+
typ : {'property', 'method'}
|
| 156 |
+
overwrite : bool, default False
|
| 157 |
+
Overwrite the method/property in the target class if it exists.
|
| 158 |
+
accessor_mapping: Callable, default lambda x: x
|
| 159 |
+
Callable to map the delegate's function to the cls' function.
|
| 160 |
+
raise_on_missing: bool, default True
|
| 161 |
+
Raise if an accessor does not exist on delegate.
|
| 162 |
+
False skips the missing accessor.
|
| 163 |
+
|
| 164 |
+
Returns
|
| 165 |
+
-------
|
| 166 |
+
callable
|
| 167 |
+
A class decorator.
|
| 168 |
+
|
| 169 |
+
Examples
|
| 170 |
+
--------
|
| 171 |
+
@delegate_names(Categorical, ["categories", "ordered"], "property")
|
| 172 |
+
class CategoricalAccessor(PandasDelegate):
|
| 173 |
+
[...]
|
| 174 |
+
"""
|
| 175 |
+
|
| 176 |
+
def add_delegate_accessors(cls):
|
| 177 |
+
cls._add_delegate_accessors(
|
| 178 |
+
delegate,
|
| 179 |
+
accessors,
|
| 180 |
+
typ,
|
| 181 |
+
overwrite=overwrite,
|
| 182 |
+
accessor_mapping=accessor_mapping,
|
| 183 |
+
raise_on_missing=raise_on_missing,
|
| 184 |
+
)
|
| 185 |
+
return cls
|
| 186 |
+
|
| 187 |
+
return add_delegate_accessors
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
# Ported with modifications from xarray; licence at LICENSES/XARRAY_LICENSE
|
| 191 |
+
# https://github.com/pydata/xarray/blob/master/xarray/core/extensions.py
|
| 192 |
+
# 1. We don't need to catch and re-raise AttributeErrors as RuntimeErrors
|
| 193 |
+
# 2. We use a UserWarning instead of a custom Warning
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class CachedAccessor:
|
| 197 |
+
"""
|
| 198 |
+
Custom property-like object.
|
| 199 |
+
|
| 200 |
+
A descriptor for caching accessors.
|
| 201 |
+
|
| 202 |
+
Parameters
|
| 203 |
+
----------
|
| 204 |
+
name : str
|
| 205 |
+
Namespace that will be accessed under, e.g. ``df.foo``.
|
| 206 |
+
accessor : cls
|
| 207 |
+
Class with the extension methods.
|
| 208 |
+
|
| 209 |
+
Notes
|
| 210 |
+
-----
|
| 211 |
+
For accessor, The class's __init__ method assumes that one of
|
| 212 |
+
``Series``, ``DataFrame`` or ``Index`` as the
|
| 213 |
+
single argument ``data``.
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
def __init__(self, name: str, accessor) -> None:
|
| 217 |
+
self._name = name
|
| 218 |
+
self._accessor = accessor
|
| 219 |
+
|
| 220 |
+
def __get__(self, obj, cls):
|
| 221 |
+
if obj is None:
|
| 222 |
+
# we're accessing the attribute of the class, i.e., Dataset.geo
|
| 223 |
+
return self._accessor
|
| 224 |
+
accessor_obj = self._accessor(obj)
|
| 225 |
+
# Replace the property with the accessor object. Inspired by:
|
| 226 |
+
# https://www.pydanny.com/cached-property.html
|
| 227 |
+
# We need to use object.__setattr__ because we overwrite __setattr__ on
|
| 228 |
+
# NDFrame
|
| 229 |
+
object.__setattr__(obj, self._name, accessor_obj)
|
| 230 |
+
return accessor_obj
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
@doc(klass="", others="")
|
| 234 |
+
def _register_accessor(name: str, cls):
|
| 235 |
+
"""
|
| 236 |
+
Register a custom accessor on {klass} objects.
|
| 237 |
+
|
| 238 |
+
Parameters
|
| 239 |
+
----------
|
| 240 |
+
name : str
|
| 241 |
+
Name under which the accessor should be registered. A warning is issued
|
| 242 |
+
if this name conflicts with a preexisting attribute.
|
| 243 |
+
|
| 244 |
+
Returns
|
| 245 |
+
-------
|
| 246 |
+
callable
|
| 247 |
+
A class decorator.
|
| 248 |
+
|
| 249 |
+
See Also
|
| 250 |
+
--------
|
| 251 |
+
register_dataframe_accessor : Register a custom accessor on DataFrame objects.
|
| 252 |
+
register_series_accessor : Register a custom accessor on Series objects.
|
| 253 |
+
register_index_accessor : Register a custom accessor on Index objects.
|
| 254 |
+
|
| 255 |
+
Notes
|
| 256 |
+
-----
|
| 257 |
+
When accessed, your accessor will be initialized with the pandas object
|
| 258 |
+
the user is interacting with. So the signature must be
|
| 259 |
+
|
| 260 |
+
.. code-block:: python
|
| 261 |
+
|
| 262 |
+
def __init__(self, pandas_object): # noqa: E999
|
| 263 |
+
...
|
| 264 |
+
|
| 265 |
+
For consistency with pandas methods, you should raise an ``AttributeError``
|
| 266 |
+
if the data passed to your accessor has an incorrect dtype.
|
| 267 |
+
|
| 268 |
+
>>> pd.Series(['a', 'b']).dt
|
| 269 |
+
Traceback (most recent call last):
|
| 270 |
+
...
|
| 271 |
+
AttributeError: Can only use .dt accessor with datetimelike values
|
| 272 |
+
|
| 273 |
+
Examples
|
| 274 |
+
--------
|
| 275 |
+
In your library code::
|
| 276 |
+
|
| 277 |
+
import pandas as pd
|
| 278 |
+
|
| 279 |
+
@pd.api.extensions.register_dataframe_accessor("geo")
|
| 280 |
+
class GeoAccessor:
|
| 281 |
+
def __init__(self, pandas_obj):
|
| 282 |
+
self._obj = pandas_obj
|
| 283 |
+
|
| 284 |
+
@property
|
| 285 |
+
def center(self):
|
| 286 |
+
# return the geographic center point of this DataFrame
|
| 287 |
+
lat = self._obj.latitude
|
| 288 |
+
lon = self._obj.longitude
|
| 289 |
+
return (float(lon.mean()), float(lat.mean()))
|
| 290 |
+
|
| 291 |
+
def plot(self):
|
| 292 |
+
# plot this array's data on a map, e.g., using Cartopy
|
| 293 |
+
pass
|
| 294 |
+
|
| 295 |
+
Back in an interactive IPython session:
|
| 296 |
+
|
| 297 |
+
.. code-block:: ipython
|
| 298 |
+
|
| 299 |
+
In [1]: ds = pd.DataFrame({{"longitude": np.linspace(0, 10),
|
| 300 |
+
...: "latitude": np.linspace(0, 20)}})
|
| 301 |
+
In [2]: ds.geo.center
|
| 302 |
+
Out[2]: (5.0, 10.0)
|
| 303 |
+
In [3]: ds.geo.plot() # plots data on a map
|
| 304 |
+
"""
|
| 305 |
+
|
| 306 |
+
def decorator(accessor):
|
| 307 |
+
if hasattr(cls, name):
|
| 308 |
+
warnings.warn(
|
| 309 |
+
f"registration of accessor {repr(accessor)} under name "
|
| 310 |
+
f"{repr(name)} for type {repr(cls)} is overriding a preexisting "
|
| 311 |
+
f"attribute with the same name.",
|
| 312 |
+
UserWarning,
|
| 313 |
+
stacklevel=find_stack_level(),
|
| 314 |
+
)
|
| 315 |
+
setattr(cls, name, CachedAccessor(name, accessor))
|
| 316 |
+
cls._accessors.add(name)
|
| 317 |
+
return accessor
|
| 318 |
+
|
| 319 |
+
return decorator
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
@doc(_register_accessor, klass="DataFrame")
|
| 323 |
+
def register_dataframe_accessor(name: str):
|
| 324 |
+
from pandas import DataFrame
|
| 325 |
+
|
| 326 |
+
return _register_accessor(name, DataFrame)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
@doc(_register_accessor, klass="Series")
|
| 330 |
+
def register_series_accessor(name: str):
|
| 331 |
+
from pandas import Series
|
| 332 |
+
|
| 333 |
+
return _register_accessor(name, Series)
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
@doc(_register_accessor, klass="Index")
|
| 337 |
+
def register_index_accessor(name: str):
|
| 338 |
+
from pandas import Index
|
| 339 |
+
|
| 340 |
+
return _register_accessor(name, Index)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/api.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pandas._libs import (
|
| 2 |
+
NaT,
|
| 3 |
+
Period,
|
| 4 |
+
Timedelta,
|
| 5 |
+
Timestamp,
|
| 6 |
+
)
|
| 7 |
+
from pandas._libs.missing import NA
|
| 8 |
+
|
| 9 |
+
from pandas.core.dtypes.dtypes import (
|
| 10 |
+
ArrowDtype,
|
| 11 |
+
CategoricalDtype,
|
| 12 |
+
DatetimeTZDtype,
|
| 13 |
+
IntervalDtype,
|
| 14 |
+
PeriodDtype,
|
| 15 |
+
)
|
| 16 |
+
from pandas.core.dtypes.missing import (
|
| 17 |
+
isna,
|
| 18 |
+
isnull,
|
| 19 |
+
notna,
|
| 20 |
+
notnull,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
from pandas.core.algorithms import (
|
| 24 |
+
factorize,
|
| 25 |
+
unique,
|
| 26 |
+
value_counts,
|
| 27 |
+
)
|
| 28 |
+
from pandas.core.arrays import Categorical
|
| 29 |
+
from pandas.core.arrays.boolean import BooleanDtype
|
| 30 |
+
from pandas.core.arrays.floating import (
|
| 31 |
+
Float32Dtype,
|
| 32 |
+
Float64Dtype,
|
| 33 |
+
)
|
| 34 |
+
from pandas.core.arrays.integer import (
|
| 35 |
+
Int8Dtype,
|
| 36 |
+
Int16Dtype,
|
| 37 |
+
Int32Dtype,
|
| 38 |
+
Int64Dtype,
|
| 39 |
+
UInt8Dtype,
|
| 40 |
+
UInt16Dtype,
|
| 41 |
+
UInt32Dtype,
|
| 42 |
+
UInt64Dtype,
|
| 43 |
+
)
|
| 44 |
+
from pandas.core.arrays.string_ import StringDtype
|
| 45 |
+
from pandas.core.construction import array
|
| 46 |
+
from pandas.core.flags import Flags
|
| 47 |
+
from pandas.core.groupby import (
|
| 48 |
+
Grouper,
|
| 49 |
+
NamedAgg,
|
| 50 |
+
)
|
| 51 |
+
from pandas.core.indexes.api import (
|
| 52 |
+
CategoricalIndex,
|
| 53 |
+
DatetimeIndex,
|
| 54 |
+
Index,
|
| 55 |
+
IntervalIndex,
|
| 56 |
+
MultiIndex,
|
| 57 |
+
PeriodIndex,
|
| 58 |
+
RangeIndex,
|
| 59 |
+
TimedeltaIndex,
|
| 60 |
+
)
|
| 61 |
+
from pandas.core.indexes.datetimes import (
|
| 62 |
+
bdate_range,
|
| 63 |
+
date_range,
|
| 64 |
+
)
|
| 65 |
+
from pandas.core.indexes.interval import (
|
| 66 |
+
Interval,
|
| 67 |
+
interval_range,
|
| 68 |
+
)
|
| 69 |
+
from pandas.core.indexes.period import period_range
|
| 70 |
+
from pandas.core.indexes.timedeltas import timedelta_range
|
| 71 |
+
from pandas.core.indexing import IndexSlice
|
| 72 |
+
from pandas.core.series import Series
|
| 73 |
+
from pandas.core.tools.datetimes import to_datetime
|
| 74 |
+
from pandas.core.tools.numeric import to_numeric
|
| 75 |
+
from pandas.core.tools.timedeltas import to_timedelta
|
| 76 |
+
|
| 77 |
+
from pandas.io.formats.format import set_eng_float_format
|
| 78 |
+
from pandas.tseries.offsets import DateOffset
|
| 79 |
+
|
| 80 |
+
# DataFrame needs to be imported after NamedAgg to avoid a circular import
|
| 81 |
+
from pandas.core.frame import DataFrame # isort:skip
|
| 82 |
+
|
| 83 |
+
__all__ = [
|
| 84 |
+
"array",
|
| 85 |
+
"ArrowDtype",
|
| 86 |
+
"bdate_range",
|
| 87 |
+
"BooleanDtype",
|
| 88 |
+
"Categorical",
|
| 89 |
+
"CategoricalDtype",
|
| 90 |
+
"CategoricalIndex",
|
| 91 |
+
"DataFrame",
|
| 92 |
+
"DateOffset",
|
| 93 |
+
"date_range",
|
| 94 |
+
"DatetimeIndex",
|
| 95 |
+
"DatetimeTZDtype",
|
| 96 |
+
"factorize",
|
| 97 |
+
"Flags",
|
| 98 |
+
"Float32Dtype",
|
| 99 |
+
"Float64Dtype",
|
| 100 |
+
"Grouper",
|
| 101 |
+
"Index",
|
| 102 |
+
"IndexSlice",
|
| 103 |
+
"Int16Dtype",
|
| 104 |
+
"Int32Dtype",
|
| 105 |
+
"Int64Dtype",
|
| 106 |
+
"Int8Dtype",
|
| 107 |
+
"Interval",
|
| 108 |
+
"IntervalDtype",
|
| 109 |
+
"IntervalIndex",
|
| 110 |
+
"interval_range",
|
| 111 |
+
"isna",
|
| 112 |
+
"isnull",
|
| 113 |
+
"MultiIndex",
|
| 114 |
+
"NA",
|
| 115 |
+
"NamedAgg",
|
| 116 |
+
"NaT",
|
| 117 |
+
"notna",
|
| 118 |
+
"notnull",
|
| 119 |
+
"Period",
|
| 120 |
+
"PeriodDtype",
|
| 121 |
+
"PeriodIndex",
|
| 122 |
+
"period_range",
|
| 123 |
+
"RangeIndex",
|
| 124 |
+
"Series",
|
| 125 |
+
"set_eng_float_format",
|
| 126 |
+
"StringDtype",
|
| 127 |
+
"Timedelta",
|
| 128 |
+
"TimedeltaIndex",
|
| 129 |
+
"timedelta_range",
|
| 130 |
+
"Timestamp",
|
| 131 |
+
"to_datetime",
|
| 132 |
+
"to_numeric",
|
| 133 |
+
"to_timedelta",
|
| 134 |
+
"UInt16Dtype",
|
| 135 |
+
"UInt32Dtype",
|
| 136 |
+
"UInt64Dtype",
|
| 137 |
+
"UInt8Dtype",
|
| 138 |
+
"unique",
|
| 139 |
+
"value_counts",
|
| 140 |
+
]
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/apply.py
ADDED
|
@@ -0,0 +1,2062 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import abc
|
| 4 |
+
from collections import defaultdict
|
| 5 |
+
import functools
|
| 6 |
+
from functools import partial
|
| 7 |
+
import inspect
|
| 8 |
+
from typing import (
|
| 9 |
+
TYPE_CHECKING,
|
| 10 |
+
Any,
|
| 11 |
+
Callable,
|
| 12 |
+
Literal,
|
| 13 |
+
cast,
|
| 14 |
+
)
|
| 15 |
+
import warnings
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
|
| 19 |
+
from pandas._config import option_context
|
| 20 |
+
|
| 21 |
+
from pandas._libs import lib
|
| 22 |
+
from pandas._libs.internals import BlockValuesRefs
|
| 23 |
+
from pandas._typing import (
|
| 24 |
+
AggFuncType,
|
| 25 |
+
AggFuncTypeBase,
|
| 26 |
+
AggFuncTypeDict,
|
| 27 |
+
AggObjType,
|
| 28 |
+
Axis,
|
| 29 |
+
AxisInt,
|
| 30 |
+
NDFrameT,
|
| 31 |
+
npt,
|
| 32 |
+
)
|
| 33 |
+
from pandas.compat._optional import import_optional_dependency
|
| 34 |
+
from pandas.errors import SpecificationError
|
| 35 |
+
from pandas.util._decorators import cache_readonly
|
| 36 |
+
from pandas.util._exceptions import find_stack_level
|
| 37 |
+
|
| 38 |
+
from pandas.core.dtypes.cast import is_nested_object
|
| 39 |
+
from pandas.core.dtypes.common import (
|
| 40 |
+
is_dict_like,
|
| 41 |
+
is_extension_array_dtype,
|
| 42 |
+
is_list_like,
|
| 43 |
+
is_numeric_dtype,
|
| 44 |
+
is_sequence,
|
| 45 |
+
)
|
| 46 |
+
from pandas.core.dtypes.dtypes import (
|
| 47 |
+
CategoricalDtype,
|
| 48 |
+
ExtensionDtype,
|
| 49 |
+
)
|
| 50 |
+
from pandas.core.dtypes.generic import (
|
| 51 |
+
ABCDataFrame,
|
| 52 |
+
ABCNDFrame,
|
| 53 |
+
ABCSeries,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
from pandas.core._numba.executor import generate_apply_looper
|
| 57 |
+
import pandas.core.common as com
|
| 58 |
+
from pandas.core.construction import ensure_wrapped_if_datetimelike
|
| 59 |
+
|
| 60 |
+
if TYPE_CHECKING:
|
| 61 |
+
from collections.abc import (
|
| 62 |
+
Generator,
|
| 63 |
+
Hashable,
|
| 64 |
+
Iterable,
|
| 65 |
+
MutableMapping,
|
| 66 |
+
Sequence,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
from pandas import (
|
| 70 |
+
DataFrame,
|
| 71 |
+
Index,
|
| 72 |
+
Series,
|
| 73 |
+
)
|
| 74 |
+
from pandas.core.groupby import GroupBy
|
| 75 |
+
from pandas.core.resample import Resampler
|
| 76 |
+
from pandas.core.window.rolling import BaseWindow
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
ResType = dict[int, Any]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def frame_apply(
|
| 83 |
+
obj: DataFrame,
|
| 84 |
+
func: AggFuncType,
|
| 85 |
+
axis: Axis = 0,
|
| 86 |
+
raw: bool = False,
|
| 87 |
+
result_type: str | None = None,
|
| 88 |
+
by_row: Literal[False, "compat"] = "compat",
|
| 89 |
+
engine: str = "python",
|
| 90 |
+
engine_kwargs: dict[str, bool] | None = None,
|
| 91 |
+
args=None,
|
| 92 |
+
kwargs=None,
|
| 93 |
+
) -> FrameApply:
|
| 94 |
+
"""construct and return a row or column based frame apply object"""
|
| 95 |
+
axis = obj._get_axis_number(axis)
|
| 96 |
+
klass: type[FrameApply]
|
| 97 |
+
if axis == 0:
|
| 98 |
+
klass = FrameRowApply
|
| 99 |
+
elif axis == 1:
|
| 100 |
+
klass = FrameColumnApply
|
| 101 |
+
|
| 102 |
+
_, func, _, _ = reconstruct_func(func, **kwargs)
|
| 103 |
+
assert func is not None
|
| 104 |
+
|
| 105 |
+
return klass(
|
| 106 |
+
obj,
|
| 107 |
+
func,
|
| 108 |
+
raw=raw,
|
| 109 |
+
result_type=result_type,
|
| 110 |
+
by_row=by_row,
|
| 111 |
+
engine=engine,
|
| 112 |
+
engine_kwargs=engine_kwargs,
|
| 113 |
+
args=args,
|
| 114 |
+
kwargs=kwargs,
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class Apply(metaclass=abc.ABCMeta):
|
| 119 |
+
axis: AxisInt
|
| 120 |
+
|
| 121 |
+
def __init__(
|
| 122 |
+
self,
|
| 123 |
+
obj: AggObjType,
|
| 124 |
+
func: AggFuncType,
|
| 125 |
+
raw: bool,
|
| 126 |
+
result_type: str | None,
|
| 127 |
+
*,
|
| 128 |
+
by_row: Literal[False, "compat", "_compat"] = "compat",
|
| 129 |
+
engine: str = "python",
|
| 130 |
+
engine_kwargs: dict[str, bool] | None = None,
|
| 131 |
+
args,
|
| 132 |
+
kwargs,
|
| 133 |
+
) -> None:
|
| 134 |
+
self.obj = obj
|
| 135 |
+
self.raw = raw
|
| 136 |
+
|
| 137 |
+
assert by_row is False or by_row in ["compat", "_compat"]
|
| 138 |
+
self.by_row = by_row
|
| 139 |
+
|
| 140 |
+
self.args = args or ()
|
| 141 |
+
self.kwargs = kwargs or {}
|
| 142 |
+
|
| 143 |
+
self.engine = engine
|
| 144 |
+
self.engine_kwargs = {} if engine_kwargs is None else engine_kwargs
|
| 145 |
+
|
| 146 |
+
if result_type not in [None, "reduce", "broadcast", "expand"]:
|
| 147 |
+
raise ValueError(
|
| 148 |
+
"invalid value for result_type, must be one "
|
| 149 |
+
"of {None, 'reduce', 'broadcast', 'expand'}"
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
self.result_type = result_type
|
| 153 |
+
|
| 154 |
+
self.func = func
|
| 155 |
+
|
| 156 |
+
@abc.abstractmethod
|
| 157 |
+
def apply(self) -> DataFrame | Series:
|
| 158 |
+
pass
|
| 159 |
+
|
| 160 |
+
@abc.abstractmethod
|
| 161 |
+
def agg_or_apply_list_like(
|
| 162 |
+
self, op_name: Literal["agg", "apply"]
|
| 163 |
+
) -> DataFrame | Series:
|
| 164 |
+
pass
|
| 165 |
+
|
| 166 |
+
@abc.abstractmethod
|
| 167 |
+
def agg_or_apply_dict_like(
|
| 168 |
+
self, op_name: Literal["agg", "apply"]
|
| 169 |
+
) -> DataFrame | Series:
|
| 170 |
+
pass
|
| 171 |
+
|
| 172 |
+
def agg(self) -> DataFrame | Series | None:
|
| 173 |
+
"""
|
| 174 |
+
Provide an implementation for the aggregators.
|
| 175 |
+
|
| 176 |
+
Returns
|
| 177 |
+
-------
|
| 178 |
+
Result of aggregation, or None if agg cannot be performed by
|
| 179 |
+
this method.
|
| 180 |
+
"""
|
| 181 |
+
obj = self.obj
|
| 182 |
+
func = self.func
|
| 183 |
+
args = self.args
|
| 184 |
+
kwargs = self.kwargs
|
| 185 |
+
|
| 186 |
+
if isinstance(func, str):
|
| 187 |
+
return self.apply_str()
|
| 188 |
+
|
| 189 |
+
if is_dict_like(func):
|
| 190 |
+
return self.agg_dict_like()
|
| 191 |
+
elif is_list_like(func):
|
| 192 |
+
# we require a list, but not a 'str'
|
| 193 |
+
return self.agg_list_like()
|
| 194 |
+
|
| 195 |
+
if callable(func):
|
| 196 |
+
f = com.get_cython_func(func)
|
| 197 |
+
if f and not args and not kwargs:
|
| 198 |
+
warn_alias_replacement(obj, func, f)
|
| 199 |
+
return getattr(obj, f)()
|
| 200 |
+
|
| 201 |
+
# caller can react
|
| 202 |
+
return None
|
| 203 |
+
|
| 204 |
+
def transform(self) -> DataFrame | Series:
|
| 205 |
+
"""
|
| 206 |
+
Transform a DataFrame or Series.
|
| 207 |
+
|
| 208 |
+
Returns
|
| 209 |
+
-------
|
| 210 |
+
DataFrame or Series
|
| 211 |
+
Result of applying ``func`` along the given axis of the
|
| 212 |
+
Series or DataFrame.
|
| 213 |
+
|
| 214 |
+
Raises
|
| 215 |
+
------
|
| 216 |
+
ValueError
|
| 217 |
+
If the transform function fails or does not transform.
|
| 218 |
+
"""
|
| 219 |
+
obj = self.obj
|
| 220 |
+
func = self.func
|
| 221 |
+
axis = self.axis
|
| 222 |
+
args = self.args
|
| 223 |
+
kwargs = self.kwargs
|
| 224 |
+
|
| 225 |
+
is_series = obj.ndim == 1
|
| 226 |
+
|
| 227 |
+
if obj._get_axis_number(axis) == 1:
|
| 228 |
+
assert not is_series
|
| 229 |
+
return obj.T.transform(func, 0, *args, **kwargs).T
|
| 230 |
+
|
| 231 |
+
if is_list_like(func) and not is_dict_like(func):
|
| 232 |
+
func = cast(list[AggFuncTypeBase], func)
|
| 233 |
+
# Convert func equivalent dict
|
| 234 |
+
if is_series:
|
| 235 |
+
func = {com.get_callable_name(v) or v: v for v in func}
|
| 236 |
+
else:
|
| 237 |
+
func = {col: func for col in obj}
|
| 238 |
+
|
| 239 |
+
if is_dict_like(func):
|
| 240 |
+
func = cast(AggFuncTypeDict, func)
|
| 241 |
+
return self.transform_dict_like(func)
|
| 242 |
+
|
| 243 |
+
# func is either str or callable
|
| 244 |
+
func = cast(AggFuncTypeBase, func)
|
| 245 |
+
try:
|
| 246 |
+
result = self.transform_str_or_callable(func)
|
| 247 |
+
except TypeError:
|
| 248 |
+
raise
|
| 249 |
+
except Exception as err:
|
| 250 |
+
raise ValueError("Transform function failed") from err
|
| 251 |
+
|
| 252 |
+
# Functions that transform may return empty Series/DataFrame
|
| 253 |
+
# when the dtype is not appropriate
|
| 254 |
+
if (
|
| 255 |
+
isinstance(result, (ABCSeries, ABCDataFrame))
|
| 256 |
+
and result.empty
|
| 257 |
+
and not obj.empty
|
| 258 |
+
):
|
| 259 |
+
raise ValueError("Transform function failed")
|
| 260 |
+
# error: Argument 1 to "__get__" of "AxisProperty" has incompatible type
|
| 261 |
+
# "Union[Series, DataFrame, GroupBy[Any], SeriesGroupBy,
|
| 262 |
+
# DataFrameGroupBy, BaseWindow, Resampler]"; expected "Union[DataFrame,
|
| 263 |
+
# Series]"
|
| 264 |
+
if not isinstance(result, (ABCSeries, ABCDataFrame)) or not result.index.equals(
|
| 265 |
+
obj.index # type: ignore[arg-type]
|
| 266 |
+
):
|
| 267 |
+
raise ValueError("Function did not transform")
|
| 268 |
+
|
| 269 |
+
return result
|
| 270 |
+
|
| 271 |
+
def transform_dict_like(self, func) -> DataFrame:
|
| 272 |
+
"""
|
| 273 |
+
Compute transform in the case of a dict-like func
|
| 274 |
+
"""
|
| 275 |
+
from pandas.core.reshape.concat import concat
|
| 276 |
+
|
| 277 |
+
obj = self.obj
|
| 278 |
+
args = self.args
|
| 279 |
+
kwargs = self.kwargs
|
| 280 |
+
|
| 281 |
+
# transform is currently only for Series/DataFrame
|
| 282 |
+
assert isinstance(obj, ABCNDFrame)
|
| 283 |
+
|
| 284 |
+
if len(func) == 0:
|
| 285 |
+
raise ValueError("No transform functions were provided")
|
| 286 |
+
|
| 287 |
+
func = self.normalize_dictlike_arg("transform", obj, func)
|
| 288 |
+
|
| 289 |
+
results: dict[Hashable, DataFrame | Series] = {}
|
| 290 |
+
for name, how in func.items():
|
| 291 |
+
colg = obj._gotitem(name, ndim=1)
|
| 292 |
+
results[name] = colg.transform(how, 0, *args, **kwargs)
|
| 293 |
+
return concat(results, axis=1)
|
| 294 |
+
|
| 295 |
+
def transform_str_or_callable(self, func) -> DataFrame | Series:
|
| 296 |
+
"""
|
| 297 |
+
Compute transform in the case of a string or callable func
|
| 298 |
+
"""
|
| 299 |
+
obj = self.obj
|
| 300 |
+
args = self.args
|
| 301 |
+
kwargs = self.kwargs
|
| 302 |
+
|
| 303 |
+
if isinstance(func, str):
|
| 304 |
+
return self._apply_str(obj, func, *args, **kwargs)
|
| 305 |
+
|
| 306 |
+
if not args and not kwargs:
|
| 307 |
+
f = com.get_cython_func(func)
|
| 308 |
+
if f:
|
| 309 |
+
warn_alias_replacement(obj, func, f)
|
| 310 |
+
return getattr(obj, f)()
|
| 311 |
+
|
| 312 |
+
# Two possible ways to use a UDF - apply or call directly
|
| 313 |
+
try:
|
| 314 |
+
return obj.apply(func, args=args, **kwargs)
|
| 315 |
+
except Exception:
|
| 316 |
+
return func(obj, *args, **kwargs)
|
| 317 |
+
|
| 318 |
+
def agg_list_like(self) -> DataFrame | Series:
|
| 319 |
+
"""
|
| 320 |
+
Compute aggregation in the case of a list-like argument.
|
| 321 |
+
|
| 322 |
+
Returns
|
| 323 |
+
-------
|
| 324 |
+
Result of aggregation.
|
| 325 |
+
"""
|
| 326 |
+
return self.agg_or_apply_list_like(op_name="agg")
|
| 327 |
+
|
| 328 |
+
def compute_list_like(
|
| 329 |
+
self,
|
| 330 |
+
op_name: Literal["agg", "apply"],
|
| 331 |
+
selected_obj: Series | DataFrame,
|
| 332 |
+
kwargs: dict[str, Any],
|
| 333 |
+
) -> tuple[list[Hashable] | Index, list[Any]]:
|
| 334 |
+
"""
|
| 335 |
+
Compute agg/apply results for like-like input.
|
| 336 |
+
|
| 337 |
+
Parameters
|
| 338 |
+
----------
|
| 339 |
+
op_name : {"agg", "apply"}
|
| 340 |
+
Operation being performed.
|
| 341 |
+
selected_obj : Series or DataFrame
|
| 342 |
+
Data to perform operation on.
|
| 343 |
+
kwargs : dict
|
| 344 |
+
Keyword arguments to pass to the functions.
|
| 345 |
+
|
| 346 |
+
Returns
|
| 347 |
+
-------
|
| 348 |
+
keys : list[Hashable] or Index
|
| 349 |
+
Index labels for result.
|
| 350 |
+
results : list
|
| 351 |
+
Data for result. When aggregating with a Series, this can contain any
|
| 352 |
+
Python objects.
|
| 353 |
+
"""
|
| 354 |
+
func = cast(list[AggFuncTypeBase], self.func)
|
| 355 |
+
obj = self.obj
|
| 356 |
+
|
| 357 |
+
results = []
|
| 358 |
+
keys = []
|
| 359 |
+
|
| 360 |
+
# degenerate case
|
| 361 |
+
if selected_obj.ndim == 1:
|
| 362 |
+
for a in func:
|
| 363 |
+
colg = obj._gotitem(selected_obj.name, ndim=1, subset=selected_obj)
|
| 364 |
+
args = (
|
| 365 |
+
[self.axis, *self.args]
|
| 366 |
+
if include_axis(op_name, colg)
|
| 367 |
+
else self.args
|
| 368 |
+
)
|
| 369 |
+
new_res = getattr(colg, op_name)(a, *args, **kwargs)
|
| 370 |
+
results.append(new_res)
|
| 371 |
+
|
| 372 |
+
# make sure we find a good name
|
| 373 |
+
name = com.get_callable_name(a) or a
|
| 374 |
+
keys.append(name)
|
| 375 |
+
|
| 376 |
+
else:
|
| 377 |
+
indices = []
|
| 378 |
+
for index, col in enumerate(selected_obj):
|
| 379 |
+
colg = obj._gotitem(col, ndim=1, subset=selected_obj.iloc[:, index])
|
| 380 |
+
args = (
|
| 381 |
+
[self.axis, *self.args]
|
| 382 |
+
if include_axis(op_name, colg)
|
| 383 |
+
else self.args
|
| 384 |
+
)
|
| 385 |
+
new_res = getattr(colg, op_name)(func, *args, **kwargs)
|
| 386 |
+
results.append(new_res)
|
| 387 |
+
indices.append(index)
|
| 388 |
+
# error: Incompatible types in assignment (expression has type "Any |
|
| 389 |
+
# Index", variable has type "list[Any | Callable[..., Any] | str]")
|
| 390 |
+
keys = selected_obj.columns.take(indices) # type: ignore[assignment]
|
| 391 |
+
|
| 392 |
+
return keys, results
|
| 393 |
+
|
| 394 |
+
def wrap_results_list_like(
|
| 395 |
+
self, keys: Iterable[Hashable], results: list[Series | DataFrame]
|
| 396 |
+
):
|
| 397 |
+
from pandas.core.reshape.concat import concat
|
| 398 |
+
|
| 399 |
+
obj = self.obj
|
| 400 |
+
|
| 401 |
+
try:
|
| 402 |
+
return concat(results, keys=keys, axis=1, sort=False)
|
| 403 |
+
except TypeError as err:
|
| 404 |
+
# we are concatting non-NDFrame objects,
|
| 405 |
+
# e.g. a list of scalars
|
| 406 |
+
from pandas import Series
|
| 407 |
+
|
| 408 |
+
result = Series(results, index=keys, name=obj.name)
|
| 409 |
+
if is_nested_object(result):
|
| 410 |
+
raise ValueError(
|
| 411 |
+
"cannot combine transform and aggregation operations"
|
| 412 |
+
) from err
|
| 413 |
+
return result
|
| 414 |
+
|
| 415 |
+
def agg_dict_like(self) -> DataFrame | Series:
|
| 416 |
+
"""
|
| 417 |
+
Compute aggregation in the case of a dict-like argument.
|
| 418 |
+
|
| 419 |
+
Returns
|
| 420 |
+
-------
|
| 421 |
+
Result of aggregation.
|
| 422 |
+
"""
|
| 423 |
+
return self.agg_or_apply_dict_like(op_name="agg")
|
| 424 |
+
|
| 425 |
+
def compute_dict_like(
|
| 426 |
+
self,
|
| 427 |
+
op_name: Literal["agg", "apply"],
|
| 428 |
+
selected_obj: Series | DataFrame,
|
| 429 |
+
selection: Hashable | Sequence[Hashable],
|
| 430 |
+
kwargs: dict[str, Any],
|
| 431 |
+
) -> tuple[list[Hashable], list[Any]]:
|
| 432 |
+
"""
|
| 433 |
+
Compute agg/apply results for dict-like input.
|
| 434 |
+
|
| 435 |
+
Parameters
|
| 436 |
+
----------
|
| 437 |
+
op_name : {"agg", "apply"}
|
| 438 |
+
Operation being performed.
|
| 439 |
+
selected_obj : Series or DataFrame
|
| 440 |
+
Data to perform operation on.
|
| 441 |
+
selection : hashable or sequence of hashables
|
| 442 |
+
Used by GroupBy, Window, and Resample if selection is applied to the object.
|
| 443 |
+
kwargs : dict
|
| 444 |
+
Keyword arguments to pass to the functions.
|
| 445 |
+
|
| 446 |
+
Returns
|
| 447 |
+
-------
|
| 448 |
+
keys : list[hashable]
|
| 449 |
+
Index labels for result.
|
| 450 |
+
results : list
|
| 451 |
+
Data for result. When aggregating with a Series, this can contain any
|
| 452 |
+
Python object.
|
| 453 |
+
"""
|
| 454 |
+
from pandas.core.groupby.generic import (
|
| 455 |
+
DataFrameGroupBy,
|
| 456 |
+
SeriesGroupBy,
|
| 457 |
+
)
|
| 458 |
+
|
| 459 |
+
obj = self.obj
|
| 460 |
+
is_groupby = isinstance(obj, (DataFrameGroupBy, SeriesGroupBy))
|
| 461 |
+
func = cast(AggFuncTypeDict, self.func)
|
| 462 |
+
func = self.normalize_dictlike_arg(op_name, selected_obj, func)
|
| 463 |
+
|
| 464 |
+
is_non_unique_col = (
|
| 465 |
+
selected_obj.ndim == 2
|
| 466 |
+
and selected_obj.columns.nunique() < len(selected_obj.columns)
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
if selected_obj.ndim == 1:
|
| 470 |
+
# key only used for output
|
| 471 |
+
colg = obj._gotitem(selection, ndim=1)
|
| 472 |
+
results = [getattr(colg, op_name)(how, **kwargs) for _, how in func.items()]
|
| 473 |
+
keys = list(func.keys())
|
| 474 |
+
elif not is_groupby and is_non_unique_col:
|
| 475 |
+
# key used for column selection and output
|
| 476 |
+
# GH#51099
|
| 477 |
+
results = []
|
| 478 |
+
keys = []
|
| 479 |
+
for key, how in func.items():
|
| 480 |
+
indices = selected_obj.columns.get_indexer_for([key])
|
| 481 |
+
labels = selected_obj.columns.take(indices)
|
| 482 |
+
label_to_indices = defaultdict(list)
|
| 483 |
+
for index, label in zip(indices, labels):
|
| 484 |
+
label_to_indices[label].append(index)
|
| 485 |
+
|
| 486 |
+
key_data = [
|
| 487 |
+
getattr(selected_obj._ixs(indice, axis=1), op_name)(how, **kwargs)
|
| 488 |
+
for label, indices in label_to_indices.items()
|
| 489 |
+
for indice in indices
|
| 490 |
+
]
|
| 491 |
+
|
| 492 |
+
keys += [key] * len(key_data)
|
| 493 |
+
results += key_data
|
| 494 |
+
else:
|
| 495 |
+
# key used for column selection and output
|
| 496 |
+
results = [
|
| 497 |
+
getattr(obj._gotitem(key, ndim=1), op_name)(how, **kwargs)
|
| 498 |
+
for key, how in func.items()
|
| 499 |
+
]
|
| 500 |
+
keys = list(func.keys())
|
| 501 |
+
|
| 502 |
+
return keys, results
|
| 503 |
+
|
| 504 |
+
def wrap_results_dict_like(
|
| 505 |
+
self,
|
| 506 |
+
selected_obj: Series | DataFrame,
|
| 507 |
+
result_index: list[Hashable],
|
| 508 |
+
result_data: list,
|
| 509 |
+
):
|
| 510 |
+
from pandas import Index
|
| 511 |
+
from pandas.core.reshape.concat import concat
|
| 512 |
+
|
| 513 |
+
obj = self.obj
|
| 514 |
+
|
| 515 |
+
# Avoid making two isinstance calls in all and any below
|
| 516 |
+
is_ndframe = [isinstance(r, ABCNDFrame) for r in result_data]
|
| 517 |
+
|
| 518 |
+
if all(is_ndframe):
|
| 519 |
+
results = dict(zip(result_index, result_data))
|
| 520 |
+
keys_to_use: Iterable[Hashable]
|
| 521 |
+
keys_to_use = [k for k in result_index if not results[k].empty]
|
| 522 |
+
# Have to check, if at least one DataFrame is not empty.
|
| 523 |
+
keys_to_use = keys_to_use if keys_to_use != [] else result_index
|
| 524 |
+
if selected_obj.ndim == 2:
|
| 525 |
+
# keys are columns, so we can preserve names
|
| 526 |
+
ktu = Index(keys_to_use)
|
| 527 |
+
ktu._set_names(selected_obj.columns.names)
|
| 528 |
+
keys_to_use = ktu
|
| 529 |
+
|
| 530 |
+
axis: AxisInt = 0 if isinstance(obj, ABCSeries) else 1
|
| 531 |
+
result = concat(
|
| 532 |
+
{k: results[k] for k in keys_to_use},
|
| 533 |
+
axis=axis,
|
| 534 |
+
keys=keys_to_use,
|
| 535 |
+
)
|
| 536 |
+
elif any(is_ndframe):
|
| 537 |
+
# There is a mix of NDFrames and scalars
|
| 538 |
+
raise ValueError(
|
| 539 |
+
"cannot perform both aggregation "
|
| 540 |
+
"and transformation operations "
|
| 541 |
+
"simultaneously"
|
| 542 |
+
)
|
| 543 |
+
else:
|
| 544 |
+
from pandas import Series
|
| 545 |
+
|
| 546 |
+
# we have a list of scalars
|
| 547 |
+
# GH 36212 use name only if obj is a series
|
| 548 |
+
if obj.ndim == 1:
|
| 549 |
+
obj = cast("Series", obj)
|
| 550 |
+
name = obj.name
|
| 551 |
+
else:
|
| 552 |
+
name = None
|
| 553 |
+
|
| 554 |
+
result = Series(result_data, index=result_index, name=name)
|
| 555 |
+
|
| 556 |
+
return result
|
| 557 |
+
|
| 558 |
+
def apply_str(self) -> DataFrame | Series:
|
| 559 |
+
"""
|
| 560 |
+
Compute apply in case of a string.
|
| 561 |
+
|
| 562 |
+
Returns
|
| 563 |
+
-------
|
| 564 |
+
result: Series or DataFrame
|
| 565 |
+
"""
|
| 566 |
+
# Caller is responsible for checking isinstance(self.f, str)
|
| 567 |
+
func = cast(str, self.func)
|
| 568 |
+
|
| 569 |
+
obj = self.obj
|
| 570 |
+
|
| 571 |
+
from pandas.core.groupby.generic import (
|
| 572 |
+
DataFrameGroupBy,
|
| 573 |
+
SeriesGroupBy,
|
| 574 |
+
)
|
| 575 |
+
|
| 576 |
+
# Support for `frame.transform('method')`
|
| 577 |
+
# Some methods (shift, etc.) require the axis argument, others
|
| 578 |
+
# don't, so inspect and insert if necessary.
|
| 579 |
+
method = getattr(obj, func, None)
|
| 580 |
+
if callable(method):
|
| 581 |
+
sig = inspect.getfullargspec(method)
|
| 582 |
+
arg_names = (*sig.args, *sig.kwonlyargs)
|
| 583 |
+
if self.axis != 0 and (
|
| 584 |
+
"axis" not in arg_names or func in ("corrwith", "skew")
|
| 585 |
+
):
|
| 586 |
+
raise ValueError(f"Operation {func} does not support axis=1")
|
| 587 |
+
if "axis" in arg_names:
|
| 588 |
+
if isinstance(obj, (SeriesGroupBy, DataFrameGroupBy)):
|
| 589 |
+
# Try to avoid FutureWarning for deprecated axis keyword;
|
| 590 |
+
# If self.axis matches the axis we would get by not passing
|
| 591 |
+
# axis, we safely exclude the keyword.
|
| 592 |
+
|
| 593 |
+
default_axis = 0
|
| 594 |
+
if func in ["idxmax", "idxmin"]:
|
| 595 |
+
# DataFrameGroupBy.idxmax, idxmin axis defaults to self.axis,
|
| 596 |
+
# whereas other axis keywords default to 0
|
| 597 |
+
default_axis = self.obj.axis
|
| 598 |
+
|
| 599 |
+
if default_axis != self.axis:
|
| 600 |
+
self.kwargs["axis"] = self.axis
|
| 601 |
+
else:
|
| 602 |
+
self.kwargs["axis"] = self.axis
|
| 603 |
+
return self._apply_str(obj, func, *self.args, **self.kwargs)
|
| 604 |
+
|
| 605 |
+
def apply_list_or_dict_like(self) -> DataFrame | Series:
|
| 606 |
+
"""
|
| 607 |
+
Compute apply in case of a list-like or dict-like.
|
| 608 |
+
|
| 609 |
+
Returns
|
| 610 |
+
-------
|
| 611 |
+
result: Series, DataFrame, or None
|
| 612 |
+
Result when self.func is a list-like or dict-like, None otherwise.
|
| 613 |
+
"""
|
| 614 |
+
|
| 615 |
+
if self.engine == "numba":
|
| 616 |
+
raise NotImplementedError(
|
| 617 |
+
"The 'numba' engine doesn't support list-like/"
|
| 618 |
+
"dict likes of callables yet."
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
if self.axis == 1 and isinstance(self.obj, ABCDataFrame):
|
| 622 |
+
return self.obj.T.apply(self.func, 0, args=self.args, **self.kwargs).T
|
| 623 |
+
|
| 624 |
+
func = self.func
|
| 625 |
+
kwargs = self.kwargs
|
| 626 |
+
|
| 627 |
+
if is_dict_like(func):
|
| 628 |
+
result = self.agg_or_apply_dict_like(op_name="apply")
|
| 629 |
+
else:
|
| 630 |
+
result = self.agg_or_apply_list_like(op_name="apply")
|
| 631 |
+
|
| 632 |
+
result = reconstruct_and_relabel_result(result, func, **kwargs)
|
| 633 |
+
|
| 634 |
+
return result
|
| 635 |
+
|
| 636 |
+
def normalize_dictlike_arg(
|
| 637 |
+
self, how: str, obj: DataFrame | Series, func: AggFuncTypeDict
|
| 638 |
+
) -> AggFuncTypeDict:
|
| 639 |
+
"""
|
| 640 |
+
Handler for dict-like argument.
|
| 641 |
+
|
| 642 |
+
Ensures that necessary columns exist if obj is a DataFrame, and
|
| 643 |
+
that a nested renamer is not passed. Also normalizes to all lists
|
| 644 |
+
when values consists of a mix of list and non-lists.
|
| 645 |
+
"""
|
| 646 |
+
assert how in ("apply", "agg", "transform")
|
| 647 |
+
|
| 648 |
+
# Can't use func.values(); wouldn't work for a Series
|
| 649 |
+
if (
|
| 650 |
+
how == "agg"
|
| 651 |
+
and isinstance(obj, ABCSeries)
|
| 652 |
+
and any(is_list_like(v) for _, v in func.items())
|
| 653 |
+
) or (any(is_dict_like(v) for _, v in func.items())):
|
| 654 |
+
# GH 15931 - deprecation of renaming keys
|
| 655 |
+
raise SpecificationError("nested renamer is not supported")
|
| 656 |
+
|
| 657 |
+
if obj.ndim != 1:
|
| 658 |
+
# Check for missing columns on a frame
|
| 659 |
+
from pandas import Index
|
| 660 |
+
|
| 661 |
+
cols = Index(list(func.keys())).difference(obj.columns, sort=True)
|
| 662 |
+
if len(cols) > 0:
|
| 663 |
+
raise KeyError(f"Column(s) {list(cols)} do not exist")
|
| 664 |
+
|
| 665 |
+
aggregator_types = (list, tuple, dict)
|
| 666 |
+
|
| 667 |
+
# if we have a dict of any non-scalars
|
| 668 |
+
# eg. {'A' : ['mean']}, normalize all to
|
| 669 |
+
# be list-likes
|
| 670 |
+
# Cannot use func.values() because arg may be a Series
|
| 671 |
+
if any(isinstance(x, aggregator_types) for _, x in func.items()):
|
| 672 |
+
new_func: AggFuncTypeDict = {}
|
| 673 |
+
for k, v in func.items():
|
| 674 |
+
if not isinstance(v, aggregator_types):
|
| 675 |
+
new_func[k] = [v]
|
| 676 |
+
else:
|
| 677 |
+
new_func[k] = v
|
| 678 |
+
func = new_func
|
| 679 |
+
return func
|
| 680 |
+
|
| 681 |
+
def _apply_str(self, obj, func: str, *args, **kwargs):
|
| 682 |
+
"""
|
| 683 |
+
if arg is a string, then try to operate on it:
|
| 684 |
+
- try to find a function (or attribute) on obj
|
| 685 |
+
- try to find a numpy function
|
| 686 |
+
- raise
|
| 687 |
+
"""
|
| 688 |
+
assert isinstance(func, str)
|
| 689 |
+
|
| 690 |
+
if hasattr(obj, func):
|
| 691 |
+
f = getattr(obj, func)
|
| 692 |
+
if callable(f):
|
| 693 |
+
return f(*args, **kwargs)
|
| 694 |
+
|
| 695 |
+
# people may aggregate on a non-callable attribute
|
| 696 |
+
# but don't let them think they can pass args to it
|
| 697 |
+
assert len(args) == 0
|
| 698 |
+
assert len([kwarg for kwarg in kwargs if kwarg not in ["axis"]]) == 0
|
| 699 |
+
return f
|
| 700 |
+
elif hasattr(np, func) and hasattr(obj, "__array__"):
|
| 701 |
+
# in particular exclude Window
|
| 702 |
+
f = getattr(np, func)
|
| 703 |
+
return f(obj, *args, **kwargs)
|
| 704 |
+
else:
|
| 705 |
+
msg = f"'{func}' is not a valid function for '{type(obj).__name__}' object"
|
| 706 |
+
raise AttributeError(msg)
|
| 707 |
+
|
| 708 |
+
|
| 709 |
+
class NDFrameApply(Apply):
|
| 710 |
+
"""
|
| 711 |
+
Methods shared by FrameApply and SeriesApply but
|
| 712 |
+
not GroupByApply or ResamplerWindowApply
|
| 713 |
+
"""
|
| 714 |
+
|
| 715 |
+
obj: DataFrame | Series
|
| 716 |
+
|
| 717 |
+
@property
|
| 718 |
+
def index(self) -> Index:
|
| 719 |
+
return self.obj.index
|
| 720 |
+
|
| 721 |
+
@property
|
| 722 |
+
def agg_axis(self) -> Index:
|
| 723 |
+
return self.obj._get_agg_axis(self.axis)
|
| 724 |
+
|
| 725 |
+
def agg_or_apply_list_like(
|
| 726 |
+
self, op_name: Literal["agg", "apply"]
|
| 727 |
+
) -> DataFrame | Series:
|
| 728 |
+
obj = self.obj
|
| 729 |
+
kwargs = self.kwargs
|
| 730 |
+
|
| 731 |
+
if op_name == "apply":
|
| 732 |
+
if isinstance(self, FrameApply):
|
| 733 |
+
by_row = self.by_row
|
| 734 |
+
|
| 735 |
+
elif isinstance(self, SeriesApply):
|
| 736 |
+
by_row = "_compat" if self.by_row else False
|
| 737 |
+
else:
|
| 738 |
+
by_row = False
|
| 739 |
+
kwargs = {**kwargs, "by_row": by_row}
|
| 740 |
+
|
| 741 |
+
if getattr(obj, "axis", 0) == 1:
|
| 742 |
+
raise NotImplementedError("axis other than 0 is not supported")
|
| 743 |
+
|
| 744 |
+
keys, results = self.compute_list_like(op_name, obj, kwargs)
|
| 745 |
+
result = self.wrap_results_list_like(keys, results)
|
| 746 |
+
return result
|
| 747 |
+
|
| 748 |
+
def agg_or_apply_dict_like(
|
| 749 |
+
self, op_name: Literal["agg", "apply"]
|
| 750 |
+
) -> DataFrame | Series:
|
| 751 |
+
assert op_name in ["agg", "apply"]
|
| 752 |
+
obj = self.obj
|
| 753 |
+
|
| 754 |
+
kwargs = {}
|
| 755 |
+
if op_name == "apply":
|
| 756 |
+
by_row = "_compat" if self.by_row else False
|
| 757 |
+
kwargs.update({"by_row": by_row})
|
| 758 |
+
|
| 759 |
+
if getattr(obj, "axis", 0) == 1:
|
| 760 |
+
raise NotImplementedError("axis other than 0 is not supported")
|
| 761 |
+
|
| 762 |
+
selection = None
|
| 763 |
+
result_index, result_data = self.compute_dict_like(
|
| 764 |
+
op_name, obj, selection, kwargs
|
| 765 |
+
)
|
| 766 |
+
result = self.wrap_results_dict_like(obj, result_index, result_data)
|
| 767 |
+
return result
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
class FrameApply(NDFrameApply):
|
| 771 |
+
obj: DataFrame
|
| 772 |
+
|
| 773 |
+
def __init__(
|
| 774 |
+
self,
|
| 775 |
+
obj: AggObjType,
|
| 776 |
+
func: AggFuncType,
|
| 777 |
+
raw: bool,
|
| 778 |
+
result_type: str | None,
|
| 779 |
+
*,
|
| 780 |
+
by_row: Literal[False, "compat"] = False,
|
| 781 |
+
engine: str = "python",
|
| 782 |
+
engine_kwargs: dict[str, bool] | None = None,
|
| 783 |
+
args,
|
| 784 |
+
kwargs,
|
| 785 |
+
) -> None:
|
| 786 |
+
if by_row is not False and by_row != "compat":
|
| 787 |
+
raise ValueError(f"by_row={by_row} not allowed")
|
| 788 |
+
super().__init__(
|
| 789 |
+
obj,
|
| 790 |
+
func,
|
| 791 |
+
raw,
|
| 792 |
+
result_type,
|
| 793 |
+
by_row=by_row,
|
| 794 |
+
engine=engine,
|
| 795 |
+
engine_kwargs=engine_kwargs,
|
| 796 |
+
args=args,
|
| 797 |
+
kwargs=kwargs,
|
| 798 |
+
)
|
| 799 |
+
|
| 800 |
+
# ---------------------------------------------------------------
|
| 801 |
+
# Abstract Methods
|
| 802 |
+
|
| 803 |
+
@property
|
| 804 |
+
@abc.abstractmethod
|
| 805 |
+
def result_index(self) -> Index:
|
| 806 |
+
pass
|
| 807 |
+
|
| 808 |
+
@property
|
| 809 |
+
@abc.abstractmethod
|
| 810 |
+
def result_columns(self) -> Index:
|
| 811 |
+
pass
|
| 812 |
+
|
| 813 |
+
@property
|
| 814 |
+
@abc.abstractmethod
|
| 815 |
+
def series_generator(self) -> Generator[Series, None, None]:
|
| 816 |
+
pass
|
| 817 |
+
|
| 818 |
+
@staticmethod
|
| 819 |
+
@functools.cache
|
| 820 |
+
@abc.abstractmethod
|
| 821 |
+
def generate_numba_apply_func(
|
| 822 |
+
func, nogil=True, nopython=True, parallel=False
|
| 823 |
+
) -> Callable[[npt.NDArray, Index, Index], dict[int, Any]]:
|
| 824 |
+
pass
|
| 825 |
+
|
| 826 |
+
@abc.abstractmethod
|
| 827 |
+
def apply_with_numba(self):
|
| 828 |
+
pass
|
| 829 |
+
|
| 830 |
+
def validate_values_for_numba(self):
|
| 831 |
+
# Validate column dtyps all OK
|
| 832 |
+
for colname, dtype in self.obj.dtypes.items():
|
| 833 |
+
if not is_numeric_dtype(dtype):
|
| 834 |
+
raise ValueError(
|
| 835 |
+
f"Column {colname} must have a numeric dtype. "
|
| 836 |
+
f"Found '{dtype}' instead"
|
| 837 |
+
)
|
| 838 |
+
if is_extension_array_dtype(dtype):
|
| 839 |
+
raise ValueError(
|
| 840 |
+
f"Column {colname} is backed by an extension array, "
|
| 841 |
+
f"which is not supported by the numba engine."
|
| 842 |
+
)
|
| 843 |
+
|
| 844 |
+
@abc.abstractmethod
|
| 845 |
+
def wrap_results_for_axis(
|
| 846 |
+
self, results: ResType, res_index: Index
|
| 847 |
+
) -> DataFrame | Series:
|
| 848 |
+
pass
|
| 849 |
+
|
| 850 |
+
# ---------------------------------------------------------------
|
| 851 |
+
|
| 852 |
+
@property
|
| 853 |
+
def res_columns(self) -> Index:
|
| 854 |
+
return self.result_columns
|
| 855 |
+
|
| 856 |
+
@property
|
| 857 |
+
def columns(self) -> Index:
|
| 858 |
+
return self.obj.columns
|
| 859 |
+
|
| 860 |
+
@cache_readonly
|
| 861 |
+
def values(self):
|
| 862 |
+
return self.obj.values
|
| 863 |
+
|
| 864 |
+
def apply(self) -> DataFrame | Series:
|
| 865 |
+
"""compute the results"""
|
| 866 |
+
|
| 867 |
+
# dispatch to handle list-like or dict-like
|
| 868 |
+
if is_list_like(self.func):
|
| 869 |
+
if self.engine == "numba":
|
| 870 |
+
raise NotImplementedError(
|
| 871 |
+
"the 'numba' engine doesn't support lists of callables yet"
|
| 872 |
+
)
|
| 873 |
+
return self.apply_list_or_dict_like()
|
| 874 |
+
|
| 875 |
+
# all empty
|
| 876 |
+
if len(self.columns) == 0 and len(self.index) == 0:
|
| 877 |
+
return self.apply_empty_result()
|
| 878 |
+
|
| 879 |
+
# string dispatch
|
| 880 |
+
if isinstance(self.func, str):
|
| 881 |
+
if self.engine == "numba":
|
| 882 |
+
raise NotImplementedError(
|
| 883 |
+
"the 'numba' engine doesn't support using "
|
| 884 |
+
"a string as the callable function"
|
| 885 |
+
)
|
| 886 |
+
return self.apply_str()
|
| 887 |
+
|
| 888 |
+
# ufunc
|
| 889 |
+
elif isinstance(self.func, np.ufunc):
|
| 890 |
+
if self.engine == "numba":
|
| 891 |
+
raise NotImplementedError(
|
| 892 |
+
"the 'numba' engine doesn't support "
|
| 893 |
+
"using a numpy ufunc as the callable function"
|
| 894 |
+
)
|
| 895 |
+
with np.errstate(all="ignore"):
|
| 896 |
+
results = self.obj._mgr.apply("apply", func=self.func)
|
| 897 |
+
# _constructor will retain self.index and self.columns
|
| 898 |
+
return self.obj._constructor_from_mgr(results, axes=results.axes)
|
| 899 |
+
|
| 900 |
+
# broadcasting
|
| 901 |
+
if self.result_type == "broadcast":
|
| 902 |
+
if self.engine == "numba":
|
| 903 |
+
raise NotImplementedError(
|
| 904 |
+
"the 'numba' engine doesn't support result_type='broadcast'"
|
| 905 |
+
)
|
| 906 |
+
return self.apply_broadcast(self.obj)
|
| 907 |
+
|
| 908 |
+
# one axis empty
|
| 909 |
+
elif not all(self.obj.shape):
|
| 910 |
+
return self.apply_empty_result()
|
| 911 |
+
|
| 912 |
+
# raw
|
| 913 |
+
elif self.raw:
|
| 914 |
+
return self.apply_raw(engine=self.engine, engine_kwargs=self.engine_kwargs)
|
| 915 |
+
|
| 916 |
+
return self.apply_standard()
|
| 917 |
+
|
| 918 |
+
def agg(self):
|
| 919 |
+
obj = self.obj
|
| 920 |
+
axis = self.axis
|
| 921 |
+
|
| 922 |
+
# TODO: Avoid having to change state
|
| 923 |
+
self.obj = self.obj if self.axis == 0 else self.obj.T
|
| 924 |
+
self.axis = 0
|
| 925 |
+
|
| 926 |
+
result = None
|
| 927 |
+
try:
|
| 928 |
+
result = super().agg()
|
| 929 |
+
finally:
|
| 930 |
+
self.obj = obj
|
| 931 |
+
self.axis = axis
|
| 932 |
+
|
| 933 |
+
if axis == 1:
|
| 934 |
+
result = result.T if result is not None else result
|
| 935 |
+
|
| 936 |
+
if result is None:
|
| 937 |
+
result = self.obj.apply(self.func, axis, args=self.args, **self.kwargs)
|
| 938 |
+
|
| 939 |
+
return result
|
| 940 |
+
|
| 941 |
+
def apply_empty_result(self):
|
| 942 |
+
"""
|
| 943 |
+
we have an empty result; at least 1 axis is 0
|
| 944 |
+
|
| 945 |
+
we will try to apply the function to an empty
|
| 946 |
+
series in order to see if this is a reduction function
|
| 947 |
+
"""
|
| 948 |
+
assert callable(self.func)
|
| 949 |
+
|
| 950 |
+
# we are not asked to reduce or infer reduction
|
| 951 |
+
# so just return a copy of the existing object
|
| 952 |
+
if self.result_type not in ["reduce", None]:
|
| 953 |
+
return self.obj.copy()
|
| 954 |
+
|
| 955 |
+
# we may need to infer
|
| 956 |
+
should_reduce = self.result_type == "reduce"
|
| 957 |
+
|
| 958 |
+
from pandas import Series
|
| 959 |
+
|
| 960 |
+
if not should_reduce:
|
| 961 |
+
try:
|
| 962 |
+
if self.axis == 0:
|
| 963 |
+
r = self.func(
|
| 964 |
+
Series([], dtype=np.float64), *self.args, **self.kwargs
|
| 965 |
+
)
|
| 966 |
+
else:
|
| 967 |
+
r = self.func(
|
| 968 |
+
Series(index=self.columns, dtype=np.float64),
|
| 969 |
+
*self.args,
|
| 970 |
+
**self.kwargs,
|
| 971 |
+
)
|
| 972 |
+
except Exception:
|
| 973 |
+
pass
|
| 974 |
+
else:
|
| 975 |
+
should_reduce = not isinstance(r, Series)
|
| 976 |
+
|
| 977 |
+
if should_reduce:
|
| 978 |
+
if len(self.agg_axis):
|
| 979 |
+
r = self.func(Series([], dtype=np.float64), *self.args, **self.kwargs)
|
| 980 |
+
else:
|
| 981 |
+
r = np.nan
|
| 982 |
+
|
| 983 |
+
return self.obj._constructor_sliced(r, index=self.agg_axis)
|
| 984 |
+
else:
|
| 985 |
+
return self.obj.copy()
|
| 986 |
+
|
| 987 |
+
def apply_raw(self, engine="python", engine_kwargs=None):
|
| 988 |
+
"""apply to the values as a numpy array"""
|
| 989 |
+
|
| 990 |
+
def wrap_function(func):
|
| 991 |
+
"""
|
| 992 |
+
Wrap user supplied function to work around numpy issue.
|
| 993 |
+
|
| 994 |
+
see https://github.com/numpy/numpy/issues/8352
|
| 995 |
+
"""
|
| 996 |
+
|
| 997 |
+
def wrapper(*args, **kwargs):
|
| 998 |
+
result = func(*args, **kwargs)
|
| 999 |
+
if isinstance(result, str):
|
| 1000 |
+
result = np.array(result, dtype=object)
|
| 1001 |
+
return result
|
| 1002 |
+
|
| 1003 |
+
return wrapper
|
| 1004 |
+
|
| 1005 |
+
if engine == "numba":
|
| 1006 |
+
engine_kwargs = {} if engine_kwargs is None else engine_kwargs
|
| 1007 |
+
|
| 1008 |
+
# error: Argument 1 to "__call__" of "_lru_cache_wrapper" has
|
| 1009 |
+
# incompatible type "Callable[..., Any] | str | list[Callable
|
| 1010 |
+
# [..., Any] | str] | dict[Hashable,Callable[..., Any] | str |
|
| 1011 |
+
# list[Callable[..., Any] | str]]"; expected "Hashable"
|
| 1012 |
+
nb_looper = generate_apply_looper(
|
| 1013 |
+
self.func, **engine_kwargs # type: ignore[arg-type]
|
| 1014 |
+
)
|
| 1015 |
+
result = nb_looper(self.values, self.axis)
|
| 1016 |
+
# If we made the result 2-D, squeeze it back to 1-D
|
| 1017 |
+
result = np.squeeze(result)
|
| 1018 |
+
else:
|
| 1019 |
+
result = np.apply_along_axis(
|
| 1020 |
+
wrap_function(self.func),
|
| 1021 |
+
self.axis,
|
| 1022 |
+
self.values,
|
| 1023 |
+
*self.args,
|
| 1024 |
+
**self.kwargs,
|
| 1025 |
+
)
|
| 1026 |
+
|
| 1027 |
+
# TODO: mixed type case
|
| 1028 |
+
if result.ndim == 2:
|
| 1029 |
+
return self.obj._constructor(result, index=self.index, columns=self.columns)
|
| 1030 |
+
else:
|
| 1031 |
+
return self.obj._constructor_sliced(result, index=self.agg_axis)
|
| 1032 |
+
|
| 1033 |
+
def apply_broadcast(self, target: DataFrame) -> DataFrame:
|
| 1034 |
+
assert callable(self.func)
|
| 1035 |
+
|
| 1036 |
+
result_values = np.empty_like(target.values)
|
| 1037 |
+
|
| 1038 |
+
# axis which we want to compare compliance
|
| 1039 |
+
result_compare = target.shape[0]
|
| 1040 |
+
|
| 1041 |
+
for i, col in enumerate(target.columns):
|
| 1042 |
+
res = self.func(target[col], *self.args, **self.kwargs)
|
| 1043 |
+
ares = np.asarray(res).ndim
|
| 1044 |
+
|
| 1045 |
+
# must be a scalar or 1d
|
| 1046 |
+
if ares > 1:
|
| 1047 |
+
raise ValueError("too many dims to broadcast")
|
| 1048 |
+
if ares == 1:
|
| 1049 |
+
# must match return dim
|
| 1050 |
+
if result_compare != len(res):
|
| 1051 |
+
raise ValueError("cannot broadcast result")
|
| 1052 |
+
|
| 1053 |
+
result_values[:, i] = res
|
| 1054 |
+
|
| 1055 |
+
# we *always* preserve the original index / columns
|
| 1056 |
+
result = self.obj._constructor(
|
| 1057 |
+
result_values, index=target.index, columns=target.columns
|
| 1058 |
+
)
|
| 1059 |
+
return result
|
| 1060 |
+
|
| 1061 |
+
def apply_standard(self):
|
| 1062 |
+
if self.engine == "python":
|
| 1063 |
+
results, res_index = self.apply_series_generator()
|
| 1064 |
+
else:
|
| 1065 |
+
results, res_index = self.apply_series_numba()
|
| 1066 |
+
|
| 1067 |
+
# wrap results
|
| 1068 |
+
return self.wrap_results(results, res_index)
|
| 1069 |
+
|
| 1070 |
+
def apply_series_generator(self) -> tuple[ResType, Index]:
|
| 1071 |
+
assert callable(self.func)
|
| 1072 |
+
|
| 1073 |
+
series_gen = self.series_generator
|
| 1074 |
+
res_index = self.result_index
|
| 1075 |
+
|
| 1076 |
+
results = {}
|
| 1077 |
+
|
| 1078 |
+
with option_context("mode.chained_assignment", None):
|
| 1079 |
+
for i, v in enumerate(series_gen):
|
| 1080 |
+
# ignore SettingWithCopy here in case the user mutates
|
| 1081 |
+
results[i] = self.func(v, *self.args, **self.kwargs)
|
| 1082 |
+
if isinstance(results[i], ABCSeries):
|
| 1083 |
+
# If we have a view on v, we need to make a copy because
|
| 1084 |
+
# series_generator will swap out the underlying data
|
| 1085 |
+
results[i] = results[i].copy(deep=False)
|
| 1086 |
+
|
| 1087 |
+
return results, res_index
|
| 1088 |
+
|
| 1089 |
+
def apply_series_numba(self):
|
| 1090 |
+
if self.engine_kwargs.get("parallel", False):
|
| 1091 |
+
raise NotImplementedError(
|
| 1092 |
+
"Parallel apply is not supported when raw=False and engine='numba'"
|
| 1093 |
+
)
|
| 1094 |
+
if not self.obj.index.is_unique or not self.columns.is_unique:
|
| 1095 |
+
raise NotImplementedError(
|
| 1096 |
+
"The index/columns must be unique when raw=False and engine='numba'"
|
| 1097 |
+
)
|
| 1098 |
+
self.validate_values_for_numba()
|
| 1099 |
+
results = self.apply_with_numba()
|
| 1100 |
+
return results, self.result_index
|
| 1101 |
+
|
| 1102 |
+
def wrap_results(self, results: ResType, res_index: Index) -> DataFrame | Series:
|
| 1103 |
+
from pandas import Series
|
| 1104 |
+
|
| 1105 |
+
# see if we can infer the results
|
| 1106 |
+
if len(results) > 0 and 0 in results and is_sequence(results[0]):
|
| 1107 |
+
return self.wrap_results_for_axis(results, res_index)
|
| 1108 |
+
|
| 1109 |
+
# dict of scalars
|
| 1110 |
+
|
| 1111 |
+
# the default dtype of an empty Series is `object`, but this
|
| 1112 |
+
# code can be hit by df.mean() where the result should have dtype
|
| 1113 |
+
# float64 even if it's an empty Series.
|
| 1114 |
+
constructor_sliced = self.obj._constructor_sliced
|
| 1115 |
+
if len(results) == 0 and constructor_sliced is Series:
|
| 1116 |
+
result = constructor_sliced(results, dtype=np.float64)
|
| 1117 |
+
else:
|
| 1118 |
+
result = constructor_sliced(results)
|
| 1119 |
+
result.index = res_index
|
| 1120 |
+
|
| 1121 |
+
return result
|
| 1122 |
+
|
| 1123 |
+
def apply_str(self) -> DataFrame | Series:
|
| 1124 |
+
# Caller is responsible for checking isinstance(self.func, str)
|
| 1125 |
+
# TODO: GH#39993 - Avoid special-casing by replacing with lambda
|
| 1126 |
+
if self.func == "size":
|
| 1127 |
+
# Special-cased because DataFrame.size returns a single scalar
|
| 1128 |
+
obj = self.obj
|
| 1129 |
+
value = obj.shape[self.axis]
|
| 1130 |
+
return obj._constructor_sliced(value, index=self.agg_axis)
|
| 1131 |
+
return super().apply_str()
|
| 1132 |
+
|
| 1133 |
+
|
| 1134 |
+
class FrameRowApply(FrameApply):
|
| 1135 |
+
axis: AxisInt = 0
|
| 1136 |
+
|
| 1137 |
+
@property
|
| 1138 |
+
def series_generator(self) -> Generator[Series, None, None]:
|
| 1139 |
+
return (self.obj._ixs(i, axis=1) for i in range(len(self.columns)))
|
| 1140 |
+
|
| 1141 |
+
@staticmethod
|
| 1142 |
+
@functools.cache
|
| 1143 |
+
def generate_numba_apply_func(
|
| 1144 |
+
func, nogil=True, nopython=True, parallel=False
|
| 1145 |
+
) -> Callable[[npt.NDArray, Index, Index], dict[int, Any]]:
|
| 1146 |
+
numba = import_optional_dependency("numba")
|
| 1147 |
+
from pandas import Series
|
| 1148 |
+
|
| 1149 |
+
# Import helper from extensions to cast string object -> np strings
|
| 1150 |
+
# Note: This also has the side effect of loading our numba extensions
|
| 1151 |
+
from pandas.core._numba.extensions import maybe_cast_str
|
| 1152 |
+
|
| 1153 |
+
jitted_udf = numba.extending.register_jitable(func)
|
| 1154 |
+
|
| 1155 |
+
# Currently the parallel argument doesn't get passed through here
|
| 1156 |
+
# (it's disabled) since the dicts in numba aren't thread-safe.
|
| 1157 |
+
@numba.jit(nogil=nogil, nopython=nopython, parallel=parallel)
|
| 1158 |
+
def numba_func(values, col_names, df_index):
|
| 1159 |
+
results = {}
|
| 1160 |
+
for j in range(values.shape[1]):
|
| 1161 |
+
# Create the series
|
| 1162 |
+
ser = Series(
|
| 1163 |
+
values[:, j], index=df_index, name=maybe_cast_str(col_names[j])
|
| 1164 |
+
)
|
| 1165 |
+
results[j] = jitted_udf(ser)
|
| 1166 |
+
return results
|
| 1167 |
+
|
| 1168 |
+
return numba_func
|
| 1169 |
+
|
| 1170 |
+
def apply_with_numba(self) -> dict[int, Any]:
|
| 1171 |
+
nb_func = self.generate_numba_apply_func(
|
| 1172 |
+
cast(Callable, self.func), **self.engine_kwargs
|
| 1173 |
+
)
|
| 1174 |
+
from pandas.core._numba.extensions import set_numba_data
|
| 1175 |
+
|
| 1176 |
+
index = self.obj.index
|
| 1177 |
+
if index.dtype == "string":
|
| 1178 |
+
index = index.astype(object)
|
| 1179 |
+
|
| 1180 |
+
columns = self.obj.columns
|
| 1181 |
+
if columns.dtype == "string":
|
| 1182 |
+
columns = columns.astype(object)
|
| 1183 |
+
|
| 1184 |
+
# Convert from numba dict to regular dict
|
| 1185 |
+
# Our isinstance checks in the df constructor don't pass for numbas typed dict
|
| 1186 |
+
with set_numba_data(index) as index, set_numba_data(columns) as columns:
|
| 1187 |
+
res = dict(nb_func(self.values, columns, index))
|
| 1188 |
+
return res
|
| 1189 |
+
|
| 1190 |
+
@property
|
| 1191 |
+
def result_index(self) -> Index:
|
| 1192 |
+
return self.columns
|
| 1193 |
+
|
| 1194 |
+
@property
|
| 1195 |
+
def result_columns(self) -> Index:
|
| 1196 |
+
return self.index
|
| 1197 |
+
|
| 1198 |
+
def wrap_results_for_axis(
|
| 1199 |
+
self, results: ResType, res_index: Index
|
| 1200 |
+
) -> DataFrame | Series:
|
| 1201 |
+
"""return the results for the rows"""
|
| 1202 |
+
|
| 1203 |
+
if self.result_type == "reduce":
|
| 1204 |
+
# e.g. test_apply_dict GH#8735
|
| 1205 |
+
res = self.obj._constructor_sliced(results)
|
| 1206 |
+
res.index = res_index
|
| 1207 |
+
return res
|
| 1208 |
+
|
| 1209 |
+
elif self.result_type is None and all(
|
| 1210 |
+
isinstance(x, dict) for x in results.values()
|
| 1211 |
+
):
|
| 1212 |
+
# Our operation was a to_dict op e.g.
|
| 1213 |
+
# test_apply_dict GH#8735, test_apply_reduce_to_dict GH#25196 #37544
|
| 1214 |
+
res = self.obj._constructor_sliced(results)
|
| 1215 |
+
res.index = res_index
|
| 1216 |
+
return res
|
| 1217 |
+
|
| 1218 |
+
try:
|
| 1219 |
+
result = self.obj._constructor(data=results)
|
| 1220 |
+
except ValueError as err:
|
| 1221 |
+
if "All arrays must be of the same length" in str(err):
|
| 1222 |
+
# e.g. result = [[2, 3], [1.5], ['foo', 'bar']]
|
| 1223 |
+
# see test_agg_listlike_result GH#29587
|
| 1224 |
+
res = self.obj._constructor_sliced(results)
|
| 1225 |
+
res.index = res_index
|
| 1226 |
+
return res
|
| 1227 |
+
else:
|
| 1228 |
+
raise
|
| 1229 |
+
|
| 1230 |
+
if not isinstance(results[0], ABCSeries):
|
| 1231 |
+
if len(result.index) == len(self.res_columns):
|
| 1232 |
+
result.index = self.res_columns
|
| 1233 |
+
|
| 1234 |
+
if len(result.columns) == len(res_index):
|
| 1235 |
+
result.columns = res_index
|
| 1236 |
+
|
| 1237 |
+
return result
|
| 1238 |
+
|
| 1239 |
+
|
| 1240 |
+
class FrameColumnApply(FrameApply):
|
| 1241 |
+
axis: AxisInt = 1
|
| 1242 |
+
|
| 1243 |
+
def apply_broadcast(self, target: DataFrame) -> DataFrame:
|
| 1244 |
+
result = super().apply_broadcast(target.T)
|
| 1245 |
+
return result.T
|
| 1246 |
+
|
| 1247 |
+
@property
|
| 1248 |
+
def series_generator(self) -> Generator[Series, None, None]:
|
| 1249 |
+
values = self.values
|
| 1250 |
+
values = ensure_wrapped_if_datetimelike(values)
|
| 1251 |
+
assert len(values) > 0
|
| 1252 |
+
|
| 1253 |
+
# We create one Series object, and will swap out the data inside
|
| 1254 |
+
# of it. Kids: don't do this at home.
|
| 1255 |
+
ser = self.obj._ixs(0, axis=0)
|
| 1256 |
+
mgr = ser._mgr
|
| 1257 |
+
|
| 1258 |
+
is_view = mgr.blocks[0].refs.has_reference() # type: ignore[union-attr]
|
| 1259 |
+
|
| 1260 |
+
if isinstance(ser.dtype, ExtensionDtype):
|
| 1261 |
+
# values will be incorrect for this block
|
| 1262 |
+
# TODO(EA2D): special case would be unnecessary with 2D EAs
|
| 1263 |
+
obj = self.obj
|
| 1264 |
+
for i in range(len(obj)):
|
| 1265 |
+
yield obj._ixs(i, axis=0)
|
| 1266 |
+
|
| 1267 |
+
else:
|
| 1268 |
+
for arr, name in zip(values, self.index):
|
| 1269 |
+
# GH#35462 re-pin mgr in case setitem changed it
|
| 1270 |
+
ser._mgr = mgr
|
| 1271 |
+
mgr.set_values(arr)
|
| 1272 |
+
object.__setattr__(ser, "_name", name)
|
| 1273 |
+
if not is_view:
|
| 1274 |
+
# In apply_series_generator we store the a shallow copy of the
|
| 1275 |
+
# result, which potentially increases the ref count of this reused
|
| 1276 |
+
# `ser` object (depending on the result of the applied function)
|
| 1277 |
+
# -> if that happened and `ser` is already a copy, then we reset
|
| 1278 |
+
# the refs here to avoid triggering a unnecessary CoW inside the
|
| 1279 |
+
# applied function (https://github.com/pandas-dev/pandas/pull/56212)
|
| 1280 |
+
mgr.blocks[0].refs = BlockValuesRefs(mgr.blocks[0]) # type: ignore[union-attr]
|
| 1281 |
+
yield ser
|
| 1282 |
+
|
| 1283 |
+
@staticmethod
|
| 1284 |
+
@functools.cache
|
| 1285 |
+
def generate_numba_apply_func(
|
| 1286 |
+
func, nogil=True, nopython=True, parallel=False
|
| 1287 |
+
) -> Callable[[npt.NDArray, Index, Index], dict[int, Any]]:
|
| 1288 |
+
numba = import_optional_dependency("numba")
|
| 1289 |
+
from pandas import Series
|
| 1290 |
+
from pandas.core._numba.extensions import maybe_cast_str
|
| 1291 |
+
|
| 1292 |
+
jitted_udf = numba.extending.register_jitable(func)
|
| 1293 |
+
|
| 1294 |
+
@numba.jit(nogil=nogil, nopython=nopython, parallel=parallel)
|
| 1295 |
+
def numba_func(values, col_names_index, index):
|
| 1296 |
+
results = {}
|
| 1297 |
+
# Currently the parallel argument doesn't get passed through here
|
| 1298 |
+
# (it's disabled) since the dicts in numba aren't thread-safe.
|
| 1299 |
+
for i in range(values.shape[0]):
|
| 1300 |
+
# Create the series
|
| 1301 |
+
# TODO: values corrupted without the copy
|
| 1302 |
+
ser = Series(
|
| 1303 |
+
values[i].copy(),
|
| 1304 |
+
index=col_names_index,
|
| 1305 |
+
name=maybe_cast_str(index[i]),
|
| 1306 |
+
)
|
| 1307 |
+
results[i] = jitted_udf(ser)
|
| 1308 |
+
|
| 1309 |
+
return results
|
| 1310 |
+
|
| 1311 |
+
return numba_func
|
| 1312 |
+
|
| 1313 |
+
def apply_with_numba(self) -> dict[int, Any]:
|
| 1314 |
+
nb_func = self.generate_numba_apply_func(
|
| 1315 |
+
cast(Callable, self.func), **self.engine_kwargs
|
| 1316 |
+
)
|
| 1317 |
+
|
| 1318 |
+
from pandas.core._numba.extensions import set_numba_data
|
| 1319 |
+
|
| 1320 |
+
# Convert from numba dict to regular dict
|
| 1321 |
+
# Our isinstance checks in the df constructor don't pass for numbas typed dict
|
| 1322 |
+
with set_numba_data(self.obj.index) as index, set_numba_data(
|
| 1323 |
+
self.columns
|
| 1324 |
+
) as columns:
|
| 1325 |
+
res = dict(nb_func(self.values, columns, index))
|
| 1326 |
+
|
| 1327 |
+
return res
|
| 1328 |
+
|
| 1329 |
+
@property
|
| 1330 |
+
def result_index(self) -> Index:
|
| 1331 |
+
return self.index
|
| 1332 |
+
|
| 1333 |
+
@property
|
| 1334 |
+
def result_columns(self) -> Index:
|
| 1335 |
+
return self.columns
|
| 1336 |
+
|
| 1337 |
+
def wrap_results_for_axis(
|
| 1338 |
+
self, results: ResType, res_index: Index
|
| 1339 |
+
) -> DataFrame | Series:
|
| 1340 |
+
"""return the results for the columns"""
|
| 1341 |
+
result: DataFrame | Series
|
| 1342 |
+
|
| 1343 |
+
# we have requested to expand
|
| 1344 |
+
if self.result_type == "expand":
|
| 1345 |
+
result = self.infer_to_same_shape(results, res_index)
|
| 1346 |
+
|
| 1347 |
+
# we have a non-series and don't want inference
|
| 1348 |
+
elif not isinstance(results[0], ABCSeries):
|
| 1349 |
+
result = self.obj._constructor_sliced(results)
|
| 1350 |
+
result.index = res_index
|
| 1351 |
+
|
| 1352 |
+
# we may want to infer results
|
| 1353 |
+
else:
|
| 1354 |
+
result = self.infer_to_same_shape(results, res_index)
|
| 1355 |
+
|
| 1356 |
+
return result
|
| 1357 |
+
|
| 1358 |
+
def infer_to_same_shape(self, results: ResType, res_index: Index) -> DataFrame:
|
| 1359 |
+
"""infer the results to the same shape as the input object"""
|
| 1360 |
+
result = self.obj._constructor(data=results)
|
| 1361 |
+
result = result.T
|
| 1362 |
+
|
| 1363 |
+
# set the index
|
| 1364 |
+
result.index = res_index
|
| 1365 |
+
|
| 1366 |
+
# infer dtypes
|
| 1367 |
+
result = result.infer_objects(copy=False)
|
| 1368 |
+
|
| 1369 |
+
return result
|
| 1370 |
+
|
| 1371 |
+
|
| 1372 |
+
class SeriesApply(NDFrameApply):
|
| 1373 |
+
obj: Series
|
| 1374 |
+
axis: AxisInt = 0
|
| 1375 |
+
by_row: Literal[False, "compat", "_compat"] # only relevant for apply()
|
| 1376 |
+
|
| 1377 |
+
def __init__(
|
| 1378 |
+
self,
|
| 1379 |
+
obj: Series,
|
| 1380 |
+
func: AggFuncType,
|
| 1381 |
+
*,
|
| 1382 |
+
convert_dtype: bool | lib.NoDefault = lib.no_default,
|
| 1383 |
+
by_row: Literal[False, "compat", "_compat"] = "compat",
|
| 1384 |
+
args,
|
| 1385 |
+
kwargs,
|
| 1386 |
+
) -> None:
|
| 1387 |
+
if convert_dtype is lib.no_default:
|
| 1388 |
+
convert_dtype = True
|
| 1389 |
+
else:
|
| 1390 |
+
warnings.warn(
|
| 1391 |
+
"the convert_dtype parameter is deprecated and will be removed in a "
|
| 1392 |
+
"future version. Do ``ser.astype(object).apply()`` "
|
| 1393 |
+
"instead if you want ``convert_dtype=False``.",
|
| 1394 |
+
FutureWarning,
|
| 1395 |
+
stacklevel=find_stack_level(),
|
| 1396 |
+
)
|
| 1397 |
+
self.convert_dtype = convert_dtype
|
| 1398 |
+
|
| 1399 |
+
super().__init__(
|
| 1400 |
+
obj,
|
| 1401 |
+
func,
|
| 1402 |
+
raw=False,
|
| 1403 |
+
result_type=None,
|
| 1404 |
+
by_row=by_row,
|
| 1405 |
+
args=args,
|
| 1406 |
+
kwargs=kwargs,
|
| 1407 |
+
)
|
| 1408 |
+
|
| 1409 |
+
def apply(self) -> DataFrame | Series:
|
| 1410 |
+
obj = self.obj
|
| 1411 |
+
|
| 1412 |
+
if len(obj) == 0:
|
| 1413 |
+
return self.apply_empty_result()
|
| 1414 |
+
|
| 1415 |
+
# dispatch to handle list-like or dict-like
|
| 1416 |
+
if is_list_like(self.func):
|
| 1417 |
+
return self.apply_list_or_dict_like()
|
| 1418 |
+
|
| 1419 |
+
if isinstance(self.func, str):
|
| 1420 |
+
# if we are a string, try to dispatch
|
| 1421 |
+
return self.apply_str()
|
| 1422 |
+
|
| 1423 |
+
if self.by_row == "_compat":
|
| 1424 |
+
return self.apply_compat()
|
| 1425 |
+
|
| 1426 |
+
# self.func is Callable
|
| 1427 |
+
return self.apply_standard()
|
| 1428 |
+
|
| 1429 |
+
def agg(self):
|
| 1430 |
+
result = super().agg()
|
| 1431 |
+
if result is None:
|
| 1432 |
+
obj = self.obj
|
| 1433 |
+
func = self.func
|
| 1434 |
+
# string, list-like, and dict-like are entirely handled in super
|
| 1435 |
+
assert callable(func)
|
| 1436 |
+
|
| 1437 |
+
# GH53325: The setup below is just to keep current behavior while emitting a
|
| 1438 |
+
# deprecation message. In the future this will all be replaced with a simple
|
| 1439 |
+
# `result = f(self.obj, *self.args, **self.kwargs)`.
|
| 1440 |
+
try:
|
| 1441 |
+
result = obj.apply(func, args=self.args, **self.kwargs)
|
| 1442 |
+
except (ValueError, AttributeError, TypeError):
|
| 1443 |
+
result = func(obj, *self.args, **self.kwargs)
|
| 1444 |
+
else:
|
| 1445 |
+
msg = (
|
| 1446 |
+
f"using {func} in {type(obj).__name__}.agg cannot aggregate and "
|
| 1447 |
+
f"has been deprecated. Use {type(obj).__name__}.transform to "
|
| 1448 |
+
f"keep behavior unchanged."
|
| 1449 |
+
)
|
| 1450 |
+
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())
|
| 1451 |
+
|
| 1452 |
+
return result
|
| 1453 |
+
|
| 1454 |
+
def apply_empty_result(self) -> Series:
|
| 1455 |
+
obj = self.obj
|
| 1456 |
+
return obj._constructor(dtype=obj.dtype, index=obj.index).__finalize__(
|
| 1457 |
+
obj, method="apply"
|
| 1458 |
+
)
|
| 1459 |
+
|
| 1460 |
+
def apply_compat(self):
|
| 1461 |
+
"""compat apply method for funcs in listlikes and dictlikes.
|
| 1462 |
+
|
| 1463 |
+
Used for each callable when giving listlikes and dictlikes of callables to
|
| 1464 |
+
apply. Needed for compatibility with Pandas < v2.1.
|
| 1465 |
+
|
| 1466 |
+
.. versionadded:: 2.1.0
|
| 1467 |
+
"""
|
| 1468 |
+
obj = self.obj
|
| 1469 |
+
func = self.func
|
| 1470 |
+
|
| 1471 |
+
if callable(func):
|
| 1472 |
+
f = com.get_cython_func(func)
|
| 1473 |
+
if f and not self.args and not self.kwargs:
|
| 1474 |
+
return obj.apply(func, by_row=False)
|
| 1475 |
+
|
| 1476 |
+
try:
|
| 1477 |
+
result = obj.apply(func, by_row="compat")
|
| 1478 |
+
except (ValueError, AttributeError, TypeError):
|
| 1479 |
+
result = obj.apply(func, by_row=False)
|
| 1480 |
+
return result
|
| 1481 |
+
|
| 1482 |
+
def apply_standard(self) -> DataFrame | Series:
|
| 1483 |
+
# caller is responsible for ensuring that f is Callable
|
| 1484 |
+
func = cast(Callable, self.func)
|
| 1485 |
+
obj = self.obj
|
| 1486 |
+
|
| 1487 |
+
if isinstance(func, np.ufunc):
|
| 1488 |
+
with np.errstate(all="ignore"):
|
| 1489 |
+
return func(obj, *self.args, **self.kwargs)
|
| 1490 |
+
elif not self.by_row:
|
| 1491 |
+
return func(obj, *self.args, **self.kwargs)
|
| 1492 |
+
|
| 1493 |
+
if self.args or self.kwargs:
|
| 1494 |
+
# _map_values does not support args/kwargs
|
| 1495 |
+
def curried(x):
|
| 1496 |
+
return func(x, *self.args, **self.kwargs)
|
| 1497 |
+
|
| 1498 |
+
else:
|
| 1499 |
+
curried = func
|
| 1500 |
+
|
| 1501 |
+
# row-wise access
|
| 1502 |
+
# apply doesn't have a `na_action` keyword and for backward compat reasons
|
| 1503 |
+
# we need to give `na_action="ignore"` for categorical data.
|
| 1504 |
+
# TODO: remove the `na_action="ignore"` when that default has been changed in
|
| 1505 |
+
# Categorical (GH51645).
|
| 1506 |
+
action = "ignore" if isinstance(obj.dtype, CategoricalDtype) else None
|
| 1507 |
+
mapped = obj._map_values(
|
| 1508 |
+
mapper=curried, na_action=action, convert=self.convert_dtype
|
| 1509 |
+
)
|
| 1510 |
+
|
| 1511 |
+
if len(mapped) and isinstance(mapped[0], ABCSeries):
|
| 1512 |
+
# GH#43986 Need to do list(mapped) in order to get treated as nested
|
| 1513 |
+
# See also GH#25959 regarding EA support
|
| 1514 |
+
return obj._constructor_expanddim(list(mapped), index=obj.index)
|
| 1515 |
+
else:
|
| 1516 |
+
return obj._constructor(mapped, index=obj.index).__finalize__(
|
| 1517 |
+
obj, method="apply"
|
| 1518 |
+
)
|
| 1519 |
+
|
| 1520 |
+
|
| 1521 |
+
class GroupByApply(Apply):
|
| 1522 |
+
obj: GroupBy | Resampler | BaseWindow
|
| 1523 |
+
|
| 1524 |
+
def __init__(
|
| 1525 |
+
self,
|
| 1526 |
+
obj: GroupBy[NDFrameT],
|
| 1527 |
+
func: AggFuncType,
|
| 1528 |
+
*,
|
| 1529 |
+
args,
|
| 1530 |
+
kwargs,
|
| 1531 |
+
) -> None:
|
| 1532 |
+
kwargs = kwargs.copy()
|
| 1533 |
+
self.axis = obj.obj._get_axis_number(kwargs.get("axis", 0))
|
| 1534 |
+
super().__init__(
|
| 1535 |
+
obj,
|
| 1536 |
+
func,
|
| 1537 |
+
raw=False,
|
| 1538 |
+
result_type=None,
|
| 1539 |
+
args=args,
|
| 1540 |
+
kwargs=kwargs,
|
| 1541 |
+
)
|
| 1542 |
+
|
| 1543 |
+
def apply(self):
|
| 1544 |
+
raise NotImplementedError
|
| 1545 |
+
|
| 1546 |
+
def transform(self):
|
| 1547 |
+
raise NotImplementedError
|
| 1548 |
+
|
| 1549 |
+
def agg_or_apply_list_like(
|
| 1550 |
+
self, op_name: Literal["agg", "apply"]
|
| 1551 |
+
) -> DataFrame | Series:
|
| 1552 |
+
obj = self.obj
|
| 1553 |
+
kwargs = self.kwargs
|
| 1554 |
+
if op_name == "apply":
|
| 1555 |
+
kwargs = {**kwargs, "by_row": False}
|
| 1556 |
+
|
| 1557 |
+
if getattr(obj, "axis", 0) == 1:
|
| 1558 |
+
raise NotImplementedError("axis other than 0 is not supported")
|
| 1559 |
+
|
| 1560 |
+
if obj._selected_obj.ndim == 1:
|
| 1561 |
+
# For SeriesGroupBy this matches _obj_with_exclusions
|
| 1562 |
+
selected_obj = obj._selected_obj
|
| 1563 |
+
else:
|
| 1564 |
+
selected_obj = obj._obj_with_exclusions
|
| 1565 |
+
|
| 1566 |
+
# Only set as_index=True on groupby objects, not Window or Resample
|
| 1567 |
+
# that inherit from this class.
|
| 1568 |
+
with com.temp_setattr(
|
| 1569 |
+
obj, "as_index", True, condition=hasattr(obj, "as_index")
|
| 1570 |
+
):
|
| 1571 |
+
keys, results = self.compute_list_like(op_name, selected_obj, kwargs)
|
| 1572 |
+
result = self.wrap_results_list_like(keys, results)
|
| 1573 |
+
return result
|
| 1574 |
+
|
| 1575 |
+
def agg_or_apply_dict_like(
|
| 1576 |
+
self, op_name: Literal["agg", "apply"]
|
| 1577 |
+
) -> DataFrame | Series:
|
| 1578 |
+
from pandas.core.groupby.generic import (
|
| 1579 |
+
DataFrameGroupBy,
|
| 1580 |
+
SeriesGroupBy,
|
| 1581 |
+
)
|
| 1582 |
+
|
| 1583 |
+
assert op_name in ["agg", "apply"]
|
| 1584 |
+
|
| 1585 |
+
obj = self.obj
|
| 1586 |
+
kwargs = {}
|
| 1587 |
+
if op_name == "apply":
|
| 1588 |
+
by_row = "_compat" if self.by_row else False
|
| 1589 |
+
kwargs.update({"by_row": by_row})
|
| 1590 |
+
|
| 1591 |
+
if getattr(obj, "axis", 0) == 1:
|
| 1592 |
+
raise NotImplementedError("axis other than 0 is not supported")
|
| 1593 |
+
|
| 1594 |
+
selected_obj = obj._selected_obj
|
| 1595 |
+
selection = obj._selection
|
| 1596 |
+
|
| 1597 |
+
is_groupby = isinstance(obj, (DataFrameGroupBy, SeriesGroupBy))
|
| 1598 |
+
|
| 1599 |
+
# Numba Groupby engine/engine-kwargs passthrough
|
| 1600 |
+
if is_groupby:
|
| 1601 |
+
engine = self.kwargs.get("engine", None)
|
| 1602 |
+
engine_kwargs = self.kwargs.get("engine_kwargs", None)
|
| 1603 |
+
kwargs.update({"engine": engine, "engine_kwargs": engine_kwargs})
|
| 1604 |
+
|
| 1605 |
+
with com.temp_setattr(
|
| 1606 |
+
obj, "as_index", True, condition=hasattr(obj, "as_index")
|
| 1607 |
+
):
|
| 1608 |
+
result_index, result_data = self.compute_dict_like(
|
| 1609 |
+
op_name, selected_obj, selection, kwargs
|
| 1610 |
+
)
|
| 1611 |
+
result = self.wrap_results_dict_like(selected_obj, result_index, result_data)
|
| 1612 |
+
return result
|
| 1613 |
+
|
| 1614 |
+
|
| 1615 |
+
class ResamplerWindowApply(GroupByApply):
|
| 1616 |
+
axis: AxisInt = 0
|
| 1617 |
+
obj: Resampler | BaseWindow
|
| 1618 |
+
|
| 1619 |
+
def __init__(
|
| 1620 |
+
self,
|
| 1621 |
+
obj: Resampler | BaseWindow,
|
| 1622 |
+
func: AggFuncType,
|
| 1623 |
+
*,
|
| 1624 |
+
args,
|
| 1625 |
+
kwargs,
|
| 1626 |
+
) -> None:
|
| 1627 |
+
super(GroupByApply, self).__init__(
|
| 1628 |
+
obj,
|
| 1629 |
+
func,
|
| 1630 |
+
raw=False,
|
| 1631 |
+
result_type=None,
|
| 1632 |
+
args=args,
|
| 1633 |
+
kwargs=kwargs,
|
| 1634 |
+
)
|
| 1635 |
+
|
| 1636 |
+
def apply(self):
|
| 1637 |
+
raise NotImplementedError
|
| 1638 |
+
|
| 1639 |
+
def transform(self):
|
| 1640 |
+
raise NotImplementedError
|
| 1641 |
+
|
| 1642 |
+
|
| 1643 |
+
def reconstruct_func(
|
| 1644 |
+
func: AggFuncType | None, **kwargs
|
| 1645 |
+
) -> tuple[bool, AggFuncType, tuple[str, ...] | None, npt.NDArray[np.intp] | None]:
|
| 1646 |
+
"""
|
| 1647 |
+
This is the internal function to reconstruct func given if there is relabeling
|
| 1648 |
+
or not and also normalize the keyword to get new order of columns.
|
| 1649 |
+
|
| 1650 |
+
If named aggregation is applied, `func` will be None, and kwargs contains the
|
| 1651 |
+
column and aggregation function information to be parsed;
|
| 1652 |
+
If named aggregation is not applied, `func` is either string (e.g. 'min') or
|
| 1653 |
+
Callable, or list of them (e.g. ['min', np.max]), or the dictionary of column name
|
| 1654 |
+
and str/Callable/list of them (e.g. {'A': 'min'}, or {'A': [np.min, lambda x: x]})
|
| 1655 |
+
|
| 1656 |
+
If relabeling is True, will return relabeling, reconstructed func, column
|
| 1657 |
+
names, and the reconstructed order of columns.
|
| 1658 |
+
If relabeling is False, the columns and order will be None.
|
| 1659 |
+
|
| 1660 |
+
Parameters
|
| 1661 |
+
----------
|
| 1662 |
+
func: agg function (e.g. 'min' or Callable) or list of agg functions
|
| 1663 |
+
(e.g. ['min', np.max]) or dictionary (e.g. {'A': ['min', np.max]}).
|
| 1664 |
+
**kwargs: dict, kwargs used in is_multi_agg_with_relabel and
|
| 1665 |
+
normalize_keyword_aggregation function for relabelling
|
| 1666 |
+
|
| 1667 |
+
Returns
|
| 1668 |
+
-------
|
| 1669 |
+
relabelling: bool, if there is relabelling or not
|
| 1670 |
+
func: normalized and mangled func
|
| 1671 |
+
columns: tuple of column names
|
| 1672 |
+
order: array of columns indices
|
| 1673 |
+
|
| 1674 |
+
Examples
|
| 1675 |
+
--------
|
| 1676 |
+
>>> reconstruct_func(None, **{"foo": ("col", "min")})
|
| 1677 |
+
(True, defaultdict(<class 'list'>, {'col': ['min']}), ('foo',), array([0]))
|
| 1678 |
+
|
| 1679 |
+
>>> reconstruct_func("min")
|
| 1680 |
+
(False, 'min', None, None)
|
| 1681 |
+
"""
|
| 1682 |
+
relabeling = func is None and is_multi_agg_with_relabel(**kwargs)
|
| 1683 |
+
columns: tuple[str, ...] | None = None
|
| 1684 |
+
order: npt.NDArray[np.intp] | None = None
|
| 1685 |
+
|
| 1686 |
+
if not relabeling:
|
| 1687 |
+
if isinstance(func, list) and len(func) > len(set(func)):
|
| 1688 |
+
# GH 28426 will raise error if duplicated function names are used and
|
| 1689 |
+
# there is no reassigned name
|
| 1690 |
+
raise SpecificationError(
|
| 1691 |
+
"Function names must be unique if there is no new column names "
|
| 1692 |
+
"assigned"
|
| 1693 |
+
)
|
| 1694 |
+
if func is None:
|
| 1695 |
+
# nicer error message
|
| 1696 |
+
raise TypeError("Must provide 'func' or tuples of '(column, aggfunc).")
|
| 1697 |
+
|
| 1698 |
+
if relabeling:
|
| 1699 |
+
# error: Incompatible types in assignment (expression has type
|
| 1700 |
+
# "MutableMapping[Hashable, list[Callable[..., Any] | str]]", variable has type
|
| 1701 |
+
# "Callable[..., Any] | str | list[Callable[..., Any] | str] |
|
| 1702 |
+
# MutableMapping[Hashable, Callable[..., Any] | str | list[Callable[..., Any] |
|
| 1703 |
+
# str]] | None")
|
| 1704 |
+
func, columns, order = normalize_keyword_aggregation( # type: ignore[assignment]
|
| 1705 |
+
kwargs
|
| 1706 |
+
)
|
| 1707 |
+
assert func is not None
|
| 1708 |
+
|
| 1709 |
+
return relabeling, func, columns, order
|
| 1710 |
+
|
| 1711 |
+
|
| 1712 |
+
def is_multi_agg_with_relabel(**kwargs) -> bool:
|
| 1713 |
+
"""
|
| 1714 |
+
Check whether kwargs passed to .agg look like multi-agg with relabeling.
|
| 1715 |
+
|
| 1716 |
+
Parameters
|
| 1717 |
+
----------
|
| 1718 |
+
**kwargs : dict
|
| 1719 |
+
|
| 1720 |
+
Returns
|
| 1721 |
+
-------
|
| 1722 |
+
bool
|
| 1723 |
+
|
| 1724 |
+
Examples
|
| 1725 |
+
--------
|
| 1726 |
+
>>> is_multi_agg_with_relabel(a="max")
|
| 1727 |
+
False
|
| 1728 |
+
>>> is_multi_agg_with_relabel(a_max=("a", "max"), a_min=("a", "min"))
|
| 1729 |
+
True
|
| 1730 |
+
>>> is_multi_agg_with_relabel()
|
| 1731 |
+
False
|
| 1732 |
+
"""
|
| 1733 |
+
return all(isinstance(v, tuple) and len(v) == 2 for v in kwargs.values()) and (
|
| 1734 |
+
len(kwargs) > 0
|
| 1735 |
+
)
|
| 1736 |
+
|
| 1737 |
+
|
| 1738 |
+
def normalize_keyword_aggregation(
|
| 1739 |
+
kwargs: dict,
|
| 1740 |
+
) -> tuple[
|
| 1741 |
+
MutableMapping[Hashable, list[AggFuncTypeBase]],
|
| 1742 |
+
tuple[str, ...],
|
| 1743 |
+
npt.NDArray[np.intp],
|
| 1744 |
+
]:
|
| 1745 |
+
"""
|
| 1746 |
+
Normalize user-provided "named aggregation" kwargs.
|
| 1747 |
+
Transforms from the new ``Mapping[str, NamedAgg]`` style kwargs
|
| 1748 |
+
to the old Dict[str, List[scalar]]].
|
| 1749 |
+
|
| 1750 |
+
Parameters
|
| 1751 |
+
----------
|
| 1752 |
+
kwargs : dict
|
| 1753 |
+
|
| 1754 |
+
Returns
|
| 1755 |
+
-------
|
| 1756 |
+
aggspec : dict
|
| 1757 |
+
The transformed kwargs.
|
| 1758 |
+
columns : tuple[str, ...]
|
| 1759 |
+
The user-provided keys.
|
| 1760 |
+
col_idx_order : List[int]
|
| 1761 |
+
List of columns indices.
|
| 1762 |
+
|
| 1763 |
+
Examples
|
| 1764 |
+
--------
|
| 1765 |
+
>>> normalize_keyword_aggregation({"output": ("input", "sum")})
|
| 1766 |
+
(defaultdict(<class 'list'>, {'input': ['sum']}), ('output',), array([0]))
|
| 1767 |
+
"""
|
| 1768 |
+
from pandas.core.indexes.base import Index
|
| 1769 |
+
|
| 1770 |
+
# Normalize the aggregation functions as Mapping[column, List[func]],
|
| 1771 |
+
# process normally, then fixup the names.
|
| 1772 |
+
# TODO: aggspec type: typing.Dict[str, List[AggScalar]]
|
| 1773 |
+
aggspec = defaultdict(list)
|
| 1774 |
+
order = []
|
| 1775 |
+
columns, pairs = list(zip(*kwargs.items()))
|
| 1776 |
+
|
| 1777 |
+
for column, aggfunc in pairs:
|
| 1778 |
+
aggspec[column].append(aggfunc)
|
| 1779 |
+
order.append((column, com.get_callable_name(aggfunc) or aggfunc))
|
| 1780 |
+
|
| 1781 |
+
# uniquify aggfunc name if duplicated in order list
|
| 1782 |
+
uniquified_order = _make_unique_kwarg_list(order)
|
| 1783 |
+
|
| 1784 |
+
# GH 25719, due to aggspec will change the order of assigned columns in aggregation
|
| 1785 |
+
# uniquified_aggspec will store uniquified order list and will compare it with order
|
| 1786 |
+
# based on index
|
| 1787 |
+
aggspec_order = [
|
| 1788 |
+
(column, com.get_callable_name(aggfunc) or aggfunc)
|
| 1789 |
+
for column, aggfuncs in aggspec.items()
|
| 1790 |
+
for aggfunc in aggfuncs
|
| 1791 |
+
]
|
| 1792 |
+
uniquified_aggspec = _make_unique_kwarg_list(aggspec_order)
|
| 1793 |
+
|
| 1794 |
+
# get the new index of columns by comparison
|
| 1795 |
+
col_idx_order = Index(uniquified_aggspec).get_indexer(uniquified_order)
|
| 1796 |
+
return aggspec, columns, col_idx_order
|
| 1797 |
+
|
| 1798 |
+
|
| 1799 |
+
def _make_unique_kwarg_list(
|
| 1800 |
+
seq: Sequence[tuple[Any, Any]]
|
| 1801 |
+
) -> Sequence[tuple[Any, Any]]:
|
| 1802 |
+
"""
|
| 1803 |
+
Uniquify aggfunc name of the pairs in the order list
|
| 1804 |
+
|
| 1805 |
+
Examples:
|
| 1806 |
+
--------
|
| 1807 |
+
>>> kwarg_list = [('a', '<lambda>'), ('a', '<lambda>'), ('b', '<lambda>')]
|
| 1808 |
+
>>> _make_unique_kwarg_list(kwarg_list)
|
| 1809 |
+
[('a', '<lambda>_0'), ('a', '<lambda>_1'), ('b', '<lambda>')]
|
| 1810 |
+
"""
|
| 1811 |
+
return [
|
| 1812 |
+
(pair[0], f"{pair[1]}_{seq[:i].count(pair)}") if seq.count(pair) > 1 else pair
|
| 1813 |
+
for i, pair in enumerate(seq)
|
| 1814 |
+
]
|
| 1815 |
+
|
| 1816 |
+
|
| 1817 |
+
def relabel_result(
|
| 1818 |
+
result: DataFrame | Series,
|
| 1819 |
+
func: dict[str, list[Callable | str]],
|
| 1820 |
+
columns: Iterable[Hashable],
|
| 1821 |
+
order: Iterable[int],
|
| 1822 |
+
) -> dict[Hashable, Series]:
|
| 1823 |
+
"""
|
| 1824 |
+
Internal function to reorder result if relabelling is True for
|
| 1825 |
+
dataframe.agg, and return the reordered result in dict.
|
| 1826 |
+
|
| 1827 |
+
Parameters:
|
| 1828 |
+
----------
|
| 1829 |
+
result: Result from aggregation
|
| 1830 |
+
func: Dict of (column name, funcs)
|
| 1831 |
+
columns: New columns name for relabelling
|
| 1832 |
+
order: New order for relabelling
|
| 1833 |
+
|
| 1834 |
+
Examples
|
| 1835 |
+
--------
|
| 1836 |
+
>>> from pandas.core.apply import relabel_result
|
| 1837 |
+
>>> result = pd.DataFrame(
|
| 1838 |
+
... {"A": [np.nan, 2, np.nan], "C": [6, np.nan, np.nan], "B": [np.nan, 4, 2.5]},
|
| 1839 |
+
... index=["max", "mean", "min"]
|
| 1840 |
+
... )
|
| 1841 |
+
>>> funcs = {"A": ["max"], "C": ["max"], "B": ["mean", "min"]}
|
| 1842 |
+
>>> columns = ("foo", "aab", "bar", "dat")
|
| 1843 |
+
>>> order = [0, 1, 2, 3]
|
| 1844 |
+
>>> result_in_dict = relabel_result(result, funcs, columns, order)
|
| 1845 |
+
>>> pd.DataFrame(result_in_dict, index=columns)
|
| 1846 |
+
A C B
|
| 1847 |
+
foo 2.0 NaN NaN
|
| 1848 |
+
aab NaN 6.0 NaN
|
| 1849 |
+
bar NaN NaN 4.0
|
| 1850 |
+
dat NaN NaN 2.5
|
| 1851 |
+
"""
|
| 1852 |
+
from pandas.core.indexes.base import Index
|
| 1853 |
+
|
| 1854 |
+
reordered_indexes = [
|
| 1855 |
+
pair[0] for pair in sorted(zip(columns, order), key=lambda t: t[1])
|
| 1856 |
+
]
|
| 1857 |
+
reordered_result_in_dict: dict[Hashable, Series] = {}
|
| 1858 |
+
idx = 0
|
| 1859 |
+
|
| 1860 |
+
reorder_mask = not isinstance(result, ABCSeries) and len(result.columns) > 1
|
| 1861 |
+
for col, fun in func.items():
|
| 1862 |
+
s = result[col].dropna()
|
| 1863 |
+
|
| 1864 |
+
# In the `_aggregate`, the callable names are obtained and used in `result`, and
|
| 1865 |
+
# these names are ordered alphabetically. e.g.
|
| 1866 |
+
# C2 C1
|
| 1867 |
+
# <lambda> 1 NaN
|
| 1868 |
+
# amax NaN 4.0
|
| 1869 |
+
# max NaN 4.0
|
| 1870 |
+
# sum 18.0 6.0
|
| 1871 |
+
# Therefore, the order of functions for each column could be shuffled
|
| 1872 |
+
# accordingly so need to get the callable name if it is not parsed names, and
|
| 1873 |
+
# reorder the aggregated result for each column.
|
| 1874 |
+
# e.g. if df.agg(c1=("C2", sum), c2=("C2", lambda x: min(x))), correct order is
|
| 1875 |
+
# [sum, <lambda>], but in `result`, it will be [<lambda>, sum], and we need to
|
| 1876 |
+
# reorder so that aggregated values map to their functions regarding the order.
|
| 1877 |
+
|
| 1878 |
+
# However there is only one column being used for aggregation, not need to
|
| 1879 |
+
# reorder since the index is not sorted, and keep as is in `funcs`, e.g.
|
| 1880 |
+
# A
|
| 1881 |
+
# min 1.0
|
| 1882 |
+
# mean 1.5
|
| 1883 |
+
# mean 1.5
|
| 1884 |
+
if reorder_mask:
|
| 1885 |
+
fun = [
|
| 1886 |
+
com.get_callable_name(f) if not isinstance(f, str) else f for f in fun
|
| 1887 |
+
]
|
| 1888 |
+
col_idx_order = Index(s.index).get_indexer(fun)
|
| 1889 |
+
s = s.iloc[col_idx_order]
|
| 1890 |
+
|
| 1891 |
+
# assign the new user-provided "named aggregation" as index names, and reindex
|
| 1892 |
+
# it based on the whole user-provided names.
|
| 1893 |
+
s.index = reordered_indexes[idx : idx + len(fun)]
|
| 1894 |
+
reordered_result_in_dict[col] = s.reindex(columns, copy=False)
|
| 1895 |
+
idx = idx + len(fun)
|
| 1896 |
+
return reordered_result_in_dict
|
| 1897 |
+
|
| 1898 |
+
|
| 1899 |
+
def reconstruct_and_relabel_result(result, func, **kwargs) -> DataFrame | Series:
|
| 1900 |
+
from pandas import DataFrame
|
| 1901 |
+
|
| 1902 |
+
relabeling, func, columns, order = reconstruct_func(func, **kwargs)
|
| 1903 |
+
|
| 1904 |
+
if relabeling:
|
| 1905 |
+
# This is to keep the order to columns occurrence unchanged, and also
|
| 1906 |
+
# keep the order of new columns occurrence unchanged
|
| 1907 |
+
|
| 1908 |
+
# For the return values of reconstruct_func, if relabeling is
|
| 1909 |
+
# False, columns and order will be None.
|
| 1910 |
+
assert columns is not None
|
| 1911 |
+
assert order is not None
|
| 1912 |
+
|
| 1913 |
+
result_in_dict = relabel_result(result, func, columns, order)
|
| 1914 |
+
result = DataFrame(result_in_dict, index=columns)
|
| 1915 |
+
|
| 1916 |
+
return result
|
| 1917 |
+
|
| 1918 |
+
|
| 1919 |
+
# TODO: Can't use, because mypy doesn't like us setting __name__
|
| 1920 |
+
# error: "partial[Any]" has no attribute "__name__"
|
| 1921 |
+
# the type is:
|
| 1922 |
+
# typing.Sequence[Callable[..., ScalarResult]]
|
| 1923 |
+
# -> typing.Sequence[Callable[..., ScalarResult]]:
|
| 1924 |
+
|
| 1925 |
+
|
| 1926 |
+
def _managle_lambda_list(aggfuncs: Sequence[Any]) -> Sequence[Any]:
|
| 1927 |
+
"""
|
| 1928 |
+
Possibly mangle a list of aggfuncs.
|
| 1929 |
+
|
| 1930 |
+
Parameters
|
| 1931 |
+
----------
|
| 1932 |
+
aggfuncs : Sequence
|
| 1933 |
+
|
| 1934 |
+
Returns
|
| 1935 |
+
-------
|
| 1936 |
+
mangled: list-like
|
| 1937 |
+
A new AggSpec sequence, where lambdas have been converted
|
| 1938 |
+
to have unique names.
|
| 1939 |
+
|
| 1940 |
+
Notes
|
| 1941 |
+
-----
|
| 1942 |
+
If just one aggfunc is passed, the name will not be mangled.
|
| 1943 |
+
"""
|
| 1944 |
+
if len(aggfuncs) <= 1:
|
| 1945 |
+
# don't mangle for .agg([lambda x: .])
|
| 1946 |
+
return aggfuncs
|
| 1947 |
+
i = 0
|
| 1948 |
+
mangled_aggfuncs = []
|
| 1949 |
+
for aggfunc in aggfuncs:
|
| 1950 |
+
if com.get_callable_name(aggfunc) == "<lambda>":
|
| 1951 |
+
aggfunc = partial(aggfunc)
|
| 1952 |
+
aggfunc.__name__ = f"<lambda_{i}>"
|
| 1953 |
+
i += 1
|
| 1954 |
+
mangled_aggfuncs.append(aggfunc)
|
| 1955 |
+
|
| 1956 |
+
return mangled_aggfuncs
|
| 1957 |
+
|
| 1958 |
+
|
| 1959 |
+
def maybe_mangle_lambdas(agg_spec: Any) -> Any:
|
| 1960 |
+
"""
|
| 1961 |
+
Make new lambdas with unique names.
|
| 1962 |
+
|
| 1963 |
+
Parameters
|
| 1964 |
+
----------
|
| 1965 |
+
agg_spec : Any
|
| 1966 |
+
An argument to GroupBy.agg.
|
| 1967 |
+
Non-dict-like `agg_spec` are pass through as is.
|
| 1968 |
+
For dict-like `agg_spec` a new spec is returned
|
| 1969 |
+
with name-mangled lambdas.
|
| 1970 |
+
|
| 1971 |
+
Returns
|
| 1972 |
+
-------
|
| 1973 |
+
mangled : Any
|
| 1974 |
+
Same type as the input.
|
| 1975 |
+
|
| 1976 |
+
Examples
|
| 1977 |
+
--------
|
| 1978 |
+
>>> maybe_mangle_lambdas('sum')
|
| 1979 |
+
'sum'
|
| 1980 |
+
>>> maybe_mangle_lambdas([lambda: 1, lambda: 2]) # doctest: +SKIP
|
| 1981 |
+
[<function __main__.<lambda_0>,
|
| 1982 |
+
<function pandas...._make_lambda.<locals>.f(*args, **kwargs)>]
|
| 1983 |
+
"""
|
| 1984 |
+
is_dict = is_dict_like(agg_spec)
|
| 1985 |
+
if not (is_dict or is_list_like(agg_spec)):
|
| 1986 |
+
return agg_spec
|
| 1987 |
+
mangled_aggspec = type(agg_spec)() # dict or OrderedDict
|
| 1988 |
+
|
| 1989 |
+
if is_dict:
|
| 1990 |
+
for key, aggfuncs in agg_spec.items():
|
| 1991 |
+
if is_list_like(aggfuncs) and not is_dict_like(aggfuncs):
|
| 1992 |
+
mangled_aggfuncs = _managle_lambda_list(aggfuncs)
|
| 1993 |
+
else:
|
| 1994 |
+
mangled_aggfuncs = aggfuncs
|
| 1995 |
+
|
| 1996 |
+
mangled_aggspec[key] = mangled_aggfuncs
|
| 1997 |
+
else:
|
| 1998 |
+
mangled_aggspec = _managle_lambda_list(agg_spec)
|
| 1999 |
+
|
| 2000 |
+
return mangled_aggspec
|
| 2001 |
+
|
| 2002 |
+
|
| 2003 |
+
def validate_func_kwargs(
|
| 2004 |
+
kwargs: dict,
|
| 2005 |
+
) -> tuple[list[str], list[str | Callable[..., Any]]]:
|
| 2006 |
+
"""
|
| 2007 |
+
Validates types of user-provided "named aggregation" kwargs.
|
| 2008 |
+
`TypeError` is raised if aggfunc is not `str` or callable.
|
| 2009 |
+
|
| 2010 |
+
Parameters
|
| 2011 |
+
----------
|
| 2012 |
+
kwargs : dict
|
| 2013 |
+
|
| 2014 |
+
Returns
|
| 2015 |
+
-------
|
| 2016 |
+
columns : List[str]
|
| 2017 |
+
List of user-provided keys.
|
| 2018 |
+
func : List[Union[str, callable[...,Any]]]
|
| 2019 |
+
List of user-provided aggfuncs
|
| 2020 |
+
|
| 2021 |
+
Examples
|
| 2022 |
+
--------
|
| 2023 |
+
>>> validate_func_kwargs({'one': 'min', 'two': 'max'})
|
| 2024 |
+
(['one', 'two'], ['min', 'max'])
|
| 2025 |
+
"""
|
| 2026 |
+
tuple_given_message = "func is expected but received {} in **kwargs."
|
| 2027 |
+
columns = list(kwargs)
|
| 2028 |
+
func = []
|
| 2029 |
+
for col_func in kwargs.values():
|
| 2030 |
+
if not (isinstance(col_func, str) or callable(col_func)):
|
| 2031 |
+
raise TypeError(tuple_given_message.format(type(col_func).__name__))
|
| 2032 |
+
func.append(col_func)
|
| 2033 |
+
if not columns:
|
| 2034 |
+
no_arg_message = "Must provide 'func' or named aggregation **kwargs."
|
| 2035 |
+
raise TypeError(no_arg_message)
|
| 2036 |
+
return columns, func
|
| 2037 |
+
|
| 2038 |
+
|
| 2039 |
+
def include_axis(op_name: Literal["agg", "apply"], colg: Series | DataFrame) -> bool:
|
| 2040 |
+
return isinstance(colg, ABCDataFrame) or (
|
| 2041 |
+
isinstance(colg, ABCSeries) and op_name == "agg"
|
| 2042 |
+
)
|
| 2043 |
+
|
| 2044 |
+
|
| 2045 |
+
def warn_alias_replacement(
|
| 2046 |
+
obj: AggObjType,
|
| 2047 |
+
func: Callable,
|
| 2048 |
+
alias: str,
|
| 2049 |
+
) -> None:
|
| 2050 |
+
if alias.startswith("np."):
|
| 2051 |
+
full_alias = alias
|
| 2052 |
+
else:
|
| 2053 |
+
full_alias = f"{type(obj).__name__}.{alias}"
|
| 2054 |
+
alias = f'"{alias}"'
|
| 2055 |
+
warnings.warn(
|
| 2056 |
+
f"The provided callable {func} is currently using "
|
| 2057 |
+
f"{full_alias}. In a future version of pandas, "
|
| 2058 |
+
f"the provided callable will be used directly. To keep current "
|
| 2059 |
+
f"behavior pass the string {alias} instead.",
|
| 2060 |
+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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Methods that can be shared by many array-like classes or subclasses:
|
| 3 |
+
Series
|
| 4 |
+
Index
|
| 5 |
+
ExtensionArray
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import operator
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
|
| 14 |
+
from pandas._libs import lib
|
| 15 |
+
from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op
|
| 16 |
+
|
| 17 |
+
from pandas.core.dtypes.generic import ABCNDFrame
|
| 18 |
+
|
| 19 |
+
from pandas.core import roperator
|
| 20 |
+
from pandas.core.construction import extract_array
|
| 21 |
+
from pandas.core.ops.common import unpack_zerodim_and_defer
|
| 22 |
+
|
| 23 |
+
REDUCTION_ALIASES = {
|
| 24 |
+
"maximum": "max",
|
| 25 |
+
"minimum": "min",
|
| 26 |
+
"add": "sum",
|
| 27 |
+
"multiply": "prod",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class OpsMixin:
|
| 32 |
+
# -------------------------------------------------------------
|
| 33 |
+
# Comparisons
|
| 34 |
+
|
| 35 |
+
def _cmp_method(self, other, op):
|
| 36 |
+
return NotImplemented
|
| 37 |
+
|
| 38 |
+
@unpack_zerodim_and_defer("__eq__")
|
| 39 |
+
def __eq__(self, other):
|
| 40 |
+
return self._cmp_method(other, operator.eq)
|
| 41 |
+
|
| 42 |
+
@unpack_zerodim_and_defer("__ne__")
|
| 43 |
+
def __ne__(self, other):
|
| 44 |
+
return self._cmp_method(other, operator.ne)
|
| 45 |
+
|
| 46 |
+
@unpack_zerodim_and_defer("__lt__")
|
| 47 |
+
def __lt__(self, other):
|
| 48 |
+
return self._cmp_method(other, operator.lt)
|
| 49 |
+
|
| 50 |
+
@unpack_zerodim_and_defer("__le__")
|
| 51 |
+
def __le__(self, other):
|
| 52 |
+
return self._cmp_method(other, operator.le)
|
| 53 |
+
|
| 54 |
+
@unpack_zerodim_and_defer("__gt__")
|
| 55 |
+
def __gt__(self, other):
|
| 56 |
+
return self._cmp_method(other, operator.gt)
|
| 57 |
+
|
| 58 |
+
@unpack_zerodim_and_defer("__ge__")
|
| 59 |
+
def __ge__(self, other):
|
| 60 |
+
return self._cmp_method(other, operator.ge)
|
| 61 |
+
|
| 62 |
+
# -------------------------------------------------------------
|
| 63 |
+
# Logical Methods
|
| 64 |
+
|
| 65 |
+
def _logical_method(self, other, op):
|
| 66 |
+
return NotImplemented
|
| 67 |
+
|
| 68 |
+
@unpack_zerodim_and_defer("__and__")
|
| 69 |
+
def __and__(self, other):
|
| 70 |
+
return self._logical_method(other, operator.and_)
|
| 71 |
+
|
| 72 |
+
@unpack_zerodim_and_defer("__rand__")
|
| 73 |
+
def __rand__(self, other):
|
| 74 |
+
return self._logical_method(other, roperator.rand_)
|
| 75 |
+
|
| 76 |
+
@unpack_zerodim_and_defer("__or__")
|
| 77 |
+
def __or__(self, other):
|
| 78 |
+
return self._logical_method(other, operator.or_)
|
| 79 |
+
|
| 80 |
+
@unpack_zerodim_and_defer("__ror__")
|
| 81 |
+
def __ror__(self, other):
|
| 82 |
+
return self._logical_method(other, roperator.ror_)
|
| 83 |
+
|
| 84 |
+
@unpack_zerodim_and_defer("__xor__")
|
| 85 |
+
def __xor__(self, other):
|
| 86 |
+
return self._logical_method(other, operator.xor)
|
| 87 |
+
|
| 88 |
+
@unpack_zerodim_and_defer("__rxor__")
|
| 89 |
+
def __rxor__(self, other):
|
| 90 |
+
return self._logical_method(other, roperator.rxor)
|
| 91 |
+
|
| 92 |
+
# -------------------------------------------------------------
|
| 93 |
+
# Arithmetic Methods
|
| 94 |
+
|
| 95 |
+
def _arith_method(self, other, op):
|
| 96 |
+
return NotImplemented
|
| 97 |
+
|
| 98 |
+
@unpack_zerodim_and_defer("__add__")
|
| 99 |
+
def __add__(self, other):
|
| 100 |
+
"""
|
| 101 |
+
Get Addition of DataFrame and other, column-wise.
|
| 102 |
+
|
| 103 |
+
Equivalent to ``DataFrame.add(other)``.
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
other : scalar, sequence, Series, dict or DataFrame
|
| 108 |
+
Object to be added to the DataFrame.
|
| 109 |
+
|
| 110 |
+
Returns
|
| 111 |
+
-------
|
| 112 |
+
DataFrame
|
| 113 |
+
The result of adding ``other`` to DataFrame.
|
| 114 |
+
|
| 115 |
+
See Also
|
| 116 |
+
--------
|
| 117 |
+
DataFrame.add : Add a DataFrame and another object, with option for index-
|
| 118 |
+
or column-oriented addition.
|
| 119 |
+
|
| 120 |
+
Examples
|
| 121 |
+
--------
|
| 122 |
+
>>> df = pd.DataFrame({'height': [1.5, 2.6], 'weight': [500, 800]},
|
| 123 |
+
... index=['elk', 'moose'])
|
| 124 |
+
>>> df
|
| 125 |
+
height weight
|
| 126 |
+
elk 1.5 500
|
| 127 |
+
moose 2.6 800
|
| 128 |
+
|
| 129 |
+
Adding a scalar affects all rows and columns.
|
| 130 |
+
|
| 131 |
+
>>> df[['height', 'weight']] + 1.5
|
| 132 |
+
height weight
|
| 133 |
+
elk 3.0 501.5
|
| 134 |
+
moose 4.1 801.5
|
| 135 |
+
|
| 136 |
+
Each element of a list is added to a column of the DataFrame, in order.
|
| 137 |
+
|
| 138 |
+
>>> df[['height', 'weight']] + [0.5, 1.5]
|
| 139 |
+
height weight
|
| 140 |
+
elk 2.0 501.5
|
| 141 |
+
moose 3.1 801.5
|
| 142 |
+
|
| 143 |
+
Keys of a dictionary are aligned to the DataFrame, based on column names;
|
| 144 |
+
each value in the dictionary is added to the corresponding column.
|
| 145 |
+
|
| 146 |
+
>>> df[['height', 'weight']] + {'height': 0.5, 'weight': 1.5}
|
| 147 |
+
height weight
|
| 148 |
+
elk 2.0 501.5
|
| 149 |
+
moose 3.1 801.5
|
| 150 |
+
|
| 151 |
+
When `other` is a :class:`Series`, the index of `other` is aligned with the
|
| 152 |
+
columns of the DataFrame.
|
| 153 |
+
|
| 154 |
+
>>> s1 = pd.Series([0.5, 1.5], index=['weight', 'height'])
|
| 155 |
+
>>> df[['height', 'weight']] + s1
|
| 156 |
+
height weight
|
| 157 |
+
elk 3.0 500.5
|
| 158 |
+
moose 4.1 800.5
|
| 159 |
+
|
| 160 |
+
Even when the index of `other` is the same as the index of the DataFrame,
|
| 161 |
+
the :class:`Series` will not be reoriented. If index-wise alignment is desired,
|
| 162 |
+
:meth:`DataFrame.add` should be used with `axis='index'`.
|
| 163 |
+
|
| 164 |
+
>>> s2 = pd.Series([0.5, 1.5], index=['elk', 'moose'])
|
| 165 |
+
>>> df[['height', 'weight']] + s2
|
| 166 |
+
elk height moose weight
|
| 167 |
+
elk NaN NaN NaN NaN
|
| 168 |
+
moose NaN NaN NaN NaN
|
| 169 |
+
|
| 170 |
+
>>> df[['height', 'weight']].add(s2, axis='index')
|
| 171 |
+
height weight
|
| 172 |
+
elk 2.0 500.5
|
| 173 |
+
moose 4.1 801.5
|
| 174 |
+
|
| 175 |
+
When `other` is a :class:`DataFrame`, both columns names and the
|
| 176 |
+
index are aligned.
|
| 177 |
+
|
| 178 |
+
>>> other = pd.DataFrame({'height': [0.2, 0.4, 0.6]},
|
| 179 |
+
... index=['elk', 'moose', 'deer'])
|
| 180 |
+
>>> df[['height', 'weight']] + other
|
| 181 |
+
height weight
|
| 182 |
+
deer NaN NaN
|
| 183 |
+
elk 1.7 NaN
|
| 184 |
+
moose 3.0 NaN
|
| 185 |
+
"""
|
| 186 |
+
return self._arith_method(other, operator.add)
|
| 187 |
+
|
| 188 |
+
@unpack_zerodim_and_defer("__radd__")
|
| 189 |
+
def __radd__(self, other):
|
| 190 |
+
return self._arith_method(other, roperator.radd)
|
| 191 |
+
|
| 192 |
+
@unpack_zerodim_and_defer("__sub__")
|
| 193 |
+
def __sub__(self, other):
|
| 194 |
+
return self._arith_method(other, operator.sub)
|
| 195 |
+
|
| 196 |
+
@unpack_zerodim_and_defer("__rsub__")
|
| 197 |
+
def __rsub__(self, other):
|
| 198 |
+
return self._arith_method(other, roperator.rsub)
|
| 199 |
+
|
| 200 |
+
@unpack_zerodim_and_defer("__mul__")
|
| 201 |
+
def __mul__(self, other):
|
| 202 |
+
return self._arith_method(other, operator.mul)
|
| 203 |
+
|
| 204 |
+
@unpack_zerodim_and_defer("__rmul__")
|
| 205 |
+
def __rmul__(self, other):
|
| 206 |
+
return self._arith_method(other, roperator.rmul)
|
| 207 |
+
|
| 208 |
+
@unpack_zerodim_and_defer("__truediv__")
|
| 209 |
+
def __truediv__(self, other):
|
| 210 |
+
return self._arith_method(other, operator.truediv)
|
| 211 |
+
|
| 212 |
+
@unpack_zerodim_and_defer("__rtruediv__")
|
| 213 |
+
def __rtruediv__(self, other):
|
| 214 |
+
return self._arith_method(other, roperator.rtruediv)
|
| 215 |
+
|
| 216 |
+
@unpack_zerodim_and_defer("__floordiv__")
|
| 217 |
+
def __floordiv__(self, other):
|
| 218 |
+
return self._arith_method(other, operator.floordiv)
|
| 219 |
+
|
| 220 |
+
@unpack_zerodim_and_defer("__rfloordiv")
|
| 221 |
+
def __rfloordiv__(self, other):
|
| 222 |
+
return self._arith_method(other, roperator.rfloordiv)
|
| 223 |
+
|
| 224 |
+
@unpack_zerodim_and_defer("__mod__")
|
| 225 |
+
def __mod__(self, other):
|
| 226 |
+
return self._arith_method(other, operator.mod)
|
| 227 |
+
|
| 228 |
+
@unpack_zerodim_and_defer("__rmod__")
|
| 229 |
+
def __rmod__(self, other):
|
| 230 |
+
return self._arith_method(other, roperator.rmod)
|
| 231 |
+
|
| 232 |
+
@unpack_zerodim_and_defer("__divmod__")
|
| 233 |
+
def __divmod__(self, other):
|
| 234 |
+
return self._arith_method(other, divmod)
|
| 235 |
+
|
| 236 |
+
@unpack_zerodim_and_defer("__rdivmod__")
|
| 237 |
+
def __rdivmod__(self, other):
|
| 238 |
+
return self._arith_method(other, roperator.rdivmod)
|
| 239 |
+
|
| 240 |
+
@unpack_zerodim_and_defer("__pow__")
|
| 241 |
+
def __pow__(self, other):
|
| 242 |
+
return self._arith_method(other, operator.pow)
|
| 243 |
+
|
| 244 |
+
@unpack_zerodim_and_defer("__rpow__")
|
| 245 |
+
def __rpow__(self, other):
|
| 246 |
+
return self._arith_method(other, roperator.rpow)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
# -----------------------------------------------------------------------------
|
| 250 |
+
# Helpers to implement __array_ufunc__
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any):
|
| 254 |
+
"""
|
| 255 |
+
Compatibility with numpy ufuncs.
|
| 256 |
+
|
| 257 |
+
See also
|
| 258 |
+
--------
|
| 259 |
+
numpy.org/doc/stable/reference/arrays.classes.html#numpy.class.__array_ufunc__
|
| 260 |
+
"""
|
| 261 |
+
from pandas.core.frame import (
|
| 262 |
+
DataFrame,
|
| 263 |
+
Series,
|
| 264 |
+
)
|
| 265 |
+
from pandas.core.generic import NDFrame
|
| 266 |
+
from pandas.core.internals import (
|
| 267 |
+
ArrayManager,
|
| 268 |
+
BlockManager,
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
cls = type(self)
|
| 272 |
+
|
| 273 |
+
kwargs = _standardize_out_kwarg(**kwargs)
|
| 274 |
+
|
| 275 |
+
# for binary ops, use our custom dunder methods
|
| 276 |
+
result = maybe_dispatch_ufunc_to_dunder_op(self, ufunc, method, *inputs, **kwargs)
|
| 277 |
+
if result is not NotImplemented:
|
| 278 |
+
return result
|
| 279 |
+
|
| 280 |
+
# Determine if we should defer.
|
| 281 |
+
no_defer = (
|
| 282 |
+
np.ndarray.__array_ufunc__,
|
| 283 |
+
cls.__array_ufunc__,
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
for item in inputs:
|
| 287 |
+
higher_priority = (
|
| 288 |
+
hasattr(item, "__array_priority__")
|
| 289 |
+
and item.__array_priority__ > self.__array_priority__
|
| 290 |
+
)
|
| 291 |
+
has_array_ufunc = (
|
| 292 |
+
hasattr(item, "__array_ufunc__")
|
| 293 |
+
and type(item).__array_ufunc__ not in no_defer
|
| 294 |
+
and not isinstance(item, self._HANDLED_TYPES)
|
| 295 |
+
)
|
| 296 |
+
if higher_priority or has_array_ufunc:
|
| 297 |
+
return NotImplemented
|
| 298 |
+
|
| 299 |
+
# align all the inputs.
|
| 300 |
+
types = tuple(type(x) for x in inputs)
|
| 301 |
+
alignable = [x for x, t in zip(inputs, types) if issubclass(t, NDFrame)]
|
| 302 |
+
|
| 303 |
+
if len(alignable) > 1:
|
| 304 |
+
# This triggers alignment.
|
| 305 |
+
# At the moment, there aren't any ufuncs with more than two inputs
|
| 306 |
+
# so this ends up just being x1.index | x2.index, but we write
|
| 307 |
+
# it to handle *args.
|
| 308 |
+
set_types = set(types)
|
| 309 |
+
if len(set_types) > 1 and {DataFrame, Series}.issubset(set_types):
|
| 310 |
+
# We currently don't handle ufunc(DataFrame, Series)
|
| 311 |
+
# well. Previously this raised an internal ValueError. We might
|
| 312 |
+
# support it someday, so raise a NotImplementedError.
|
| 313 |
+
raise NotImplementedError(
|
| 314 |
+
f"Cannot apply ufunc {ufunc} to mixed DataFrame and Series inputs."
|
| 315 |
+
)
|
| 316 |
+
axes = self.axes
|
| 317 |
+
for obj in alignable[1:]:
|
| 318 |
+
# this relies on the fact that we aren't handling mixed
|
| 319 |
+
# series / frame ufuncs.
|
| 320 |
+
for i, (ax1, ax2) in enumerate(zip(axes, obj.axes)):
|
| 321 |
+
axes[i] = ax1.union(ax2)
|
| 322 |
+
|
| 323 |
+
reconstruct_axes = dict(zip(self._AXIS_ORDERS, axes))
|
| 324 |
+
inputs = tuple(
|
| 325 |
+
x.reindex(**reconstruct_axes) if issubclass(t, NDFrame) else x
|
| 326 |
+
for x, t in zip(inputs, types)
|
| 327 |
+
)
|
| 328 |
+
else:
|
| 329 |
+
reconstruct_axes = dict(zip(self._AXIS_ORDERS, self.axes))
|
| 330 |
+
|
| 331 |
+
if self.ndim == 1:
|
| 332 |
+
names = [getattr(x, "name") for x in inputs if hasattr(x, "name")]
|
| 333 |
+
name = names[0] if len(set(names)) == 1 else None
|
| 334 |
+
reconstruct_kwargs = {"name": name}
|
| 335 |
+
else:
|
| 336 |
+
reconstruct_kwargs = {}
|
| 337 |
+
|
| 338 |
+
def reconstruct(result):
|
| 339 |
+
if ufunc.nout > 1:
|
| 340 |
+
# np.modf, np.frexp, np.divmod
|
| 341 |
+
return tuple(_reconstruct(x) for x in result)
|
| 342 |
+
|
| 343 |
+
return _reconstruct(result)
|
| 344 |
+
|
| 345 |
+
def _reconstruct(result):
|
| 346 |
+
if lib.is_scalar(result):
|
| 347 |
+
return result
|
| 348 |
+
|
| 349 |
+
if result.ndim != self.ndim:
|
| 350 |
+
if method == "outer":
|
| 351 |
+
raise NotImplementedError
|
| 352 |
+
return result
|
| 353 |
+
if isinstance(result, (BlockManager, ArrayManager)):
|
| 354 |
+
# we went through BlockManager.apply e.g. np.sqrt
|
| 355 |
+
result = self._constructor_from_mgr(result, axes=result.axes)
|
| 356 |
+
else:
|
| 357 |
+
# we converted an array, lost our axes
|
| 358 |
+
result = self._constructor(
|
| 359 |
+
result, **reconstruct_axes, **reconstruct_kwargs, copy=False
|
| 360 |
+
)
|
| 361 |
+
# TODO: When we support multiple values in __finalize__, this
|
| 362 |
+
# should pass alignable to `__finalize__` instead of self.
|
| 363 |
+
# Then `np.add(a, b)` would consider attrs from both a and b
|
| 364 |
+
# when a and b are NDFrames.
|
| 365 |
+
if len(alignable) == 1:
|
| 366 |
+
result = result.__finalize__(self)
|
| 367 |
+
return result
|
| 368 |
+
|
| 369 |
+
if "out" in kwargs:
|
| 370 |
+
# e.g. test_multiindex_get_loc
|
| 371 |
+
result = dispatch_ufunc_with_out(self, ufunc, method, *inputs, **kwargs)
|
| 372 |
+
return reconstruct(result)
|
| 373 |
+
|
| 374 |
+
if method == "reduce":
|
| 375 |
+
# e.g. test.series.test_ufunc.test_reduce
|
| 376 |
+
result = dispatch_reduction_ufunc(self, ufunc, method, *inputs, **kwargs)
|
| 377 |
+
if result is not NotImplemented:
|
| 378 |
+
return result
|
| 379 |
+
|
| 380 |
+
# We still get here with kwargs `axis` for e.g. np.maximum.accumulate
|
| 381 |
+
# and `dtype` and `keepdims` for np.ptp
|
| 382 |
+
|
| 383 |
+
if self.ndim > 1 and (len(inputs) > 1 or ufunc.nout > 1):
|
| 384 |
+
# Just give up on preserving types in the complex case.
|
| 385 |
+
# In theory we could preserve them for them.
|
| 386 |
+
# * nout>1 is doable if BlockManager.apply took nout and
|
| 387 |
+
# returned a Tuple[BlockManager].
|
| 388 |
+
# * len(inputs) > 1 is doable when we know that we have
|
| 389 |
+
# aligned blocks / dtypes.
|
| 390 |
+
|
| 391 |
+
# e.g. my_ufunc, modf, logaddexp, heaviside, subtract, add
|
| 392 |
+
inputs = tuple(np.asarray(x) for x in inputs)
|
| 393 |
+
# Note: we can't use default_array_ufunc here bc reindexing means
|
| 394 |
+
# that `self` may not be among `inputs`
|
| 395 |
+
result = getattr(ufunc, method)(*inputs, **kwargs)
|
| 396 |
+
elif self.ndim == 1:
|
| 397 |
+
# ufunc(series, ...)
|
| 398 |
+
inputs = tuple(extract_array(x, extract_numpy=True) for x in inputs)
|
| 399 |
+
result = getattr(ufunc, method)(*inputs, **kwargs)
|
| 400 |
+
else:
|
| 401 |
+
# ufunc(dataframe)
|
| 402 |
+
if method == "__call__" and not kwargs:
|
| 403 |
+
# for np.<ufunc>(..) calls
|
| 404 |
+
# kwargs cannot necessarily be handled block-by-block, so only
|
| 405 |
+
# take this path if there are no kwargs
|
| 406 |
+
mgr = inputs[0]._mgr
|
| 407 |
+
result = mgr.apply(getattr(ufunc, method))
|
| 408 |
+
else:
|
| 409 |
+
# otherwise specific ufunc methods (eg np.<ufunc>.accumulate(..))
|
| 410 |
+
# Those can have an axis keyword and thus can't be called block-by-block
|
| 411 |
+
result = default_array_ufunc(inputs[0], ufunc, method, *inputs, **kwargs)
|
| 412 |
+
# e.g. np.negative (only one reached), with "where" and "out" in kwargs
|
| 413 |
+
|
| 414 |
+
result = reconstruct(result)
|
| 415 |
+
return result
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
def _standardize_out_kwarg(**kwargs) -> dict:
|
| 419 |
+
"""
|
| 420 |
+
If kwargs contain "out1" and "out2", replace that with a tuple "out"
|
| 421 |
+
|
| 422 |
+
np.divmod, np.modf, np.frexp can have either `out=(out1, out2)` or
|
| 423 |
+
`out1=out1, out2=out2)`
|
| 424 |
+
"""
|
| 425 |
+
if "out" not in kwargs and "out1" in kwargs and "out2" in kwargs:
|
| 426 |
+
out1 = kwargs.pop("out1")
|
| 427 |
+
out2 = kwargs.pop("out2")
|
| 428 |
+
out = (out1, out2)
|
| 429 |
+
kwargs["out"] = out
|
| 430 |
+
return kwargs
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
def dispatch_ufunc_with_out(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
|
| 434 |
+
"""
|
| 435 |
+
If we have an `out` keyword, then call the ufunc without `out` and then
|
| 436 |
+
set the result into the given `out`.
|
| 437 |
+
"""
|
| 438 |
+
|
| 439 |
+
# Note: we assume _standardize_out_kwarg has already been called.
|
| 440 |
+
out = kwargs.pop("out")
|
| 441 |
+
where = kwargs.pop("where", None)
|
| 442 |
+
|
| 443 |
+
result = getattr(ufunc, method)(*inputs, **kwargs)
|
| 444 |
+
|
| 445 |
+
if result is NotImplemented:
|
| 446 |
+
return NotImplemented
|
| 447 |
+
|
| 448 |
+
if isinstance(result, tuple):
|
| 449 |
+
# i.e. np.divmod, np.modf, np.frexp
|
| 450 |
+
if not isinstance(out, tuple) or len(out) != len(result):
|
| 451 |
+
raise NotImplementedError
|
| 452 |
+
|
| 453 |
+
for arr, res in zip(out, result):
|
| 454 |
+
_assign_where(arr, res, where)
|
| 455 |
+
|
| 456 |
+
return out
|
| 457 |
+
|
| 458 |
+
if isinstance(out, tuple):
|
| 459 |
+
if len(out) == 1:
|
| 460 |
+
out = out[0]
|
| 461 |
+
else:
|
| 462 |
+
raise NotImplementedError
|
| 463 |
+
|
| 464 |
+
_assign_where(out, result, where)
|
| 465 |
+
return out
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
def _assign_where(out, result, where) -> None:
|
| 469 |
+
"""
|
| 470 |
+
Set a ufunc result into 'out', masking with a 'where' argument if necessary.
|
| 471 |
+
"""
|
| 472 |
+
if where is None:
|
| 473 |
+
# no 'where' arg passed to ufunc
|
| 474 |
+
out[:] = result
|
| 475 |
+
else:
|
| 476 |
+
np.putmask(out, where, result)
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
def default_array_ufunc(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
|
| 480 |
+
"""
|
| 481 |
+
Fallback to the behavior we would get if we did not define __array_ufunc__.
|
| 482 |
+
|
| 483 |
+
Notes
|
| 484 |
+
-----
|
| 485 |
+
We are assuming that `self` is among `inputs`.
|
| 486 |
+
"""
|
| 487 |
+
if not any(x is self for x in inputs):
|
| 488 |
+
raise NotImplementedError
|
| 489 |
+
|
| 490 |
+
new_inputs = [x if x is not self else np.asarray(x) for x in inputs]
|
| 491 |
+
|
| 492 |
+
return getattr(ufunc, method)(*new_inputs, **kwargs)
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
def dispatch_reduction_ufunc(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
|
| 496 |
+
"""
|
| 497 |
+
Dispatch ufunc reductions to self's reduction methods.
|
| 498 |
+
"""
|
| 499 |
+
assert method == "reduce"
|
| 500 |
+
|
| 501 |
+
if len(inputs) != 1 or inputs[0] is not self:
|
| 502 |
+
return NotImplemented
|
| 503 |
+
|
| 504 |
+
if ufunc.__name__ not in REDUCTION_ALIASES:
|
| 505 |
+
return NotImplemented
|
| 506 |
+
|
| 507 |
+
method_name = REDUCTION_ALIASES[ufunc.__name__]
|
| 508 |
+
|
| 509 |
+
# NB: we are assuming that min/max represent minimum/maximum methods,
|
| 510 |
+
# which would not be accurate for e.g. Timestamp.min
|
| 511 |
+
if not hasattr(self, method_name):
|
| 512 |
+
return NotImplemented
|
| 513 |
+
|
| 514 |
+
if self.ndim > 1:
|
| 515 |
+
if isinstance(self, ABCNDFrame):
|
| 516 |
+
# TODO: test cases where this doesn't hold, i.e. 2D DTA/TDA
|
| 517 |
+
kwargs["numeric_only"] = False
|
| 518 |
+
|
| 519 |
+
if "axis" not in kwargs:
|
| 520 |
+
# For DataFrame reductions we don't want the default axis=0
|
| 521 |
+
# Note: np.min is not a ufunc, but uses array_function_dispatch,
|
| 522 |
+
# so calls DataFrame.min (without ever getting here) with the np.min
|
| 523 |
+
# default of axis=None, which DataFrame.min catches and changes to axis=0.
|
| 524 |
+
# np.minimum.reduce(df) gets here bc axis is not in kwargs,
|
| 525 |
+
# so we set axis=0 to match the behaviorof np.minimum.reduce(df.values)
|
| 526 |
+
kwargs["axis"] = 0
|
| 527 |
+
|
| 528 |
+
# By default, numpy's reductions do not skip NaNs, so we have to
|
| 529 |
+
# pass skipna=False
|
| 530 |
+
return getattr(self, method_name)(skipna=False, **kwargs)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/pandas/core/base.py
ADDED
|
@@ -0,0 +1,1391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
"""
|
| 2 |
+
Base and utility classes for pandas objects.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import textwrap
|
| 8 |
+
from typing import (
|
| 9 |
+
TYPE_CHECKING,
|
| 10 |
+
Any,
|
| 11 |
+
Generic,
|
| 12 |
+
Literal,
|
| 13 |
+
cast,
|
| 14 |
+
final,
|
| 15 |
+
overload,
|
| 16 |
+
)
|
| 17 |
+
import warnings
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
|
| 21 |
+
from pandas._config import using_copy_on_write
|
| 22 |
+
|
| 23 |
+
from pandas._libs import lib
|
| 24 |
+
from pandas._typing import (
|
| 25 |
+
AxisInt,
|
| 26 |
+
DtypeObj,
|
| 27 |
+
IndexLabel,
|
| 28 |
+
NDFrameT,
|
| 29 |
+
Self,
|
| 30 |
+
Shape,
|
| 31 |
+
npt,
|
| 32 |
+
)
|
| 33 |
+
from pandas.compat import PYPY
|
| 34 |
+
from pandas.compat.numpy import function as nv
|
| 35 |
+
from pandas.errors import AbstractMethodError
|
| 36 |
+
from pandas.util._decorators import (
|
| 37 |
+
cache_readonly,
|
| 38 |
+
doc,
|
| 39 |
+
)
|
| 40 |
+
from pandas.util._exceptions import find_stack_level
|
| 41 |
+
|
| 42 |
+
from pandas.core.dtypes.cast import can_hold_element
|
| 43 |
+
from pandas.core.dtypes.common import (
|
| 44 |
+
is_object_dtype,
|
| 45 |
+
is_scalar,
|
| 46 |
+
)
|
| 47 |
+
from pandas.core.dtypes.dtypes import ExtensionDtype
|
| 48 |
+
from pandas.core.dtypes.generic import (
|
| 49 |
+
ABCDataFrame,
|
| 50 |
+
ABCIndex,
|
| 51 |
+
ABCSeries,
|
| 52 |
+
)
|
| 53 |
+
from pandas.core.dtypes.missing import (
|
| 54 |
+
isna,
|
| 55 |
+
remove_na_arraylike,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
from pandas.core import (
|
| 59 |
+
algorithms,
|
| 60 |
+
nanops,
|
| 61 |
+
ops,
|
| 62 |
+
)
|
| 63 |
+
from pandas.core.accessor import DirNamesMixin
|
| 64 |
+
from pandas.core.arraylike import OpsMixin
|
| 65 |
+
from pandas.core.arrays import ExtensionArray
|
| 66 |
+
from pandas.core.construction import (
|
| 67 |
+
ensure_wrapped_if_datetimelike,
|
| 68 |
+
extract_array,
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
if TYPE_CHECKING:
|
| 72 |
+
from collections.abc import (
|
| 73 |
+
Hashable,
|
| 74 |
+
Iterator,
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
from pandas._typing import (
|
| 78 |
+
DropKeep,
|
| 79 |
+
NumpySorter,
|
| 80 |
+
NumpyValueArrayLike,
|
| 81 |
+
ScalarLike_co,
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
from pandas import (
|
| 85 |
+
DataFrame,
|
| 86 |
+
Index,
|
| 87 |
+
Series,
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
_shared_docs: dict[str, str] = {}
|
| 92 |
+
_indexops_doc_kwargs = {
|
| 93 |
+
"klass": "IndexOpsMixin",
|
| 94 |
+
"inplace": "",
|
| 95 |
+
"unique": "IndexOpsMixin",
|
| 96 |
+
"duplicated": "IndexOpsMixin",
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class PandasObject(DirNamesMixin):
|
| 101 |
+
"""
|
| 102 |
+
Baseclass for various pandas objects.
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
# results from calls to methods decorated with cache_readonly get added to _cache
|
| 106 |
+
_cache: dict[str, Any]
|
| 107 |
+
|
| 108 |
+
@property
|
| 109 |
+
def _constructor(self):
|
| 110 |
+
"""
|
| 111 |
+
Class constructor (for this class it's just `__class__`).
|
| 112 |
+
"""
|
| 113 |
+
return type(self)
|
| 114 |
+
|
| 115 |
+
def __repr__(self) -> str:
|
| 116 |
+
"""
|
| 117 |
+
Return a string representation for a particular object.
|
| 118 |
+
"""
|
| 119 |
+
# Should be overwritten by base classes
|
| 120 |
+
return object.__repr__(self)
|
| 121 |
+
|
| 122 |
+
def _reset_cache(self, key: str | None = None) -> None:
|
| 123 |
+
"""
|
| 124 |
+
Reset cached properties. If ``key`` is passed, only clears that key.
|
| 125 |
+
"""
|
| 126 |
+
if not hasattr(self, "_cache"):
|
| 127 |
+
return
|
| 128 |
+
if key is None:
|
| 129 |
+
self._cache.clear()
|
| 130 |
+
else:
|
| 131 |
+
self._cache.pop(key, None)
|
| 132 |
+
|
| 133 |
+
def __sizeof__(self) -> int:
|
| 134 |
+
"""
|
| 135 |
+
Generates the total memory usage for an object that returns
|
| 136 |
+
either a value or Series of values
|
| 137 |
+
"""
|
| 138 |
+
memory_usage = getattr(self, "memory_usage", None)
|
| 139 |
+
if memory_usage:
|
| 140 |
+
mem = memory_usage(deep=True) # pylint: disable=not-callable
|
| 141 |
+
return int(mem if is_scalar(mem) else mem.sum())
|
| 142 |
+
|
| 143 |
+
# no memory_usage attribute, so fall back to object's 'sizeof'
|
| 144 |
+
return super().__sizeof__()
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
class NoNewAttributesMixin:
|
| 148 |
+
"""
|
| 149 |
+
Mixin which prevents adding new attributes.
|
| 150 |
+
|
| 151 |
+
Prevents additional attributes via xxx.attribute = "something" after a
|
| 152 |
+
call to `self.__freeze()`. Mainly used to prevent the user from using
|
| 153 |
+
wrong attributes on an accessor (`Series.cat/.str/.dt`).
|
| 154 |
+
|
| 155 |
+
If you really want to add a new attribute at a later time, you need to use
|
| 156 |
+
`object.__setattr__(self, key, value)`.
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
def _freeze(self) -> None:
|
| 160 |
+
"""
|
| 161 |
+
Prevents setting additional attributes.
|
| 162 |
+
"""
|
| 163 |
+
object.__setattr__(self, "__frozen", True)
|
| 164 |
+
|
| 165 |
+
# prevent adding any attribute via s.xxx.new_attribute = ...
|
| 166 |
+
def __setattr__(self, key: str, value) -> None:
|
| 167 |
+
# _cache is used by a decorator
|
| 168 |
+
# We need to check both 1.) cls.__dict__ and 2.) getattr(self, key)
|
| 169 |
+
# because
|
| 170 |
+
# 1.) getattr is false for attributes that raise errors
|
| 171 |
+
# 2.) cls.__dict__ doesn't traverse into base classes
|
| 172 |
+
if getattr(self, "__frozen", False) and not (
|
| 173 |
+
key == "_cache"
|
| 174 |
+
or key in type(self).__dict__
|
| 175 |
+
or getattr(self, key, None) is not None
|
| 176 |
+
):
|
| 177 |
+
raise AttributeError(f"You cannot add any new attribute '{key}'")
|
| 178 |
+
object.__setattr__(self, key, value)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class SelectionMixin(Generic[NDFrameT]):
|
| 182 |
+
"""
|
| 183 |
+
mixin implementing the selection & aggregation interface on a group-like
|
| 184 |
+
object sub-classes need to define: obj, exclusions
|
| 185 |
+
"""
|
| 186 |
+
|
| 187 |
+
obj: NDFrameT
|
| 188 |
+
_selection: IndexLabel | None = None
|
| 189 |
+
exclusions: frozenset[Hashable]
|
| 190 |
+
_internal_names = ["_cache", "__setstate__"]
|
| 191 |
+
_internal_names_set = set(_internal_names)
|
| 192 |
+
|
| 193 |
+
@final
|
| 194 |
+
@property
|
| 195 |
+
def _selection_list(self):
|
| 196 |
+
if not isinstance(
|
| 197 |
+
self._selection, (list, tuple, ABCSeries, ABCIndex, np.ndarray)
|
| 198 |
+
):
|
| 199 |
+
return [self._selection]
|
| 200 |
+
return self._selection
|
| 201 |
+
|
| 202 |
+
@cache_readonly
|
| 203 |
+
def _selected_obj(self):
|
| 204 |
+
if self._selection is None or isinstance(self.obj, ABCSeries):
|
| 205 |
+
return self.obj
|
| 206 |
+
else:
|
| 207 |
+
return self.obj[self._selection]
|
| 208 |
+
|
| 209 |
+
@final
|
| 210 |
+
@cache_readonly
|
| 211 |
+
def ndim(self) -> int:
|
| 212 |
+
return self._selected_obj.ndim
|
| 213 |
+
|
| 214 |
+
@final
|
| 215 |
+
@cache_readonly
|
| 216 |
+
def _obj_with_exclusions(self):
|
| 217 |
+
if isinstance(self.obj, ABCSeries):
|
| 218 |
+
return self.obj
|
| 219 |
+
|
| 220 |
+
if self._selection is not None:
|
| 221 |
+
return self.obj._getitem_nocopy(self._selection_list)
|
| 222 |
+
|
| 223 |
+
if len(self.exclusions) > 0:
|
| 224 |
+
# equivalent to `self.obj.drop(self.exclusions, axis=1)
|
| 225 |
+
# but this avoids consolidating and making a copy
|
| 226 |
+
# TODO: following GH#45287 can we now use .drop directly without
|
| 227 |
+
# making a copy?
|
| 228 |
+
return self.obj._drop_axis(self.exclusions, axis=1, only_slice=True)
|
| 229 |
+
else:
|
| 230 |
+
return self.obj
|
| 231 |
+
|
| 232 |
+
def __getitem__(self, key):
|
| 233 |
+
if self._selection is not None:
|
| 234 |
+
raise IndexError(f"Column(s) {self._selection} already selected")
|
| 235 |
+
|
| 236 |
+
if isinstance(key, (list, tuple, ABCSeries, ABCIndex, np.ndarray)):
|
| 237 |
+
if len(self.obj.columns.intersection(key)) != len(set(key)):
|
| 238 |
+
bad_keys = list(set(key).difference(self.obj.columns))
|
| 239 |
+
raise KeyError(f"Columns not found: {str(bad_keys)[1:-1]}")
|
| 240 |
+
return self._gotitem(list(key), ndim=2)
|
| 241 |
+
|
| 242 |
+
else:
|
| 243 |
+
if key not in self.obj:
|
| 244 |
+
raise KeyError(f"Column not found: {key}")
|
| 245 |
+
ndim = self.obj[key].ndim
|
| 246 |
+
return self._gotitem(key, ndim=ndim)
|
| 247 |
+
|
| 248 |
+
def _gotitem(self, key, ndim: int, subset=None):
|
| 249 |
+
"""
|
| 250 |
+
sub-classes to define
|
| 251 |
+
return a sliced object
|
| 252 |
+
|
| 253 |
+
Parameters
|
| 254 |
+
----------
|
| 255 |
+
key : str / list of selections
|
| 256 |
+
ndim : {1, 2}
|
| 257 |
+
requested ndim of result
|
| 258 |
+
subset : object, default None
|
| 259 |
+
subset to act on
|
| 260 |
+
"""
|
| 261 |
+
raise AbstractMethodError(self)
|
| 262 |
+
|
| 263 |
+
@final
|
| 264 |
+
def _infer_selection(self, key, subset: Series | DataFrame):
|
| 265 |
+
"""
|
| 266 |
+
Infer the `selection` to pass to our constructor in _gotitem.
|
| 267 |
+
"""
|
| 268 |
+
# Shared by Rolling and Resample
|
| 269 |
+
selection = None
|
| 270 |
+
if subset.ndim == 2 and (
|
| 271 |
+
(lib.is_scalar(key) and key in subset) or lib.is_list_like(key)
|
| 272 |
+
):
|
| 273 |
+
selection = key
|
| 274 |
+
elif subset.ndim == 1 and lib.is_scalar(key) and key == subset.name:
|
| 275 |
+
selection = key
|
| 276 |
+
return selection
|
| 277 |
+
|
| 278 |
+
def aggregate(self, func, *args, **kwargs):
|
| 279 |
+
raise AbstractMethodError(self)
|
| 280 |
+
|
| 281 |
+
agg = aggregate
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
class IndexOpsMixin(OpsMixin):
|
| 285 |
+
"""
|
| 286 |
+
Common ops mixin to support a unified interface / docs for Series / Index
|
| 287 |
+
"""
|
| 288 |
+
|
| 289 |
+
# ndarray compatibility
|
| 290 |
+
__array_priority__ = 1000
|
| 291 |
+
_hidden_attrs: frozenset[str] = frozenset(
|
| 292 |
+
["tolist"] # tolist is not deprecated, just suppressed in the __dir__
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
@property
|
| 296 |
+
def dtype(self) -> DtypeObj:
|
| 297 |
+
# must be defined here as a property for mypy
|
| 298 |
+
raise AbstractMethodError(self)
|
| 299 |
+
|
| 300 |
+
@property
|
| 301 |
+
def _values(self) -> ExtensionArray | np.ndarray:
|
| 302 |
+
# must be defined here as a property for mypy
|
| 303 |
+
raise AbstractMethodError(self)
|
| 304 |
+
|
| 305 |
+
@final
|
| 306 |
+
def transpose(self, *args, **kwargs) -> Self:
|
| 307 |
+
"""
|
| 308 |
+
Return the transpose, which is by definition self.
|
| 309 |
+
|
| 310 |
+
Returns
|
| 311 |
+
-------
|
| 312 |
+
%(klass)s
|
| 313 |
+
"""
|
| 314 |
+
nv.validate_transpose(args, kwargs)
|
| 315 |
+
return self
|
| 316 |
+
|
| 317 |
+
T = property(
|
| 318 |
+
transpose,
|
| 319 |
+
doc="""
|
| 320 |
+
Return the transpose, which is by definition self.
|
| 321 |
+
|
| 322 |
+
Examples
|
| 323 |
+
--------
|
| 324 |
+
For Series:
|
| 325 |
+
|
| 326 |
+
>>> s = pd.Series(['Ant', 'Bear', 'Cow'])
|
| 327 |
+
>>> s
|
| 328 |
+
0 Ant
|
| 329 |
+
1 Bear
|
| 330 |
+
2 Cow
|
| 331 |
+
dtype: object
|
| 332 |
+
>>> s.T
|
| 333 |
+
0 Ant
|
| 334 |
+
1 Bear
|
| 335 |
+
2 Cow
|
| 336 |
+
dtype: object
|
| 337 |
+
|
| 338 |
+
For Index:
|
| 339 |
+
|
| 340 |
+
>>> idx = pd.Index([1, 2, 3])
|
| 341 |
+
>>> idx.T
|
| 342 |
+
Index([1, 2, 3], dtype='int64')
|
| 343 |
+
""",
|
| 344 |
+
)
|
| 345 |
+
|
| 346 |
+
@property
|
| 347 |
+
def shape(self) -> Shape:
|
| 348 |
+
"""
|
| 349 |
+
Return a tuple of the shape of the underlying data.
|
| 350 |
+
|
| 351 |
+
Examples
|
| 352 |
+
--------
|
| 353 |
+
>>> s = pd.Series([1, 2, 3])
|
| 354 |
+
>>> s.shape
|
| 355 |
+
(3,)
|
| 356 |
+
"""
|
| 357 |
+
return self._values.shape
|
| 358 |
+
|
| 359 |
+
def __len__(self) -> int:
|
| 360 |
+
# We need this defined here for mypy
|
| 361 |
+
raise AbstractMethodError(self)
|
| 362 |
+
|
| 363 |
+
@property
|
| 364 |
+
def ndim(self) -> Literal[1]:
|
| 365 |
+
"""
|
| 366 |
+
Number of dimensions of the underlying data, by definition 1.
|
| 367 |
+
|
| 368 |
+
Examples
|
| 369 |
+
--------
|
| 370 |
+
>>> s = pd.Series(['Ant', 'Bear', 'Cow'])
|
| 371 |
+
>>> s
|
| 372 |
+
0 Ant
|
| 373 |
+
1 Bear
|
| 374 |
+
2 Cow
|
| 375 |
+
dtype: object
|
| 376 |
+
>>> s.ndim
|
| 377 |
+
1
|
| 378 |
+
|
| 379 |
+
For Index:
|
| 380 |
+
|
| 381 |
+
>>> idx = pd.Index([1, 2, 3])
|
| 382 |
+
>>> idx
|
| 383 |
+
Index([1, 2, 3], dtype='int64')
|
| 384 |
+
>>> idx.ndim
|
| 385 |
+
1
|
| 386 |
+
"""
|
| 387 |
+
return 1
|
| 388 |
+
|
| 389 |
+
@final
|
| 390 |
+
def item(self):
|
| 391 |
+
"""
|
| 392 |
+
Return the first element of the underlying data as a Python scalar.
|
| 393 |
+
|
| 394 |
+
Returns
|
| 395 |
+
-------
|
| 396 |
+
scalar
|
| 397 |
+
The first element of Series or Index.
|
| 398 |
+
|
| 399 |
+
Raises
|
| 400 |
+
------
|
| 401 |
+
ValueError
|
| 402 |
+
If the data is not length = 1.
|
| 403 |
+
|
| 404 |
+
Examples
|
| 405 |
+
--------
|
| 406 |
+
>>> s = pd.Series([1])
|
| 407 |
+
>>> s.item()
|
| 408 |
+
1
|
| 409 |
+
|
| 410 |
+
For an index:
|
| 411 |
+
|
| 412 |
+
>>> s = pd.Series([1], index=['a'])
|
| 413 |
+
>>> s.index.item()
|
| 414 |
+
'a'
|
| 415 |
+
"""
|
| 416 |
+
if len(self) == 1:
|
| 417 |
+
return next(iter(self))
|
| 418 |
+
raise ValueError("can only convert an array of size 1 to a Python scalar")
|
| 419 |
+
|
| 420 |
+
@property
|
| 421 |
+
def nbytes(self) -> int:
|
| 422 |
+
"""
|
| 423 |
+
Return the number of bytes in the underlying data.
|
| 424 |
+
|
| 425 |
+
Examples
|
| 426 |
+
--------
|
| 427 |
+
For Series:
|
| 428 |
+
|
| 429 |
+
>>> s = pd.Series(['Ant', 'Bear', 'Cow'])
|
| 430 |
+
>>> s
|
| 431 |
+
0 Ant
|
| 432 |
+
1 Bear
|
| 433 |
+
2 Cow
|
| 434 |
+
dtype: object
|
| 435 |
+
>>> s.nbytes
|
| 436 |
+
24
|
| 437 |
+
|
| 438 |
+
For Index:
|
| 439 |
+
|
| 440 |
+
>>> idx = pd.Index([1, 2, 3])
|
| 441 |
+
>>> idx
|
| 442 |
+
Index([1, 2, 3], dtype='int64')
|
| 443 |
+
>>> idx.nbytes
|
| 444 |
+
24
|
| 445 |
+
"""
|
| 446 |
+
return self._values.nbytes
|
| 447 |
+
|
| 448 |
+
@property
|
| 449 |
+
def size(self) -> int:
|
| 450 |
+
"""
|
| 451 |
+
Return the number of elements in the underlying data.
|
| 452 |
+
|
| 453 |
+
Examples
|
| 454 |
+
--------
|
| 455 |
+
For Series:
|
| 456 |
+
|
| 457 |
+
>>> s = pd.Series(['Ant', 'Bear', 'Cow'])
|
| 458 |
+
>>> s
|
| 459 |
+
0 Ant
|
| 460 |
+
1 Bear
|
| 461 |
+
2 Cow
|
| 462 |
+
dtype: object
|
| 463 |
+
>>> s.size
|
| 464 |
+
3
|
| 465 |
+
|
| 466 |
+
For Index:
|
| 467 |
+
|
| 468 |
+
>>> idx = pd.Index([1, 2, 3])
|
| 469 |
+
>>> idx
|
| 470 |
+
Index([1, 2, 3], dtype='int64')
|
| 471 |
+
>>> idx.size
|
| 472 |
+
3
|
| 473 |
+
"""
|
| 474 |
+
return len(self._values)
|
| 475 |
+
|
| 476 |
+
@property
|
| 477 |
+
def array(self) -> ExtensionArray:
|
| 478 |
+
"""
|
| 479 |
+
The ExtensionArray of the data backing this Series or Index.
|
| 480 |
+
|
| 481 |
+
Returns
|
| 482 |
+
-------
|
| 483 |
+
ExtensionArray
|
| 484 |
+
An ExtensionArray of the values stored within. For extension
|
| 485 |
+
types, this is the actual array. For NumPy native types, this
|
| 486 |
+
is a thin (no copy) wrapper around :class:`numpy.ndarray`.
|
| 487 |
+
|
| 488 |
+
``.array`` differs from ``.values``, which may require converting
|
| 489 |
+
the data to a different form.
|
| 490 |
+
|
| 491 |
+
See Also
|
| 492 |
+
--------
|
| 493 |
+
Index.to_numpy : Similar method that always returns a NumPy array.
|
| 494 |
+
Series.to_numpy : Similar method that always returns a NumPy array.
|
| 495 |
+
|
| 496 |
+
Notes
|
| 497 |
+
-----
|
| 498 |
+
This table lays out the different array types for each extension
|
| 499 |
+
dtype within pandas.
|
| 500 |
+
|
| 501 |
+
================== =============================
|
| 502 |
+
dtype array type
|
| 503 |
+
================== =============================
|
| 504 |
+
category Categorical
|
| 505 |
+
period PeriodArray
|
| 506 |
+
interval IntervalArray
|
| 507 |
+
IntegerNA IntegerArray
|
| 508 |
+
string StringArray
|
| 509 |
+
boolean BooleanArray
|
| 510 |
+
datetime64[ns, tz] DatetimeArray
|
| 511 |
+
================== =============================
|
| 512 |
+
|
| 513 |
+
For any 3rd-party extension types, the array type will be an
|
| 514 |
+
ExtensionArray.
|
| 515 |
+
|
| 516 |
+
For all remaining dtypes ``.array`` will be a
|
| 517 |
+
:class:`arrays.NumpyExtensionArray` wrapping the actual ndarray
|
| 518 |
+
stored within. If you absolutely need a NumPy array (possibly with
|
| 519 |
+
copying / coercing data), then use :meth:`Series.to_numpy` instead.
|
| 520 |
+
|
| 521 |
+
Examples
|
| 522 |
+
--------
|
| 523 |
+
For regular NumPy types like int, and float, a NumpyExtensionArray
|
| 524 |
+
is returned.
|
| 525 |
+
|
| 526 |
+
>>> pd.Series([1, 2, 3]).array
|
| 527 |
+
<NumpyExtensionArray>
|
| 528 |
+
[1, 2, 3]
|
| 529 |
+
Length: 3, dtype: int64
|
| 530 |
+
|
| 531 |
+
For extension types, like Categorical, the actual ExtensionArray
|
| 532 |
+
is returned
|
| 533 |
+
|
| 534 |
+
>>> ser = pd.Series(pd.Categorical(['a', 'b', 'a']))
|
| 535 |
+
>>> ser.array
|
| 536 |
+
['a', 'b', 'a']
|
| 537 |
+
Categories (2, object): ['a', 'b']
|
| 538 |
+
"""
|
| 539 |
+
raise AbstractMethodError(self)
|
| 540 |
+
|
| 541 |
+
@final
|
| 542 |
+
def to_numpy(
|
| 543 |
+
self,
|
| 544 |
+
dtype: npt.DTypeLike | None = None,
|
| 545 |
+
copy: bool = False,
|
| 546 |
+
na_value: object = lib.no_default,
|
| 547 |
+
**kwargs,
|
| 548 |
+
) -> np.ndarray:
|
| 549 |
+
"""
|
| 550 |
+
A NumPy ndarray representing the values in this Series or Index.
|
| 551 |
+
|
| 552 |
+
Parameters
|
| 553 |
+
----------
|
| 554 |
+
dtype : str or numpy.dtype, optional
|
| 555 |
+
The dtype to pass to :meth:`numpy.asarray`.
|
| 556 |
+
copy : bool, default False
|
| 557 |
+
Whether to ensure that the returned value is not a view on
|
| 558 |
+
another array. Note that ``copy=False`` does not *ensure* that
|
| 559 |
+
``to_numpy()`` is no-copy. Rather, ``copy=True`` ensure that
|
| 560 |
+
a copy is made, even if not strictly necessary.
|
| 561 |
+
na_value : Any, optional
|
| 562 |
+
The value to use for missing values. The default value depends
|
| 563 |
+
on `dtype` and the type of the array.
|
| 564 |
+
**kwargs
|
| 565 |
+
Additional keywords passed through to the ``to_numpy`` method
|
| 566 |
+
of the underlying array (for extension arrays).
|
| 567 |
+
|
| 568 |
+
Returns
|
| 569 |
+
-------
|
| 570 |
+
numpy.ndarray
|
| 571 |
+
|
| 572 |
+
See Also
|
| 573 |
+
--------
|
| 574 |
+
Series.array : Get the actual data stored within.
|
| 575 |
+
Index.array : Get the actual data stored within.
|
| 576 |
+
DataFrame.to_numpy : Similar method for DataFrame.
|
| 577 |
+
|
| 578 |
+
Notes
|
| 579 |
+
-----
|
| 580 |
+
The returned array will be the same up to equality (values equal
|
| 581 |
+
in `self` will be equal in the returned array; likewise for values
|
| 582 |
+
that are not equal). When `self` contains an ExtensionArray, the
|
| 583 |
+
dtype may be different. For example, for a category-dtype Series,
|
| 584 |
+
``to_numpy()`` will return a NumPy array and the categorical dtype
|
| 585 |
+
will be lost.
|
| 586 |
+
|
| 587 |
+
For NumPy dtypes, this will be a reference to the actual data stored
|
| 588 |
+
in this Series or Index (assuming ``copy=False``). Modifying the result
|
| 589 |
+
in place will modify the data stored in the Series or Index (not that
|
| 590 |
+
we recommend doing that).
|
| 591 |
+
|
| 592 |
+
For extension types, ``to_numpy()`` *may* require copying data and
|
| 593 |
+
coercing the result to a NumPy type (possibly object), which may be
|
| 594 |
+
expensive. When you need a no-copy reference to the underlying data,
|
| 595 |
+
:attr:`Series.array` should be used instead.
|
| 596 |
+
|
| 597 |
+
This table lays out the different dtypes and default return types of
|
| 598 |
+
``to_numpy()`` for various dtypes within pandas.
|
| 599 |
+
|
| 600 |
+
================== ================================
|
| 601 |
+
dtype array type
|
| 602 |
+
================== ================================
|
| 603 |
+
category[T] ndarray[T] (same dtype as input)
|
| 604 |
+
period ndarray[object] (Periods)
|
| 605 |
+
interval ndarray[object] (Intervals)
|
| 606 |
+
IntegerNA ndarray[object]
|
| 607 |
+
datetime64[ns] datetime64[ns]
|
| 608 |
+
datetime64[ns, tz] ndarray[object] (Timestamps)
|
| 609 |
+
================== ================================
|
| 610 |
+
|
| 611 |
+
Examples
|
| 612 |
+
--------
|
| 613 |
+
>>> ser = pd.Series(pd.Categorical(['a', 'b', 'a']))
|
| 614 |
+
>>> ser.to_numpy()
|
| 615 |
+
array(['a', 'b', 'a'], dtype=object)
|
| 616 |
+
|
| 617 |
+
Specify the `dtype` to control how datetime-aware data is represented.
|
| 618 |
+
Use ``dtype=object`` to return an ndarray of pandas :class:`Timestamp`
|
| 619 |
+
objects, each with the correct ``tz``.
|
| 620 |
+
|
| 621 |
+
>>> ser = pd.Series(pd.date_range('2000', periods=2, tz="CET"))
|
| 622 |
+
>>> ser.to_numpy(dtype=object)
|
| 623 |
+
array([Timestamp('2000-01-01 00:00:00+0100', tz='CET'),
|
| 624 |
+
Timestamp('2000-01-02 00:00:00+0100', tz='CET')],
|
| 625 |
+
dtype=object)
|
| 626 |
+
|
| 627 |
+
Or ``dtype='datetime64[ns]'`` to return an ndarray of native
|
| 628 |
+
datetime64 values. The values are converted to UTC and the timezone
|
| 629 |
+
info is dropped.
|
| 630 |
+
|
| 631 |
+
>>> ser.to_numpy(dtype="datetime64[ns]")
|
| 632 |
+
... # doctest: +ELLIPSIS
|
| 633 |
+
array(['1999-12-31T23:00:00.000000000', '2000-01-01T23:00:00...'],
|
| 634 |
+
dtype='datetime64[ns]')
|
| 635 |
+
"""
|
| 636 |
+
if isinstance(self.dtype, ExtensionDtype):
|
| 637 |
+
return self.array.to_numpy(dtype, copy=copy, na_value=na_value, **kwargs)
|
| 638 |
+
elif kwargs:
|
| 639 |
+
bad_keys = next(iter(kwargs.keys()))
|
| 640 |
+
raise TypeError(
|
| 641 |
+
f"to_numpy() got an unexpected keyword argument '{bad_keys}'"
|
| 642 |
+
)
|
| 643 |
+
|
| 644 |
+
fillna = (
|
| 645 |
+
na_value is not lib.no_default
|
| 646 |
+
# no need to fillna with np.nan if we already have a float dtype
|
| 647 |
+
and not (na_value is np.nan and np.issubdtype(self.dtype, np.floating))
|
| 648 |
+
)
|
| 649 |
+
|
| 650 |
+
values = self._values
|
| 651 |
+
if fillna:
|
| 652 |
+
if not can_hold_element(values, na_value):
|
| 653 |
+
# if we can't hold the na_value asarray either makes a copy or we
|
| 654 |
+
# error before modifying values. The asarray later on thus won't make
|
| 655 |
+
# another copy
|
| 656 |
+
values = np.asarray(values, dtype=dtype)
|
| 657 |
+
else:
|
| 658 |
+
values = values.copy()
|
| 659 |
+
|
| 660 |
+
values[np.asanyarray(isna(self))] = na_value
|
| 661 |
+
|
| 662 |
+
result = np.asarray(values, dtype=dtype)
|
| 663 |
+
|
| 664 |
+
if (copy and not fillna) or (not copy and using_copy_on_write()):
|
| 665 |
+
if np.shares_memory(self._values[:2], result[:2]):
|
| 666 |
+
# Take slices to improve performance of check
|
| 667 |
+
if using_copy_on_write() and not copy:
|
| 668 |
+
result = result.view()
|
| 669 |
+
result.flags.writeable = False
|
| 670 |
+
else:
|
| 671 |
+
result = result.copy()
|
| 672 |
+
|
| 673 |
+
return result
|
| 674 |
+
|
| 675 |
+
@final
|
| 676 |
+
@property
|
| 677 |
+
def empty(self) -> bool:
|
| 678 |
+
return not self.size
|
| 679 |
+
|
| 680 |
+
@doc(op="max", oppose="min", value="largest")
|
| 681 |
+
def argmax(
|
| 682 |
+
self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs
|
| 683 |
+
) -> int:
|
| 684 |
+
"""
|
| 685 |
+
Return int position of the {value} value in the Series.
|
| 686 |
+
|
| 687 |
+
If the {op}imum is achieved in multiple locations,
|
| 688 |
+
the first row position is returned.
|
| 689 |
+
|
| 690 |
+
Parameters
|
| 691 |
+
----------
|
| 692 |
+
axis : {{None}}
|
| 693 |
+
Unused. Parameter needed for compatibility with DataFrame.
|
| 694 |
+
skipna : bool, default True
|
| 695 |
+
Exclude NA/null values when showing the result.
|
| 696 |
+
*args, **kwargs
|
| 697 |
+
Additional arguments and keywords for compatibility with NumPy.
|
| 698 |
+
|
| 699 |
+
Returns
|
| 700 |
+
-------
|
| 701 |
+
int
|
| 702 |
+
Row position of the {op}imum value.
|
| 703 |
+
|
| 704 |
+
See Also
|
| 705 |
+
--------
|
| 706 |
+
Series.arg{op} : Return position of the {op}imum value.
|
| 707 |
+
Series.arg{oppose} : Return position of the {oppose}imum value.
|
| 708 |
+
numpy.ndarray.arg{op} : Equivalent method for numpy arrays.
|
| 709 |
+
Series.idxmax : Return index label of the maximum values.
|
| 710 |
+
Series.idxmin : Return index label of the minimum values.
|
| 711 |
+
|
| 712 |
+
Examples
|
| 713 |
+
--------
|
| 714 |
+
Consider dataset containing cereal calories
|
| 715 |
+
|
| 716 |
+
>>> s = pd.Series({{'Corn Flakes': 100.0, 'Almond Delight': 110.0,
|
| 717 |
+
... 'Cinnamon Toast Crunch': 120.0, 'Cocoa Puff': 110.0}})
|
| 718 |
+
>>> s
|
| 719 |
+
Corn Flakes 100.0
|
| 720 |
+
Almond Delight 110.0
|
| 721 |
+
Cinnamon Toast Crunch 120.0
|
| 722 |
+
Cocoa Puff 110.0
|
| 723 |
+
dtype: float64
|
| 724 |
+
|
| 725 |
+
>>> s.argmax()
|
| 726 |
+
2
|
| 727 |
+
>>> s.argmin()
|
| 728 |
+
0
|
| 729 |
+
|
| 730 |
+
The maximum cereal calories is the third element and
|
| 731 |
+
the minimum cereal calories is the first element,
|
| 732 |
+
since series is zero-indexed.
|
| 733 |
+
"""
|
| 734 |
+
delegate = self._values
|
| 735 |
+
nv.validate_minmax_axis(axis)
|
| 736 |
+
skipna = nv.validate_argmax_with_skipna(skipna, args, kwargs)
|
| 737 |
+
|
| 738 |
+
if isinstance(delegate, ExtensionArray):
|
| 739 |
+
if not skipna and delegate.isna().any():
|
| 740 |
+
warnings.warn(
|
| 741 |
+
f"The behavior of {type(self).__name__}.argmax/argmin "
|
| 742 |
+
"with skipna=False and NAs, or with all-NAs is deprecated. "
|
| 743 |
+
"In a future version this will raise ValueError.",
|
| 744 |
+
FutureWarning,
|
| 745 |
+
stacklevel=find_stack_level(),
|
| 746 |
+
)
|
| 747 |
+
return -1
|
| 748 |
+
else:
|
| 749 |
+
return delegate.argmax()
|
| 750 |
+
else:
|
| 751 |
+
result = nanops.nanargmax(delegate, skipna=skipna)
|
| 752 |
+
if result == -1:
|
| 753 |
+
warnings.warn(
|
| 754 |
+
f"The behavior of {type(self).__name__}.argmax/argmin "
|
| 755 |
+
"with skipna=False and NAs, or with all-NAs is deprecated. "
|
| 756 |
+
"In a future version this will raise ValueError.",
|
| 757 |
+
FutureWarning,
|
| 758 |
+
stacklevel=find_stack_level(),
|
| 759 |
+
)
|
| 760 |
+
# error: Incompatible return value type (got "Union[int, ndarray]", expected
|
| 761 |
+
# "int")
|
| 762 |
+
return result # type: ignore[return-value]
|
| 763 |
+
|
| 764 |
+
@doc(argmax, op="min", oppose="max", value="smallest")
|
| 765 |
+
def argmin(
|
| 766 |
+
self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs
|
| 767 |
+
) -> int:
|
| 768 |
+
delegate = self._values
|
| 769 |
+
nv.validate_minmax_axis(axis)
|
| 770 |
+
skipna = nv.validate_argmin_with_skipna(skipna, args, kwargs)
|
| 771 |
+
|
| 772 |
+
if isinstance(delegate, ExtensionArray):
|
| 773 |
+
if not skipna and delegate.isna().any():
|
| 774 |
+
warnings.warn(
|
| 775 |
+
f"The behavior of {type(self).__name__}.argmax/argmin "
|
| 776 |
+
"with skipna=False and NAs, or with all-NAs is deprecated. "
|
| 777 |
+
"In a future version this will raise ValueError.",
|
| 778 |
+
FutureWarning,
|
| 779 |
+
stacklevel=find_stack_level(),
|
| 780 |
+
)
|
| 781 |
+
return -1
|
| 782 |
+
else:
|
| 783 |
+
return delegate.argmin()
|
| 784 |
+
else:
|
| 785 |
+
result = nanops.nanargmin(delegate, skipna=skipna)
|
| 786 |
+
if result == -1:
|
| 787 |
+
warnings.warn(
|
| 788 |
+
f"The behavior of {type(self).__name__}.argmax/argmin "
|
| 789 |
+
"with skipna=False and NAs, or with all-NAs is deprecated. "
|
| 790 |
+
"In a future version this will raise ValueError.",
|
| 791 |
+
FutureWarning,
|
| 792 |
+
stacklevel=find_stack_level(),
|
| 793 |
+
)
|
| 794 |
+
# error: Incompatible return value type (got "Union[int, ndarray]", expected
|
| 795 |
+
# "int")
|
| 796 |
+
return result # type: ignore[return-value]
|
| 797 |
+
|
| 798 |
+
def tolist(self):
|
| 799 |
+
"""
|
| 800 |
+
Return a list of the values.
|
| 801 |
+
|
| 802 |
+
These are each a scalar type, which is a Python scalar
|
| 803 |
+
(for str, int, float) or a pandas scalar
|
| 804 |
+
(for Timestamp/Timedelta/Interval/Period)
|
| 805 |
+
|
| 806 |
+
Returns
|
| 807 |
+
-------
|
| 808 |
+
list
|
| 809 |
+
|
| 810 |
+
See Also
|
| 811 |
+
--------
|
| 812 |
+
numpy.ndarray.tolist : Return the array as an a.ndim-levels deep
|
| 813 |
+
nested list of Python scalars.
|
| 814 |
+
|
| 815 |
+
Examples
|
| 816 |
+
--------
|
| 817 |
+
For Series
|
| 818 |
+
|
| 819 |
+
>>> s = pd.Series([1, 2, 3])
|
| 820 |
+
>>> s.to_list()
|
| 821 |
+
[1, 2, 3]
|
| 822 |
+
|
| 823 |
+
For Index:
|
| 824 |
+
|
| 825 |
+
>>> idx = pd.Index([1, 2, 3])
|
| 826 |
+
>>> idx
|
| 827 |
+
Index([1, 2, 3], dtype='int64')
|
| 828 |
+
|
| 829 |
+
>>> idx.to_list()
|
| 830 |
+
[1, 2, 3]
|
| 831 |
+
"""
|
| 832 |
+
return self._values.tolist()
|
| 833 |
+
|
| 834 |
+
to_list = tolist
|
| 835 |
+
|
| 836 |
+
def __iter__(self) -> Iterator:
|
| 837 |
+
"""
|
| 838 |
+
Return an iterator of the values.
|
| 839 |
+
|
| 840 |
+
These are each a scalar type, which is a Python scalar
|
| 841 |
+
(for str, int, float) or a pandas scalar
|
| 842 |
+
(for Timestamp/Timedelta/Interval/Period)
|
| 843 |
+
|
| 844 |
+
Returns
|
| 845 |
+
-------
|
| 846 |
+
iterator
|
| 847 |
+
|
| 848 |
+
Examples
|
| 849 |
+
--------
|
| 850 |
+
>>> s = pd.Series([1, 2, 3])
|
| 851 |
+
>>> for x in s:
|
| 852 |
+
... print(x)
|
| 853 |
+
1
|
| 854 |
+
2
|
| 855 |
+
3
|
| 856 |
+
"""
|
| 857 |
+
# We are explicitly making element iterators.
|
| 858 |
+
if not isinstance(self._values, np.ndarray):
|
| 859 |
+
# Check type instead of dtype to catch DTA/TDA
|
| 860 |
+
return iter(self._values)
|
| 861 |
+
else:
|
| 862 |
+
return map(self._values.item, range(self._values.size))
|
| 863 |
+
|
| 864 |
+
@cache_readonly
|
| 865 |
+
def hasnans(self) -> bool:
|
| 866 |
+
"""
|
| 867 |
+
Return True if there are any NaNs.
|
| 868 |
+
|
| 869 |
+
Enables various performance speedups.
|
| 870 |
+
|
| 871 |
+
Returns
|
| 872 |
+
-------
|
| 873 |
+
bool
|
| 874 |
+
|
| 875 |
+
Examples
|
| 876 |
+
--------
|
| 877 |
+
>>> s = pd.Series([1, 2, 3, None])
|
| 878 |
+
>>> s
|
| 879 |
+
0 1.0
|
| 880 |
+
1 2.0
|
| 881 |
+
2 3.0
|
| 882 |
+
3 NaN
|
| 883 |
+
dtype: float64
|
| 884 |
+
>>> s.hasnans
|
| 885 |
+
True
|
| 886 |
+
"""
|
| 887 |
+
# error: Item "bool" of "Union[bool, ndarray[Any, dtype[bool_]], NDFrame]"
|
| 888 |
+
# has no attribute "any"
|
| 889 |
+
return bool(isna(self).any()) # type: ignore[union-attr]
|
| 890 |
+
|
| 891 |
+
@final
|
| 892 |
+
def _map_values(self, mapper, na_action=None, convert: bool = True):
|
| 893 |
+
"""
|
| 894 |
+
An internal function that maps values using the input
|
| 895 |
+
correspondence (which can be a dict, Series, or function).
|
| 896 |
+
|
| 897 |
+
Parameters
|
| 898 |
+
----------
|
| 899 |
+
mapper : function, dict, or Series
|
| 900 |
+
The input correspondence object
|
| 901 |
+
na_action : {None, 'ignore'}
|
| 902 |
+
If 'ignore', propagate NA values, without passing them to the
|
| 903 |
+
mapping function
|
| 904 |
+
convert : bool, default True
|
| 905 |
+
Try to find better dtype for elementwise function results. If
|
| 906 |
+
False, leave as dtype=object. Note that the dtype is always
|
| 907 |
+
preserved for some extension array dtypes, such as Categorical.
|
| 908 |
+
|
| 909 |
+
Returns
|
| 910 |
+
-------
|
| 911 |
+
Union[Index, MultiIndex], inferred
|
| 912 |
+
The output of the mapping function applied to the index.
|
| 913 |
+
If the function returns a tuple with more than one element
|
| 914 |
+
a MultiIndex will be returned.
|
| 915 |
+
"""
|
| 916 |
+
arr = self._values
|
| 917 |
+
|
| 918 |
+
if isinstance(arr, ExtensionArray):
|
| 919 |
+
return arr.map(mapper, na_action=na_action)
|
| 920 |
+
|
| 921 |
+
return algorithms.map_array(arr, mapper, na_action=na_action, convert=convert)
|
| 922 |
+
|
| 923 |
+
@final
|
| 924 |
+
def value_counts(
|
| 925 |
+
self,
|
| 926 |
+
normalize: bool = False,
|
| 927 |
+
sort: bool = True,
|
| 928 |
+
ascending: bool = False,
|
| 929 |
+
bins=None,
|
| 930 |
+
dropna: bool = True,
|
| 931 |
+
) -> Series:
|
| 932 |
+
"""
|
| 933 |
+
Return a Series containing counts of unique values.
|
| 934 |
+
|
| 935 |
+
The resulting object will be in descending order so that the
|
| 936 |
+
first element is the most frequently-occurring element.
|
| 937 |
+
Excludes NA values by default.
|
| 938 |
+
|
| 939 |
+
Parameters
|
| 940 |
+
----------
|
| 941 |
+
normalize : bool, default False
|
| 942 |
+
If True then the object returned will contain the relative
|
| 943 |
+
frequencies of the unique values.
|
| 944 |
+
sort : bool, default True
|
| 945 |
+
Sort by frequencies when True. Preserve the order of the data when False.
|
| 946 |
+
ascending : bool, default False
|
| 947 |
+
Sort in ascending order.
|
| 948 |
+
bins : int, optional
|
| 949 |
+
Rather than count values, group them into half-open bins,
|
| 950 |
+
a convenience for ``pd.cut``, only works with numeric data.
|
| 951 |
+
dropna : bool, default True
|
| 952 |
+
Don't include counts of NaN.
|
| 953 |
+
|
| 954 |
+
Returns
|
| 955 |
+
-------
|
| 956 |
+
Series
|
| 957 |
+
|
| 958 |
+
See Also
|
| 959 |
+
--------
|
| 960 |
+
Series.count: Number of non-NA elements in a Series.
|
| 961 |
+
DataFrame.count: Number of non-NA elements in a DataFrame.
|
| 962 |
+
DataFrame.value_counts: Equivalent method on DataFrames.
|
| 963 |
+
|
| 964 |
+
Examples
|
| 965 |
+
--------
|
| 966 |
+
>>> index = pd.Index([3, 1, 2, 3, 4, np.nan])
|
| 967 |
+
>>> index.value_counts()
|
| 968 |
+
3.0 2
|
| 969 |
+
1.0 1
|
| 970 |
+
2.0 1
|
| 971 |
+
4.0 1
|
| 972 |
+
Name: count, dtype: int64
|
| 973 |
+
|
| 974 |
+
With `normalize` set to `True`, returns the relative frequency by
|
| 975 |
+
dividing all values by the sum of values.
|
| 976 |
+
|
| 977 |
+
>>> s = pd.Series([3, 1, 2, 3, 4, np.nan])
|
| 978 |
+
>>> s.value_counts(normalize=True)
|
| 979 |
+
3.0 0.4
|
| 980 |
+
1.0 0.2
|
| 981 |
+
2.0 0.2
|
| 982 |
+
4.0 0.2
|
| 983 |
+
Name: proportion, dtype: float64
|
| 984 |
+
|
| 985 |
+
**bins**
|
| 986 |
+
|
| 987 |
+
Bins can be useful for going from a continuous variable to a
|
| 988 |
+
categorical variable; instead of counting unique
|
| 989 |
+
apparitions of values, divide the index in the specified
|
| 990 |
+
number of half-open bins.
|
| 991 |
+
|
| 992 |
+
>>> s.value_counts(bins=3)
|
| 993 |
+
(0.996, 2.0] 2
|
| 994 |
+
(2.0, 3.0] 2
|
| 995 |
+
(3.0, 4.0] 1
|
| 996 |
+
Name: count, dtype: int64
|
| 997 |
+
|
| 998 |
+
**dropna**
|
| 999 |
+
|
| 1000 |
+
With `dropna` set to `False` we can also see NaN index values.
|
| 1001 |
+
|
| 1002 |
+
>>> s.value_counts(dropna=False)
|
| 1003 |
+
3.0 2
|
| 1004 |
+
1.0 1
|
| 1005 |
+
2.0 1
|
| 1006 |
+
4.0 1
|
| 1007 |
+
NaN 1
|
| 1008 |
+
Name: count, dtype: int64
|
| 1009 |
+
"""
|
| 1010 |
+
return algorithms.value_counts_internal(
|
| 1011 |
+
self,
|
| 1012 |
+
sort=sort,
|
| 1013 |
+
ascending=ascending,
|
| 1014 |
+
normalize=normalize,
|
| 1015 |
+
bins=bins,
|
| 1016 |
+
dropna=dropna,
|
| 1017 |
+
)
|
| 1018 |
+
|
| 1019 |
+
def unique(self):
|
| 1020 |
+
values = self._values
|
| 1021 |
+
if not isinstance(values, np.ndarray):
|
| 1022 |
+
# i.e. ExtensionArray
|
| 1023 |
+
result = values.unique()
|
| 1024 |
+
else:
|
| 1025 |
+
result = algorithms.unique1d(values)
|
| 1026 |
+
return result
|
| 1027 |
+
|
| 1028 |
+
@final
|
| 1029 |
+
def nunique(self, dropna: bool = True) -> int:
|
| 1030 |
+
"""
|
| 1031 |
+
Return number of unique elements in the object.
|
| 1032 |
+
|
| 1033 |
+
Excludes NA values by default.
|
| 1034 |
+
|
| 1035 |
+
Parameters
|
| 1036 |
+
----------
|
| 1037 |
+
dropna : bool, default True
|
| 1038 |
+
Don't include NaN in the count.
|
| 1039 |
+
|
| 1040 |
+
Returns
|
| 1041 |
+
-------
|
| 1042 |
+
int
|
| 1043 |
+
|
| 1044 |
+
See Also
|
| 1045 |
+
--------
|
| 1046 |
+
DataFrame.nunique: Method nunique for DataFrame.
|
| 1047 |
+
Series.count: Count non-NA/null observations in the Series.
|
| 1048 |
+
|
| 1049 |
+
Examples
|
| 1050 |
+
--------
|
| 1051 |
+
>>> s = pd.Series([1, 3, 5, 7, 7])
|
| 1052 |
+
>>> s
|
| 1053 |
+
0 1
|
| 1054 |
+
1 3
|
| 1055 |
+
2 5
|
| 1056 |
+
3 7
|
| 1057 |
+
4 7
|
| 1058 |
+
dtype: int64
|
| 1059 |
+
|
| 1060 |
+
>>> s.nunique()
|
| 1061 |
+
4
|
| 1062 |
+
"""
|
| 1063 |
+
uniqs = self.unique()
|
| 1064 |
+
if dropna:
|
| 1065 |
+
uniqs = remove_na_arraylike(uniqs)
|
| 1066 |
+
return len(uniqs)
|
| 1067 |
+
|
| 1068 |
+
@property
|
| 1069 |
+
def is_unique(self) -> bool:
|
| 1070 |
+
"""
|
| 1071 |
+
Return boolean if values in the object are unique.
|
| 1072 |
+
|
| 1073 |
+
Returns
|
| 1074 |
+
-------
|
| 1075 |
+
bool
|
| 1076 |
+
|
| 1077 |
+
Examples
|
| 1078 |
+
--------
|
| 1079 |
+
>>> s = pd.Series([1, 2, 3])
|
| 1080 |
+
>>> s.is_unique
|
| 1081 |
+
True
|
| 1082 |
+
|
| 1083 |
+
>>> s = pd.Series([1, 2, 3, 1])
|
| 1084 |
+
>>> s.is_unique
|
| 1085 |
+
False
|
| 1086 |
+
"""
|
| 1087 |
+
return self.nunique(dropna=False) == len(self)
|
| 1088 |
+
|
| 1089 |
+
@property
|
| 1090 |
+
def is_monotonic_increasing(self) -> bool:
|
| 1091 |
+
"""
|
| 1092 |
+
Return boolean if values in the object are monotonically increasing.
|
| 1093 |
+
|
| 1094 |
+
Returns
|
| 1095 |
+
-------
|
| 1096 |
+
bool
|
| 1097 |
+
|
| 1098 |
+
Examples
|
| 1099 |
+
--------
|
| 1100 |
+
>>> s = pd.Series([1, 2, 2])
|
| 1101 |
+
>>> s.is_monotonic_increasing
|
| 1102 |
+
True
|
| 1103 |
+
|
| 1104 |
+
>>> s = pd.Series([3, 2, 1])
|
| 1105 |
+
>>> s.is_monotonic_increasing
|
| 1106 |
+
False
|
| 1107 |
+
"""
|
| 1108 |
+
from pandas import Index
|
| 1109 |
+
|
| 1110 |
+
return Index(self).is_monotonic_increasing
|
| 1111 |
+
|
| 1112 |
+
@property
|
| 1113 |
+
def is_monotonic_decreasing(self) -> bool:
|
| 1114 |
+
"""
|
| 1115 |
+
Return boolean if values in the object are monotonically decreasing.
|
| 1116 |
+
|
| 1117 |
+
Returns
|
| 1118 |
+
-------
|
| 1119 |
+
bool
|
| 1120 |
+
|
| 1121 |
+
Examples
|
| 1122 |
+
--------
|
| 1123 |
+
>>> s = pd.Series([3, 2, 2, 1])
|
| 1124 |
+
>>> s.is_monotonic_decreasing
|
| 1125 |
+
True
|
| 1126 |
+
|
| 1127 |
+
>>> s = pd.Series([1, 2, 3])
|
| 1128 |
+
>>> s.is_monotonic_decreasing
|
| 1129 |
+
False
|
| 1130 |
+
"""
|
| 1131 |
+
from pandas import Index
|
| 1132 |
+
|
| 1133 |
+
return Index(self).is_monotonic_decreasing
|
| 1134 |
+
|
| 1135 |
+
@final
|
| 1136 |
+
def _memory_usage(self, deep: bool = False) -> int:
|
| 1137 |
+
"""
|
| 1138 |
+
Memory usage of the values.
|
| 1139 |
+
|
| 1140 |
+
Parameters
|
| 1141 |
+
----------
|
| 1142 |
+
deep : bool, default False
|
| 1143 |
+
Introspect the data deeply, interrogate
|
| 1144 |
+
`object` dtypes for system-level memory consumption.
|
| 1145 |
+
|
| 1146 |
+
Returns
|
| 1147 |
+
-------
|
| 1148 |
+
bytes used
|
| 1149 |
+
|
| 1150 |
+
See Also
|
| 1151 |
+
--------
|
| 1152 |
+
numpy.ndarray.nbytes : Total bytes consumed by the elements of the
|
| 1153 |
+
array.
|
| 1154 |
+
|
| 1155 |
+
Notes
|
| 1156 |
+
-----
|
| 1157 |
+
Memory usage does not include memory consumed by elements that
|
| 1158 |
+
are not components of the array if deep=False or if used on PyPy
|
| 1159 |
+
|
| 1160 |
+
Examples
|
| 1161 |
+
--------
|
| 1162 |
+
>>> idx = pd.Index([1, 2, 3])
|
| 1163 |
+
>>> idx.memory_usage()
|
| 1164 |
+
24
|
| 1165 |
+
"""
|
| 1166 |
+
if hasattr(self.array, "memory_usage"):
|
| 1167 |
+
return self.array.memory_usage( # pyright: ignore[reportGeneralTypeIssues]
|
| 1168 |
+
deep=deep,
|
| 1169 |
+
)
|
| 1170 |
+
|
| 1171 |
+
v = self.array.nbytes
|
| 1172 |
+
if deep and is_object_dtype(self.dtype) and not PYPY:
|
| 1173 |
+
values = cast(np.ndarray, self._values)
|
| 1174 |
+
v += lib.memory_usage_of_objects(values)
|
| 1175 |
+
return v
|
| 1176 |
+
|
| 1177 |
+
@doc(
|
| 1178 |
+
algorithms.factorize,
|
| 1179 |
+
values="",
|
| 1180 |
+
order="",
|
| 1181 |
+
size_hint="",
|
| 1182 |
+
sort=textwrap.dedent(
|
| 1183 |
+
"""\
|
| 1184 |
+
sort : bool, default False
|
| 1185 |
+
Sort `uniques` and shuffle `codes` to maintain the
|
| 1186 |
+
relationship.
|
| 1187 |
+
"""
|
| 1188 |
+
),
|
| 1189 |
+
)
|
| 1190 |
+
def factorize(
|
| 1191 |
+
self,
|
| 1192 |
+
sort: bool = False,
|
| 1193 |
+
use_na_sentinel: bool = True,
|
| 1194 |
+
) -> tuple[npt.NDArray[np.intp], Index]:
|
| 1195 |
+
codes, uniques = algorithms.factorize(
|
| 1196 |
+
self._values, sort=sort, use_na_sentinel=use_na_sentinel
|
| 1197 |
+
)
|
| 1198 |
+
if uniques.dtype == np.float16:
|
| 1199 |
+
uniques = uniques.astype(np.float32)
|
| 1200 |
+
|
| 1201 |
+
if isinstance(self, ABCIndex):
|
| 1202 |
+
# preserve e.g. MultiIndex
|
| 1203 |
+
uniques = self._constructor(uniques)
|
| 1204 |
+
else:
|
| 1205 |
+
from pandas import Index
|
| 1206 |
+
|
| 1207 |
+
uniques = Index(uniques)
|
| 1208 |
+
return codes, uniques
|
| 1209 |
+
|
| 1210 |
+
_shared_docs[
|
| 1211 |
+
"searchsorted"
|
| 1212 |
+
] = """
|
| 1213 |
+
Find indices where elements should be inserted to maintain order.
|
| 1214 |
+
|
| 1215 |
+
Find the indices into a sorted {klass} `self` such that, if the
|
| 1216 |
+
corresponding elements in `value` were inserted before the indices,
|
| 1217 |
+
the order of `self` would be preserved.
|
| 1218 |
+
|
| 1219 |
+
.. note::
|
| 1220 |
+
|
| 1221 |
+
The {klass} *must* be monotonically sorted, otherwise
|
| 1222 |
+
wrong locations will likely be returned. Pandas does *not*
|
| 1223 |
+
check this for you.
|
| 1224 |
+
|
| 1225 |
+
Parameters
|
| 1226 |
+
----------
|
| 1227 |
+
value : array-like or scalar
|
| 1228 |
+
Values to insert into `self`.
|
| 1229 |
+
side : {{'left', 'right'}}, optional
|
| 1230 |
+
If 'left', the index of the first suitable location found is given.
|
| 1231 |
+
If 'right', return the last such index. If there is no suitable
|
| 1232 |
+
index, return either 0 or N (where N is the length of `self`).
|
| 1233 |
+
sorter : 1-D array-like, optional
|
| 1234 |
+
Optional array of integer indices that sort `self` into ascending
|
| 1235 |
+
order. They are typically the result of ``np.argsort``.
|
| 1236 |
+
|
| 1237 |
+
Returns
|
| 1238 |
+
-------
|
| 1239 |
+
int or array of int
|
| 1240 |
+
A scalar or array of insertion points with the
|
| 1241 |
+
same shape as `value`.
|
| 1242 |
+
|
| 1243 |
+
See Also
|
| 1244 |
+
--------
|
| 1245 |
+
sort_values : Sort by the values along either axis.
|
| 1246 |
+
numpy.searchsorted : Similar method from NumPy.
|
| 1247 |
+
|
| 1248 |
+
Notes
|
| 1249 |
+
-----
|
| 1250 |
+
Binary search is used to find the required insertion points.
|
| 1251 |
+
|
| 1252 |
+
Examples
|
| 1253 |
+
--------
|
| 1254 |
+
>>> ser = pd.Series([1, 2, 3])
|
| 1255 |
+
>>> ser
|
| 1256 |
+
0 1
|
| 1257 |
+
1 2
|
| 1258 |
+
2 3
|
| 1259 |
+
dtype: int64
|
| 1260 |
+
|
| 1261 |
+
>>> ser.searchsorted(4)
|
| 1262 |
+
3
|
| 1263 |
+
|
| 1264 |
+
>>> ser.searchsorted([0, 4])
|
| 1265 |
+
array([0, 3])
|
| 1266 |
+
|
| 1267 |
+
>>> ser.searchsorted([1, 3], side='left')
|
| 1268 |
+
array([0, 2])
|
| 1269 |
+
|
| 1270 |
+
>>> ser.searchsorted([1, 3], side='right')
|
| 1271 |
+
array([1, 3])
|
| 1272 |
+
|
| 1273 |
+
>>> ser = pd.Series(pd.to_datetime(['3/11/2000', '3/12/2000', '3/13/2000']))
|
| 1274 |
+
>>> ser
|
| 1275 |
+
0 2000-03-11
|
| 1276 |
+
1 2000-03-12
|
| 1277 |
+
2 2000-03-13
|
| 1278 |
+
dtype: datetime64[ns]
|
| 1279 |
+
|
| 1280 |
+
>>> ser.searchsorted('3/14/2000')
|
| 1281 |
+
3
|
| 1282 |
+
|
| 1283 |
+
>>> ser = pd.Categorical(
|
| 1284 |
+
... ['apple', 'bread', 'bread', 'cheese', 'milk'], ordered=True
|
| 1285 |
+
... )
|
| 1286 |
+
>>> ser
|
| 1287 |
+
['apple', 'bread', 'bread', 'cheese', 'milk']
|
| 1288 |
+
Categories (4, object): ['apple' < 'bread' < 'cheese' < 'milk']
|
| 1289 |
+
|
| 1290 |
+
>>> ser.searchsorted('bread')
|
| 1291 |
+
1
|
| 1292 |
+
|
| 1293 |
+
>>> ser.searchsorted(['bread'], side='right')
|
| 1294 |
+
array([3])
|
| 1295 |
+
|
| 1296 |
+
If the values are not monotonically sorted, wrong locations
|
| 1297 |
+
may be returned:
|
| 1298 |
+
|
| 1299 |
+
>>> ser = pd.Series([2, 1, 3])
|
| 1300 |
+
>>> ser
|
| 1301 |
+
0 2
|
| 1302 |
+
1 1
|
| 1303 |
+
2 3
|
| 1304 |
+
dtype: int64
|
| 1305 |
+
|
| 1306 |
+
>>> ser.searchsorted(1) # doctest: +SKIP
|
| 1307 |
+
0 # wrong result, correct would be 1
|
| 1308 |
+
"""
|
| 1309 |
+
|
| 1310 |
+
# This overload is needed so that the call to searchsorted in
|
| 1311 |
+
# pandas.core.resample.TimeGrouper._get_period_bins picks the correct result
|
| 1312 |
+
|
| 1313 |
+
# error: Overloaded function signatures 1 and 2 overlap with incompatible
|
| 1314 |
+
# return types
|
| 1315 |
+
@overload
|
| 1316 |
+
def searchsorted( # type: ignore[overload-overlap]
|
| 1317 |
+
self,
|
| 1318 |
+
value: ScalarLike_co,
|
| 1319 |
+
side: Literal["left", "right"] = ...,
|
| 1320 |
+
sorter: NumpySorter = ...,
|
| 1321 |
+
) -> np.intp:
|
| 1322 |
+
...
|
| 1323 |
+
|
| 1324 |
+
@overload
|
| 1325 |
+
def searchsorted(
|
| 1326 |
+
self,
|
| 1327 |
+
value: npt.ArrayLike | ExtensionArray,
|
| 1328 |
+
side: Literal["left", "right"] = ...,
|
| 1329 |
+
sorter: NumpySorter = ...,
|
| 1330 |
+
) -> npt.NDArray[np.intp]:
|
| 1331 |
+
...
|
| 1332 |
+
|
| 1333 |
+
@doc(_shared_docs["searchsorted"], klass="Index")
|
| 1334 |
+
def searchsorted(
|
| 1335 |
+
self,
|
| 1336 |
+
value: NumpyValueArrayLike | ExtensionArray,
|
| 1337 |
+
side: Literal["left", "right"] = "left",
|
| 1338 |
+
sorter: NumpySorter | None = None,
|
| 1339 |
+
) -> npt.NDArray[np.intp] | np.intp:
|
| 1340 |
+
if isinstance(value, ABCDataFrame):
|
| 1341 |
+
msg = (
|
| 1342 |
+
"Value must be 1-D array-like or scalar, "
|
| 1343 |
+
f"{type(value).__name__} is not supported"
|
| 1344 |
+
)
|
| 1345 |
+
raise ValueError(msg)
|
| 1346 |
+
|
| 1347 |
+
values = self._values
|
| 1348 |
+
if not isinstance(values, np.ndarray):
|
| 1349 |
+
# Going through EA.searchsorted directly improves performance GH#38083
|
| 1350 |
+
return values.searchsorted(value, side=side, sorter=sorter)
|
| 1351 |
+
|
| 1352 |
+
return algorithms.searchsorted(
|
| 1353 |
+
values,
|
| 1354 |
+
value,
|
| 1355 |
+
side=side,
|
| 1356 |
+
sorter=sorter,
|
| 1357 |
+
)
|
| 1358 |
+
|
| 1359 |
+
def drop_duplicates(self, *, keep: DropKeep = "first"):
|
| 1360 |
+
duplicated = self._duplicated(keep=keep)
|
| 1361 |
+
# error: Value of type "IndexOpsMixin" is not indexable
|
| 1362 |
+
return self[~duplicated] # type: ignore[index]
|
| 1363 |
+
|
| 1364 |
+
@final
|
| 1365 |
+
def _duplicated(self, keep: DropKeep = "first") -> npt.NDArray[np.bool_]:
|
| 1366 |
+
arr = self._values
|
| 1367 |
+
if isinstance(arr, ExtensionArray):
|
| 1368 |
+
return arr.duplicated(keep=keep)
|
| 1369 |
+
return algorithms.duplicated(arr, keep=keep)
|
| 1370 |
+
|
| 1371 |
+
def _arith_method(self, other, op):
|
| 1372 |
+
res_name = ops.get_op_result_name(self, other)
|
| 1373 |
+
|
| 1374 |
+
lvalues = self._values
|
| 1375 |
+
rvalues = extract_array(other, extract_numpy=True, extract_range=True)
|
| 1376 |
+
rvalues = ops.maybe_prepare_scalar_for_op(rvalues, lvalues.shape)
|
| 1377 |
+
rvalues = ensure_wrapped_if_datetimelike(rvalues)
|
| 1378 |
+
if isinstance(rvalues, range):
|
| 1379 |
+
rvalues = np.arange(rvalues.start, rvalues.stop, rvalues.step)
|
| 1380 |
+
|
| 1381 |
+
with np.errstate(all="ignore"):
|
| 1382 |
+
result = ops.arithmetic_op(lvalues, rvalues, op)
|
| 1383 |
+
|
| 1384 |
+
return self._construct_result(result, name=res_name)
|
| 1385 |
+
|
| 1386 |
+
def _construct_result(self, result, name):
|
| 1387 |
+
"""
|
| 1388 |
+
Construct an appropriately-wrapped result from the ArrayLike result
|
| 1389 |
+
of an arithmetic-like operation.
|
| 1390 |
+
"""
|
| 1391 |
+
raise AbstractMethodError(self)
|