Skip to content

Commit 641d315

Browse files
committed
Merge branch 'main' of https://github.com/pandas-dev/pandas into maybe-fix-windows-free-threaded
2 parents 962a662 + d1c6404 commit 641d315

File tree

32 files changed

+169
-109
lines changed

32 files changed

+169
-109
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
minimum_pre_commit_version: 2.15.0
1+
minimum_pre_commit_version: 4.0.0
22
exclude: ^LICENSES/|\.(html|csv|svg)$
33
# reserve "manual" for relatively slow hooks which we still want to run in CI
44
default_stages: [
@@ -19,13 +19,13 @@ ci:
1919
skip: [pyright, mypy]
2020
repos:
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.9.9
22+
rev: v0.11.4
2323
hooks:
2424
- id: ruff
2525
args: [--exit-non-zero-on-fix]
2626
exclude: ^pandas/tests/frame/test_query_eval.py
2727
- id: ruff
28-
# TODO: remove autofixe-only rules when they are checked by ruff
28+
# TODO: remove autofix only rules when they are checked by ruff
2929
name: ruff-selected-autofixes
3030
alias: ruff-selected-autofixes
3131
files: ^pandas
@@ -34,7 +34,7 @@ repos:
3434
- id: ruff-format
3535
exclude: ^scripts|^pandas/tests/frame/test_query_eval.py
3636
- repo: https://github.com/jendrikseipp/vulture
37-
rev: 'v2.14'
37+
rev: v2.14
3838
hooks:
3939
- id: vulture
4040
entry: python scripts/run_vulture.py
@@ -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: v19.1.7
98+
rev: v20.1.0
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.7.0
105+
rev: v1.7.2
106106
hooks:
107107
- id: meson-fmt
108108
args: ['--inplace']

asv_bench/benchmarks/frame_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def setup(self):
517517
self.df = DataFrame(np.random.randn(1000, 100))
518518

519519
self.s = Series(np.arange(1028.0))
520-
self.df2 = DataFrame({i: self.s for i in range(1028)})
520+
self.df2 = DataFrame(dict.fromkeys(range(1028), self.s))
521521
self.df3 = DataFrame(np.random.randn(1000, 3), columns=list("ABC"))
522522

523523
def time_apply_user_func(self):

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Other enhancements
6868
- :func:`read_parquet` accepts ``to_pandas_kwargs`` which are forwarded to :meth:`pyarrow.Table.to_pandas` which enables passing additional keywords to customize the conversion to pandas, such as ``maps_as_pydicts`` to read the Parquet map data type as python dictionaries (:issue:`56842`)
6969
- :meth:`.DataFrameGroupBy.transform`, :meth:`.SeriesGroupBy.transform`, :meth:`.DataFrameGroupBy.agg`, :meth:`.SeriesGroupBy.agg`, :meth:`.SeriesGroupBy.apply`, :meth:`.DataFrameGroupBy.apply` now support ``kurt`` (:issue:`40139`)
7070
- :meth:`DataFrame.apply` supports using third-party execution engines like the Bodo.ai JIT compiler (:issue:`60668`)
71+
- :meth:`DataFrame.iloc` and :meth:`Series.iloc` now support boolean masks in ``__getitem__`` for more consistent indexing behavior (:issue:`60994`)
7172
- :meth:`DataFrameGroupBy.transform`, :meth:`SeriesGroupBy.transform`, :meth:`DataFrameGroupBy.agg`, :meth:`SeriesGroupBy.agg`, :meth:`RollingGroupby.apply`, :meth:`ExpandingGroupby.apply`, :meth:`Rolling.apply`, :meth:`Expanding.apply`, :meth:`DataFrame.apply` with ``engine="numba"`` now supports positional arguments passed as kwargs (:issue:`58995`)
7273
- :meth:`Rolling.agg`, :meth:`Expanding.agg` and :meth:`ExponentialMovingWindow.agg` now accept :class:`NamedAgg` aggregations through ``**kwargs`` (:issue:`28333`)
7374
- :meth:`Series.map` can now accept kwargs to pass on to func (:issue:`59814`)
@@ -762,6 +763,7 @@ Plotting
762763
- Bug in :meth:`DataFrame.plot.bar` with ``stacked=True`` where labels on stacked bars with zero-height segments were incorrectly positioned at the base instead of the label position of the previous segment (:issue:`59429`)
763764
- Bug in :meth:`DataFrame.plot.line` raising ``ValueError`` when set both color and a ``dict`` style (:issue:`59461`)
764765
- Bug in :meth:`DataFrame.plot` that causes a shift to the right when the frequency multiplier is greater than one. (:issue:`57587`)
766+
- Bug in :meth:`Series.plot` preventing a line and scatter plot from being aligned (:issue:`61005`)
765767
- Bug in :meth:`Series.plot` with ``kind="pie"`` with :class:`ArrowDtype` (:issue:`59192`)
766768

767769
Groupby/resample/rolling

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ dependencies:
8080
- flake8=7.1.0 # run in subprocess over docstring examples
8181
- mypy=1.13.0 # pre-commit uses locally installed mypy
8282
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
83-
- pre-commit>=4.0.1
83+
- pre-commit>=4.2.0
8484

8585
# documentation
8686
- gitpython # obtain contributors from git for whatsnew

pandas/_libs/tslibs/timedeltas.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from typing import (
33
ClassVar,
44
Literal,
55
TypeAlias,
6-
TypeVar,
76
overload,
87
)
98

@@ -60,7 +59,6 @@ UnitChoices: TypeAlias = Literal[
6059
"nanos",
6160
"nanosecond",
6261
]
63-
_S = TypeVar("_S", bound=timedelta)
6462

6563
def get_unit_for_round(freq, creso: int) -> int: ...
6664
def disallow_ambiguous_unit(unit: str | None) -> None: ...
@@ -95,11 +93,11 @@ class Timedelta(timedelta):
9593
_value: int # np.int64
9694
# error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]")
9795
def __new__( # type: ignore[misc]
98-
cls: type[_S],
96+
cls: type[Self],
9997
value=...,
10098
unit: str | None = ...,
10199
**kwargs: float | np.integer | np.floating,
102-
) -> _S | NaTType: ...
100+
) -> Self | NaTType: ...
103101
@classmethod
104102
def _from_value_and_reso(cls, value: np.int64, reso: int) -> Timedelta: ...
105103
@property

pandas/core/apply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def transform(self) -> DataFrame | Series:
327327
if is_series:
328328
func = {com.get_callable_name(v) or v: v for v in func}
329329
else:
330-
func = {col: func for col in obj}
330+
func = dict.fromkeys(obj, func)
331331

332332
if is_dict_like(func):
333333
func = cast(AggFuncTypeDict, func)

pandas/core/arrays/string_arrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]:
281281
]
282282

283283
# short-circuit to return all False array.
284-
if not len(value_set):
284+
if not value_set:
285285
return np.zeros(len(self), dtype=bool)
286286

287287
result = pc.is_in(

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9705,7 +9705,7 @@ def _where(
97059705
# CoW: Make sure reference is not kept alive
97069706
if cond.ndim == 1 and self.ndim == 2:
97079707
cond = cond._constructor_expanddim(
9708-
{i: cond for i in range(len(self.columns))},
9708+
dict.fromkeys(range(len(self.columns)), cond),
97099709
copy=False,
97109710
)
97119711
cond.columns = self.columns

pandas/core/groupby/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,7 @@ def _apply_to_column_groupbys(self, func) -> DataFrame:
25052505
)
25062506
results = [func(sgb) for sgb in sgbs]
25072507

2508-
if not len(results):
2508+
if not results:
25092509
# concat would raise
25102510
res_df = DataFrame([], columns=columns, index=self._grouper.result_index)
25112511
else:

pandas/core/groupby/groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5175,8 +5175,8 @@ def diff(
51755175
shifted = shifted.astype("float32")
51765176
else:
51775177
to_coerce = [c for c, dtype in obj.dtypes.items() if dtype in dtypes_to_f32]
5178-
if len(to_coerce):
5179-
shifted = shifted.astype({c: "float32" for c in to_coerce})
5178+
if to_coerce:
5179+
shifted = shifted.astype(dict.fromkeys(to_coerce, "float32"))
51805180

51815181
return obj - shifted
51825182

pandas/core/indexing.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,11 +1582,7 @@ def _validate_key(self, key, axis: AxisInt) -> None:
15821582
if com.is_bool_indexer(key):
15831583
if hasattr(key, "index") and isinstance(key.index, Index):
15841584
if key.index.inferred_type == "integer":
1585-
raise NotImplementedError(
1586-
"iLocation based boolean "
1587-
"indexing on an integer type "
1588-
"is not available"
1589-
)
1585+
return
15901586
raise ValueError(
15911587
"iLocation based boolean indexing cannot use an indexable as a mask"
15921588
)

pandas/core/internals/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def replace_list(
805805
for x, y in zip(src_list, dest_list)
806806
if (self._can_hold_element(x) or (self.dtype == "string" and is_re(x)))
807807
]
808-
if not len(pairs):
808+
if not pairs:
809809
return [self.copy(deep=False)]
810810

811811
src_len = len(pairs) - 1

pandas/core/internals/construction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def _finalize_columns_and_data(
864864
# GH#26429 do not raise user-facing AssertionError
865865
raise ValueError(err) from err
866866

867-
if len(contents) and contents[0].dtype == np.object_:
867+
if contents and contents[0].dtype == np.object_:
868868
contents = convert_object_array(contents, dtype=dtype)
869869

870870
return contents, columns

pandas/core/internals/managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ def value_getitem(placement):
12981298
# Defer setting the new values to enable consolidation
12991299
self._iset_split_block(blkno_l, blk_locs, refs=refs)
13001300

1301-
if len(removed_blknos):
1301+
if removed_blknos:
13021302
# Remove blocks & update blknos accordingly
13031303
is_deleted = np.zeros(self.nblocks, dtype=np.bool_)
13041304
is_deleted[removed_blknos] = True

pandas/io/formats/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def _initialize_colspace(self, col_space: ColspaceArgType | None) -> ColspaceTyp
566566
result = {}
567567
elif isinstance(col_space, (int, str)):
568568
result = {"": col_space}
569-
result.update({column: col_space for column in self.frame.columns})
569+
result.update(dict.fromkeys(self.frame.columns, col_space))
570570
elif isinstance(col_space, Mapping):
571571
for column in col_space.keys():
572572
if column not in self.frame.columns and column != "":

pandas/io/formats/style_render.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ def format(
12251225
data = self.data.loc[subset]
12261226

12271227
if not isinstance(formatter, dict):
1228-
formatter = {col: formatter for col in data.columns}
1228+
formatter = dict.fromkeys(data.columns, formatter)
12291229

12301230
cis = self.columns.get_indexer_for(data.columns)
12311231
ris = self.index.get_indexer_for(data.index)
@@ -1411,7 +1411,7 @@ def format_index(
14111411
return self # clear the formatter / revert to default and avoid looping
14121412

14131413
if not isinstance(formatter, dict):
1414-
formatter = {level: formatter for level in levels_}
1414+
formatter = dict.fromkeys(levels_, formatter)
14151415
else:
14161416
formatter = {
14171417
obj._get_level_number(level): formatter_
@@ -1708,7 +1708,7 @@ def format_index_names(
17081708
return self # clear the formatter / revert to default and avoid looping
17091709

17101710
if not isinstance(formatter, dict):
1711-
formatter = {level: formatter for level in levels_}
1711+
formatter = dict.fromkeys(levels_, formatter)
17121712
else:
17131713
formatter = {
17141714
obj._get_level_number(level): formatter_

pandas/io/pytables.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ def info(self) -> str:
17601760

17611761
if self.is_open:
17621762
lkeys = sorted(self.keys())
1763-
if len(lkeys):
1763+
if lkeys:
17641764
keys = []
17651765
values = []
17661766

@@ -4540,7 +4540,7 @@ def write_data(self, chunksize: int | None, dropna: bool = False) -> None:
45404540
masks.append(mask.astype("u1", copy=False))
45414541

45424542
# consolidate masks
4543-
if len(masks):
4543+
if masks:
45444544
mask = masks[0]
45454545
for m in masks[1:]:
45464546
mask = mask & m
@@ -4660,7 +4660,7 @@ def delete(
46604660
groups = list(diff[diff > 1].index)
46614661

46624662
# 1 group
4663-
if not len(groups):
4663+
if not groups:
46644664
groups = [0]
46654665

46664666
# final element

pandas/io/sql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ def prep_table(
19011901
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
19021902
# Type[object]]]]"; expected type "Union[ExtensionDtype, str,
19031903
# dtype[Any], Type[object]]"
1904-
dtype = {col_name: dtype for col_name in frame} # type: ignore[misc]
1904+
dtype = dict.fromkeys(frame, dtype) # type: ignore[arg-type]
19051905
else:
19061906
dtype = cast(dict, dtype)
19071907

@@ -2615,7 +2615,7 @@ def _create_table_setup(self):
26152615
]
26162616

26172617
ix_cols = [cname for cname, _, is_index in column_names_and_types if is_index]
2618-
if len(ix_cols):
2618+
if ix_cols:
26192619
cnames = "_".join(ix_cols)
26202620
cnames_br = ",".join([escape(c) for c in ix_cols])
26212621
create_stmts.append(
@@ -2859,7 +2859,7 @@ def to_sql(
28592859
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
28602860
# Type[object]]]]"; expected type "Union[ExtensionDtype, str,
28612861
# dtype[Any], Type[object]]"
2862-
dtype = {col_name: dtype for col_name in frame} # type: ignore[misc]
2862+
dtype = dict.fromkeys(frame, dtype) # type: ignore[arg-type]
28632863
else:
28642864
dtype = cast(dict, dtype)
28652865

0 commit comments

Comments
 (0)