Skip to content

Commit 05c8a02

Browse files
authored
Merge branch 'main' into fix-issue-61221
2 parents 31d7b33 + d1c6404 commit 05c8a02

36 files changed

+260
-122
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):

ci/code_checks.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7272
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
7373
-i "pandas.Period.freq GL08" \
7474
-i "pandas.Period.ordinal GL08" \
75-
-i "pandas.Timestamp.max PR02" \
76-
-i "pandas.Timestamp.min PR02" \
77-
-i "pandas.Timestamp.resolution PR02" \
7875
-i "pandas.core.groupby.DataFrameGroupBy.plot PR02" \
7976
-i "pandas.core.groupby.SeriesGroupBy.plot PR02" \
8077
-i "pandas.core.resample.Resampler.quantile PR01,PR07" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 3 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
@@ -773,6 +775,7 @@ Groupby/resample/rolling
773775
- Bug in :meth:`.DataFrameGroupBy.quantile` when ``interpolation="nearest"`` is inconsistent with :meth:`DataFrame.quantile` (:issue:`47942`)
774776
- Bug in :meth:`.Resampler.interpolate` on a :class:`DataFrame` with non-uniform sampling and/or indices not aligning with the resulting resampled index would result in wrong interpolation (:issue:`21351`)
775777
- Bug in :meth:`DataFrame.ewm` and :meth:`Series.ewm` when passed ``times`` and aggregation functions other than mean (:issue:`51695`)
778+
- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` were not keeping the index name when the index had :class:`ArrowDtype` timestamp dtype (:issue:`61222`)
776779
- Bug in :meth:`DataFrame.resample` changing index type to :class:`MultiIndex` when the dataframe is empty and using an upsample method (:issue:`55572`)
777780
- Bug in :meth:`DataFrameGroupBy.agg` that raises ``AttributeError`` when there is dictionary input and duplicated columns, instead of returning a DataFrame with the aggregation of all duplicate columns. (:issue:`55041`)
778781
- Bug in :meth:`DataFrameGroupBy.apply` and :meth:`SeriesGroupBy.apply` for empty data frame with ``group_keys=False`` still creating output index using group keys. (:issue:`60471`)

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/_libs/tslibs/timestamps.pyx

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ class MinMaxReso:
200200
201201
See also: timedeltas.MinMaxReso
202202
"""
203-
def __init__(self, name):
203+
def __init__(self, name, docstring):
204204
self._name = name
205+
self.__doc__ = docstring
205206

206207
def __get__(self, obj, type=None):
207208
cls = Timestamp
@@ -216,11 +217,15 @@ class MinMaxReso:
216217

217218
if obj is None:
218219
# i.e. this is on the class, default to nanos
219-
return cls(val)
220+
result = cls(val)
220221
elif self._name == "resolution":
221-
return Timedelta._from_value_and_reso(val, obj._creso)
222+
result = Timedelta._from_value_and_reso(val, obj._creso)
222223
else:
223-
return Timestamp._from_value_and_reso(val, obj._creso, tz=None)
224+
result = Timestamp._from_value_and_reso(val, obj._creso, tz=None)
225+
226+
result.__doc__ = self.__doc__
227+
228+
return result
224229

225230
def __set__(self, obj, value):
226231
raise AttributeError(f"{self._name} is not settable.")
@@ -235,9 +240,74 @@ cdef class _Timestamp(ABCTimestamp):
235240
dayofweek = _Timestamp.day_of_week
236241
dayofyear = _Timestamp.day_of_year
237242

238-
min = MinMaxReso("min")
239-
max = MinMaxReso("max")
240-
resolution = MinMaxReso("resolution") # GH#21336, GH#21365
243+
_docstring_min = """
244+
Returns the minimum bound possible for Timestamp.
245+
246+
This property provides access to the smallest possible value that
247+
can be represented by a Timestamp object.
248+
249+
Returns
250+
-------
251+
Timestamp
252+
253+
See Also
254+
--------
255+
Timestamp.max: Returns the maximum bound possible for Timestamp.
256+
Timestamp.resolution: Returns the smallest possible difference between
257+
non-equal Timestamp objects.
258+
259+
Examples
260+
--------
261+
>>> pd.Timestamp.min
262+
Timestamp('1677-09-21 00:12:43.145224193')
263+
"""
264+
265+
_docstring_max = """
266+
Returns the maximum bound possible for Timestamp.
267+
268+
This property provides access to the largest possible value that
269+
can be represented by a Timestamp object.
270+
271+
Returns
272+
-------
273+
Timestamp
274+
275+
See Also
276+
--------
277+
Timestamp.min: Returns the minimum bound possible for Timestamp.
278+
Timestamp.resolution: Returns the smallest possible difference between
279+
non-equal Timestamp objects.
280+
281+
Examples
282+
--------
283+
>>> pd.Timestamp.max
284+
Timestamp('2262-04-11 23:47:16.854775807')
285+
"""
286+
287+
_docstring_reso = """
288+
Returns the smallest possible difference between non-equal Timestamp objects.
289+
290+
The resolution value is determined by the underlying representation of time
291+
units and is equivalent to Timedelta(nanoseconds=1).
292+
293+
Returns
294+
-------
295+
Timedelta
296+
297+
See Also
298+
--------
299+
Timestamp.max: Returns the maximum bound possible for Timestamp.
300+
Timestamp.min: Returns the minimum bound possible for Timestamp.
301+
302+
Examples
303+
--------
304+
>>> pd.Timestamp.resolution
305+
Timedelta('0 days 00:00:00.000000001')
306+
"""
307+
308+
min = MinMaxReso("min", _docstring_min)
309+
max = MinMaxReso("max", _docstring_max)
310+
resolution = MinMaxReso("resolution", _docstring_reso) # GH#21336, GH#21365
241311

242312
@property
243313
def value(self) -> int:

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/core/resample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ def _wrap_result(self, result):
518518

519519
if self._timegrouper._arrow_dtype is not None:
520520
result.index = result.index.astype(self._timegrouper._arrow_dtype)
521+
result.index.name = self.obj.index.name
521522

522523
return result
523524

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

0 commit comments

Comments
 (0)