Skip to content

Commit dfc7f71

Browse files
committed
updated documentation build branch with commits from upstream/main
2 parents 9c5b2d3 + 2ad2abd commit dfc7f71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+302
-228
lines changed

.github/workflows/wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jobs:
162162
run: echo "sdist_name=$(cd ./dist && ls -d */)" >> "$GITHUB_ENV"
163163

164164
- name: Build wheels
165-
uses: pypa/[email protected].1
165+
uses: pypa/[email protected].3
166166
with:
167167
package-dir: ./dist/${{ startsWith(matrix.buildplat[1], 'macosx') && env.sdist_name || needs.build_sdist.outputs.sdist_file }}
168168
env:

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ci:
1919
skip: [pyright, mypy]
2020
repos:
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.12.2
22+
rev: v0.12.7
2323
hooks:
2424
- id: ruff
2525
args: [--exit-non-zero-on-fix]
@@ -95,14 +95,14 @@ repos:
9595
- id: sphinx-lint
9696
args: ["--enable", "all", "--disable", "line-too-long"]
9797
- repo: https://github.com/pre-commit/mirrors-clang-format
98-
rev: v20.1.7
98+
rev: v20.1.8
9999
hooks:
100100
- id: clang-format
101101
files: ^pandas/_libs/src|^pandas/_libs/include
102102
args: [-i]
103103
types_or: [c, c++]
104104
- repo: https://github.com/trim21/pre-commit-mirror-meson
105-
rev: v1.8.2
105+
rev: v1.8.3
106106
hooks:
107107
- id: meson-fmt
108108
args: ['--inplace']

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Other enhancements
8181
- :meth:`Rolling.agg`, :meth:`Expanding.agg` and :meth:`ExponentialMovingWindow.agg` now accept :class:`NamedAgg` aggregations through ``**kwargs`` (:issue:`28333`)
8282
- :meth:`Series.map` can now accept kwargs to pass on to func (:issue:`59814`)
8383
- :meth:`Series.map` now accepts an ``engine`` parameter to allow execution with a third-party execution engine (:issue:`61125`)
84+
- :meth:`Series.rank` and :meth:`DataFrame.rank` with numpy-nullable dtypes preserve ``NA`` values and return ``UInt64`` dtype where appropriate instead of casting ``NA`` to ``NaN`` with ``float64`` dtype (:issue:`62043`)
8485
- :meth:`Series.str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`)
8586
- :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`)
8687
- :py:class:`frozenset` elements in pandas objects are now natively printed (:issue:`60690`)

pandas/_libs/index.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ cdef class BaseMultiIndexCodesEngine:
803803
int_keys : 1-dimensional array of dtype uint64 or object
804804
Integers representing one combination each
805805
"""
806-
level_codes = list(target._recode_for_new_levels(self.levels))
806+
level_codes = list(target._recode_for_new_levels(self.levels, copy=True))
807807
for i, codes in enumerate(level_codes):
808808
if self.levels[i].hasnans:
809809
na_index = self.levels[i].isna().nonzero()[0][0]

pandas/conftest.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,25 +176,19 @@ def pytest_collection_modifyitems(items, config) -> None:
176176
ignore_doctest_warning(item, path, message)
177177

178178

179-
hypothesis_health_checks = [
180-
hypothesis.HealthCheck.too_slow,
181-
hypothesis.HealthCheck.differing_executors,
182-
]
183-
184-
# Hypothesis
179+
# Similar to "ci" config in
180+
# https://hypothesis.readthedocs.io/en/latest/reference/api.html#built-in-profiles
185181
hypothesis.settings.register_profile(
186-
"ci",
187-
# Hypothesis timing checks are tuned for scalars by default, so we bump
188-
# them from 200ms to 500ms per test case as the global default. If this
189-
# is too short for a specific test, (a) try to make it faster, and (b)
190-
# if it really is slow add `@settings(deadline=...)` with a working value,
191-
# or `deadline=None` to entirely disable timeouts for that test.
192-
# 2022-02-09: Changed deadline from 500 -> None. Deadline leads to
193-
# non-actionable, flaky CI failures (# GH 24641, 44969, 45118, 44969)
182+
"pandas_ci",
183+
database=None,
194184
deadline=None,
195-
suppress_health_check=tuple(hypothesis_health_checks),
185+
max_examples=15,
186+
suppress_health_check=(
187+
hypothesis.HealthCheck.too_slow,
188+
hypothesis.HealthCheck.differing_executors,
189+
),
196190
)
197-
hypothesis.settings.load_profile("ci")
191+
hypothesis.settings.load_profile("pandas_ci")
198192

199193
# Registering these strategies makes them globally available via st.from_type,
200194
# which is use for offsets in tests/tseries/offsets/test_offsets_properties.py

pandas/core/arrays/categorical.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,15 @@ def _from_inferred_categories(
670670
if known_categories:
671671
# Recode from observation order to dtype.categories order.
672672
categories = dtype.categories
673-
codes = recode_for_categories(inferred_codes, cats, categories)
673+
codes = recode_for_categories(inferred_codes, cats, categories, copy=False)
674674
elif not cats.is_monotonic_increasing:
675675
# Sort categories and recode for unknown categories.
676676
unsorted = cats.copy()
677677
categories = cats.sort_values()
678678

679-
codes = recode_for_categories(inferred_codes, unsorted, categories)
679+
codes = recode_for_categories(
680+
inferred_codes, unsorted, categories, copy=False
681+
)
680682
dtype = CategoricalDtype(categories, ordered=False)
681683
else:
682684
dtype = CategoricalDtype(cats, ordered=False)
@@ -945,7 +947,7 @@ def _set_categories(self, categories, fastpath: bool = False) -> None:
945947

946948
super().__init__(self._ndarray, new_dtype)
947949

948-
def _set_dtype(self, dtype: CategoricalDtype, copy: bool = True) -> Self:
950+
def _set_dtype(self, dtype: CategoricalDtype, *, copy: bool) -> Self:
949951
"""
950952
Internal method for directly updating the CategoricalDtype
951953
@@ -959,7 +961,7 @@ def _set_dtype(self, dtype: CategoricalDtype, copy: bool = True) -> Self:
959961
a (valid) instance of `CategoricalDtype`.
960962
"""
961963
codes = recode_for_categories(
962-
self.codes, self.categories, dtype.categories, copy
964+
self.codes, self.categories, dtype.categories, copy=copy
963965
)
964966
return type(self)._simple_new(codes, dtype=dtype)
965967

@@ -1154,7 +1156,7 @@ def set_categories(
11541156
codes = cat._codes
11551157
else:
11561158
codes = recode_for_categories(
1157-
cat.codes, cat.categories, new_dtype.categories
1159+
cat.codes, cat.categories, new_dtype.categories, copy=False
11581160
)
11591161
NDArrayBacked.__init__(cat, codes, new_dtype)
11601162
return cat
@@ -3006,7 +3008,7 @@ def _get_codes_for_values(
30063008

30073009

30083010
def recode_for_categories(
3009-
codes: np.ndarray, old_categories, new_categories, copy: bool = True
3011+
codes: np.ndarray, old_categories, new_categories, *, copy: bool
30103012
) -> np.ndarray:
30113013
"""
30123014
Convert a set of codes for to a new set of categories
@@ -3027,7 +3029,7 @@ def recode_for_categories(
30273029
>>> old_cat = pd.Index(["b", "a", "c"])
30283030
>>> new_cat = pd.Index(["a", "b"])
30293031
>>> codes = np.array([0, 1, 1, 2])
3030-
>>> recode_for_categories(codes, old_cat, new_cat)
3032+
>>> recode_for_categories(codes, old_cat, new_cat, copy=True)
30313033
array([ 1, 0, 0, -1], dtype=int8)
30323034
"""
30333035
if len(old_categories) == 0:

pandas/core/arrays/masked.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313

1414
from pandas._libs import (
15+
algos as libalgos,
1516
lib,
1617
missing as libmissing,
1718
)
@@ -992,6 +993,49 @@ def copy(self) -> Self:
992993
mask = self._mask.copy()
993994
return self._simple_new(data, mask)
994995

996+
def _rank(
997+
self,
998+
*,
999+
axis: AxisInt = 0,
1000+
method: str = "average",
1001+
na_option: str = "keep",
1002+
ascending: bool = True,
1003+
pct: bool = False,
1004+
):
1005+
# GH#62043 Avoid going through copy-making ensure_data in algorithms.rank
1006+
if axis != 0 or self.ndim != 1:
1007+
raise NotImplementedError
1008+
1009+
from pandas.core.arrays import FloatingArray
1010+
1011+
data = self._data
1012+
if data.dtype.kind == "b":
1013+
data = data.view("uint8")
1014+
1015+
result = libalgos.rank_1d(
1016+
data,
1017+
is_datetimelike=False,
1018+
ties_method=method,
1019+
ascending=ascending,
1020+
na_option=na_option,
1021+
pct=pct,
1022+
mask=self.isna(),
1023+
)
1024+
if na_option in ["top", "bottom"]:
1025+
mask = np.zeros(self.shape, dtype=bool)
1026+
else:
1027+
mask = self._mask.copy()
1028+
1029+
if method != "average" and not pct:
1030+
if na_option not in ["top", "bottom"]:
1031+
result[self._mask] = 0 # avoid warning on casting
1032+
result = result.astype("uint64", copy=False)
1033+
from pandas.core.arrays import IntegerArray
1034+
1035+
return IntegerArray(result, mask=mask)
1036+
1037+
return FloatingArray(result, mask=mask)
1038+
9951039
@doc(ExtensionArray.duplicated)
9961040
def duplicated(
9971041
self, keep: Literal["first", "last", False] = "first"

pandas/core/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ def consensus_name_attr(objs):
9191
try:
9292
if obj.name != name:
9393
name = None
94+
break
9495
except ValueError:
9596
name = None
97+
break
9698
return name
9799

98100

pandas/core/dtypes/concat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ def _maybe_unwrap(x):
318318
categories = categories.sort_values()
319319

320320
new_codes = [
321-
recode_for_categories(c.codes, c.categories, categories) for c in to_union
321+
recode_for_categories(c.codes, c.categories, categories, copy=False)
322+
for c in to_union
322323
]
323324
new_codes = np.concatenate(new_codes)
324325
else:

pandas/core/groupby/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def recode_for_groupby(c: Categorical, sort: bool, observed: bool) -> Categorica
5353

5454
# we recode according to the uniques
5555
categories = c.categories.take(take_codes)
56-
codes = recode_for_categories(c.codes, c.categories, categories)
56+
codes = recode_for_categories(c.codes, c.categories, categories, copy=False)
5757

5858
# return a new categorical that maps our new codes
5959
# and categories

0 commit comments

Comments
 (0)