Skip to content

Commit 5135fae

Browse files
Merge branch 'main' into pandas.core.groupby.DataFrameGroupBy.groups
2 parents 38bfe3b + 4fcee0e commit 5135fae

File tree

22 files changed

+110
-94
lines changed

22 files changed

+110
-94
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
9090
-i "pandas.arrays.ArrowExtensionArray PR07,SA01" \
9191
-i "pandas.arrays.IntegerArray SA01" \
9292
-i "pandas.arrays.IntervalArray.length SA01" \
93-
-i "pandas.arrays.IntervalArray.right SA01" \
9493
-i "pandas.arrays.NumpyExtensionArray SA01" \
95-
-i "pandas.arrays.SparseArray PR07,SA01" \
9694
-i "pandas.arrays.TimedeltaArray PR07,SA01" \
9795
-i "pandas.core.groupby.DataFrameGroupBy.boxplot PR07,RT03,SA01" \
9896
-i "pandas.core.groupby.DataFrameGroupBy.get_group RT03,SA01" \

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ dependencies:
7777

7878
# code checks
7979
- flake8=7.1.0 # run in subprocess over docstring examples
80-
- mypy=1.11.2 # pre-commit uses locally installed mypy
80+
- mypy=1.13.0 # pre-commit uses locally installed mypy
8181
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
8282
- pre-commit>=4.0.1
8383

pandas/_testing/__init__.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import (
88
TYPE_CHECKING,
99
ContextManager,
10-
cast,
1110
)
1211

1312
import numpy as np
@@ -21,8 +20,6 @@
2120

2221
from pandas.compat import pa_version_under10p1
2322

24-
from pandas.core.dtypes.common import is_string_dtype
25-
2623
import pandas as pd
2724
from pandas import (
2825
ArrowDtype,
@@ -77,8 +74,8 @@
7774
with_csv_dialect,
7875
)
7976
from pandas.core.arrays import (
77+
ArrowExtensionArray,
8078
BaseMaskedArray,
81-
ExtensionArray,
8279
NumpyExtensionArray,
8380
)
8481
from pandas.core.arrays._mixins import NDArrayBackedExtensionArray
@@ -92,7 +89,6 @@
9289
NpDtype,
9390
)
9491

95-
from pandas.core.arrays import ArrowExtensionArray
9692

9793
UNSIGNED_INT_NUMPY_DTYPES: list[NpDtype] = ["uint8", "uint16", "uint32", "uint64"]
9894
UNSIGNED_INT_EA_DTYPES: list[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
@@ -512,24 +508,18 @@ def shares_memory(left, right) -> bool:
512508
if isinstance(left, pd.core.arrays.IntervalArray):
513509
return shares_memory(left._left, right) or shares_memory(left._right, right)
514510

515-
if (
516-
isinstance(left, ExtensionArray)
517-
and is_string_dtype(left.dtype)
518-
and left.dtype.storage == "pyarrow" # type: ignore[attr-defined]
519-
):
520-
# https://github.com/pandas-dev/pandas/pull/43930#discussion_r736862669
521-
left = cast("ArrowExtensionArray", left)
522-
if (
523-
isinstance(right, ExtensionArray)
524-
and is_string_dtype(right.dtype)
525-
and right.dtype.storage == "pyarrow" # type: ignore[attr-defined]
526-
):
527-
right = cast("ArrowExtensionArray", right)
511+
if isinstance(left, ArrowExtensionArray):
512+
if isinstance(right, ArrowExtensionArray):
513+
# https://github.com/pandas-dev/pandas/pull/43930#discussion_r736862669
528514
left_pa_data = left._pa_array
529515
right_pa_data = right._pa_array
530516
left_buf1 = left_pa_data.chunk(0).buffers()[1]
531517
right_buf1 = right_pa_data.chunk(0).buffers()[1]
532-
return left_buf1 == right_buf1
518+
return left_buf1.address == right_buf1.address
519+
else:
520+
# if we have one one ArrowExtensionArray and one other array, assume
521+
# they can only share memory if they share the same numpy buffer
522+
return np.shares_memory(left, right)
533523

534524
if isinstance(left, BaseMaskedArray) and isinstance(right, BaseMaskedArray):
535525
# By convention, we'll say these share memory if they share *either*

pandas/core/arrays/interval.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,21 @@ def right(self) -> Index:
12691269
"""
12701270
Return the right endpoints of each Interval in the IntervalArray as an Index.
12711271
1272+
This property extracts the right endpoints from each interval contained within
1273+
the IntervalArray. This can be helpful in use cases where you need to work
1274+
with or compare only the upper bounds of intervals, such as when performing
1275+
range-based filtering, determining interval overlaps, or visualizing the end
1276+
boundaries of data segments.
1277+
1278+
See Also
1279+
--------
1280+
arrays.IntervalArray.left : Return the left endpoints of each Interval in
1281+
the IntervalArray as an Index.
1282+
arrays.IntervalArray.mid : Return the midpoint of each Interval in the
1283+
IntervalArray as an Index.
1284+
arrays.IntervalArray.contains : Check elementwise if the Intervals contain
1285+
the value.
1286+
12721287
Examples
12731288
--------
12741289

pandas/core/arrays/sparse/array.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,18 @@ class SparseArray(OpsMixin, PandasObject, ExtensionArray):
289289
"""
290290
An ExtensionArray for storing sparse data.
291291
292+
SparseArray efficiently stores data with a high frequency of a
293+
specific fill value (e.g., zeros), saving memory by only retaining
294+
non-fill elements and their indices. This class is particularly
295+
useful for large datasets where most values are redundant.
296+
292297
Parameters
293298
----------
294299
data : array-like or scalar
295300
A dense array of values to store in the SparseArray. This may contain
296301
`fill_value`.
297302
sparse_index : SparseIndex, optional
303+
Index indicating the locations of sparse elements.
298304
fill_value : scalar, optional
299305
Elements in data that are ``fill_value`` are not stored in the
300306
SparseArray. For memory savings, this should be the most common value
@@ -345,6 +351,10 @@ class SparseArray(OpsMixin, PandasObject, ExtensionArray):
345351
-------
346352
None
347353
354+
See Also
355+
--------
356+
SparseDtype : Dtype for sparse data.
357+
348358
Examples
349359
--------
350360
>>> from pandas.arrays import SparseArray

pandas/core/computation/ops.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
class Term:
7777
def __new__(cls, name, env, side=None, encoding=None):
7878
klass = Constant if not isinstance(name, str) else cls
79-
# error: Argument 2 for "super" not an instance of argument 1
80-
supr_new = super(Term, klass).__new__ # type: ignore[misc]
79+
supr_new = super(Term, klass).__new__
8180
return supr_new(klass)
8281

8382
is_local: bool

pandas/core/dtypes/dtypes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,9 +2130,11 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
21302130
PerformanceWarning,
21312131
stacklevel=find_stack_level(),
21322132
)
2133-
21342133
np_dtypes = (x.subtype if isinstance(x, SparseDtype) else x for x in dtypes)
2135-
return SparseDtype(np_find_common_type(*np_dtypes), fill_value=fill_value)
2134+
# error: Argument 1 to "np_find_common_type" has incompatible type
2135+
# "*Generator[Any | dtype[Any] | ExtensionDtype, None, None]";
2136+
# expected "dtype[Any]" [arg-type]
2137+
return SparseDtype(np_find_common_type(*np_dtypes), fill_value=fill_value) # type: ignore [arg-type]
21362138

21372139

21382140
@register_extension_dtype

pandas/core/generic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8024,7 +8024,9 @@ def asof(self, where, subset=None):
80248024
np.nan, index=self.columns, name=where[0]
80258025
)
80268026

8027-
locs = self.index.asof_locs(where, ~(nulls._values))
8027+
# error: Unsupported operand type for
8028+
# ~ ("ExtensionArray | ndarray[Any, Any] | Any")
8029+
locs = self.index.asof_locs(where, ~nulls._values) # type: ignore[operator]
80288030

80298031
# mask the missing
80308032
mask = locs == -1

pandas/core/indexes/interval.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,7 @@ def _maybe_convert_i8(self, key):
558558
left = self._maybe_convert_i8(key.left)
559559
right = self._maybe_convert_i8(key.right)
560560
constructor = Interval if scalar else IntervalIndex.from_arrays
561-
# error: "object" not callable
562-
return constructor(left, right, closed=self.closed) # type: ignore[operator]
561+
return constructor(left, right, closed=self.closed)
563562

564563
if scalar:
565564
# Timestamp/Timedelta

pandas/core/indexing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,9 @@ def __setitem__(self, key, value) -> None:
914914
indexer = self._get_setitem_indexer(key)
915915
self._has_valid_setitem_indexer(key)
916916

917-
iloc = self if self.name == "iloc" else self.obj.iloc
917+
iloc: _iLocIndexer = (
918+
cast("_iLocIndexer", self) if self.name == "iloc" else self.obj.iloc
919+
)
918920
iloc._setitem_with_indexer(indexer, value, self.name)
919921

920922
def _validate_key(self, key, axis: AxisInt) -> None:

0 commit comments

Comments
 (0)