Skip to content

Commit 3b71240

Browse files
simonjayhawkinsdeepith-18
authored andcommitted
Merge branch 'main' into doc-fix-frame-periods
2 parents d2b025d + e503c13 commit 3b71240

File tree

19 files changed

+154
-34
lines changed

19 files changed

+154
-34
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ Reshaping
10831083
- Bug in :meth:`DataFrame.join` when a :class:`DataFrame` with a :class:`MultiIndex` would raise an ``AssertionError`` when :attr:`MultiIndex.names` contained ``None``. (:issue:`58721`)
10841084
- Bug in :meth:`DataFrame.merge` where merging on a column containing only ``NaN`` values resulted in an out-of-bounds array access (:issue:`59421`)
10851085
- Bug in :meth:`DataFrame.unstack` producing incorrect results when ``sort=False`` (:issue:`54987`, :issue:`55516`)
1086+
- Bug in :meth:`DataFrame.unstack` raising an error with indexes containing ``NaN`` with ``sort=False`` (:issue:`61221`)
10861087
- Bug in :meth:`DataFrame.merge` when merging two :class:`DataFrame` on ``intc`` or ``uintc`` types on Windows (:issue:`60091`, :issue:`58713`)
10871088
- Bug in :meth:`DataFrame.pivot_table` incorrectly subaggregating results when called without an ``index`` argument (:issue:`58722`)
10881089
- Bug in :meth:`DataFrame.pivot_table` incorrectly ignoring the ``values`` argument when also supplied to the ``index`` or ``columns`` parameters (:issue:`57876`, :issue:`61292`)

environment.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ dependencies:
9191
- sphinx
9292
- sphinx-design
9393
- sphinx-copybutton
94+
95+
# static typing
96+
- scipy-stubs
9497
- types-python-dateutil
9598
- types-PyMySQL
9699
- types-pytz

pandas/_testing/asserters.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,13 @@ def raise_assert_detail(
584584

585585
if isinstance(left, np.ndarray):
586586
left = pprint_thing(left)
587-
elif isinstance(left, (CategoricalDtype, NumpyEADtype)):
587+
elif isinstance(left, (CategoricalDtype, StringDtype, NumpyEADtype)):
588588
left = repr(left)
589-
elif isinstance(left, StringDtype):
590-
# TODO(infer_string) this special case could be avoided if we have
591-
# a more informative repr https://github.com/pandas-dev/pandas/issues/59342
592-
left = f"StringDtype(storage={left.storage}, na_value={left.na_value})"
593589

594590
if isinstance(right, np.ndarray):
595591
right = pprint_thing(right)
596-
elif isinstance(right, (CategoricalDtype, NumpyEADtype)):
592+
elif isinstance(right, (CategoricalDtype, StringDtype, NumpyEADtype)):
597593
right = repr(right)
598-
elif isinstance(right, StringDtype):
599-
right = f"StringDtype(storage={right.storage}, na_value={right.na_value})"
600594

601595
msg += f"""
602596
[left]: {left}

pandas/core/arrays/boolean.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
lib,
1515
missing as libmissing,
1616
)
17+
from pandas.util._decorators import set_module
1718

1819
from pandas.core.dtypes.common import is_list_like
1920
from pandas.core.dtypes.dtypes import register_extension_dtype
@@ -39,6 +40,7 @@
3940

4041

4142
@register_extension_dtype
43+
@set_module("pandas")
4244
class BooleanDtype(BaseMaskedDtype):
4345
"""
4446
Extension dtype for boolean data.

pandas/core/arrays/floating.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import numpy as np
1010

11+
from pandas.util._decorators import set_module
12+
1113
from pandas.core.dtypes.base import register_extension_dtype
1214
from pandas.core.dtypes.common import is_float_dtype
1315

@@ -168,13 +170,15 @@ class FloatingArray(NumericArray):
168170

169171

170172
@register_extension_dtype
173+
@set_module("pandas")
171174
class Float32Dtype(FloatingDtype):
172175
type = np.float32
173176
name: ClassVar[str] = "Float32"
174177
__doc__ = _dtype_docstring.format(dtype="float32")
175178

176179

177180
@register_extension_dtype
181+
@set_module("pandas")
178182
class Float64Dtype(FloatingDtype):
179183
type = np.float64
180184
name: ClassVar[str] = "Float64"

pandas/core/arrays/integer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import numpy as np
1010

11+
from pandas.util._decorators import set_module
12+
1113
from pandas.core.dtypes.base import register_extension_dtype
1214
from pandas.core.dtypes.common import is_integer_dtype
1315

@@ -218,55 +220,63 @@ class IntegerArray(NumericArray):
218220

219221

220222
@register_extension_dtype
223+
@set_module("pandas")
221224
class Int8Dtype(IntegerDtype):
222225
type = np.int8
223226
name: ClassVar[str] = "Int8"
224227
__doc__ = _dtype_docstring.format(dtype="int8")
225228

226229

227230
@register_extension_dtype
231+
@set_module("pandas")
228232
class Int16Dtype(IntegerDtype):
229233
type = np.int16
230234
name: ClassVar[str] = "Int16"
231235
__doc__ = _dtype_docstring.format(dtype="int16")
232236

233237

234238
@register_extension_dtype
239+
@set_module("pandas")
235240
class Int32Dtype(IntegerDtype):
236241
type = np.int32
237242
name: ClassVar[str] = "Int32"
238243
__doc__ = _dtype_docstring.format(dtype="int32")
239244

240245

241246
@register_extension_dtype
247+
@set_module("pandas")
242248
class Int64Dtype(IntegerDtype):
243249
type = np.int64
244250
name: ClassVar[str] = "Int64"
245251
__doc__ = _dtype_docstring.format(dtype="int64")
246252

247253

248254
@register_extension_dtype
255+
@set_module("pandas")
249256
class UInt8Dtype(IntegerDtype):
250257
type = np.uint8
251258
name: ClassVar[str] = "UInt8"
252259
__doc__ = _dtype_docstring.format(dtype="uint8")
253260

254261

255262
@register_extension_dtype
263+
@set_module("pandas")
256264
class UInt16Dtype(IntegerDtype):
257265
type = np.uint16
258266
name: ClassVar[str] = "UInt16"
259267
__doc__ = _dtype_docstring.format(dtype="uint16")
260268

261269

262270
@register_extension_dtype
271+
@set_module("pandas")
263272
class UInt32Dtype(IntegerDtype):
264273
type = np.uint32
265274
name: ClassVar[str] = "UInt32"
266275
__doc__ = _dtype_docstring.format(dtype="uint32")
267276

268277

269278
@register_extension_dtype
279+
@set_module("pandas")
270280
class UInt64Dtype(IntegerDtype):
271281
type = np.uint64
272282
name: ClassVar[str] = "UInt64"

pandas/core/dtypes/dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class PandasExtensionDtype(ExtensionDtype):
123123
# problem dealing with multiple inheritance from PandasExtensionDtype
124124
# and ExtensionDtype's @properties in the subclasses below. The kind and
125125
# type variables in those subclasses are explicitly typed below.
126-
subdtype = None
126+
subdtype: DtypeObj | None = None
127127
str: str_type
128128
num = 100
129129
shape: tuple[int, ...] = ()
@@ -1604,7 +1604,7 @@ class BaseMaskedDtype(ExtensionDtype):
16041604
Base class for dtypes for BaseMaskedArray subclasses.
16051605
"""
16061606

1607-
base = None
1607+
base: DtypeObj | None = None
16081608
type: type
16091609
_internal_fill_value: Scalar
16101610

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11774,7 +11774,7 @@ def count(self, axis: Axis = 0, numeric_only: bool = False) -> Series:
1177411774
axis : {0 or 'index', 1 or 'columns'}, default 0
1177511775
If 0 or 'index' counts are generated for each column.
1177611776
If 1 or 'columns' counts are generated for each row.
11777-
numeric_only : bool, default False.
11777+
numeric_only : bool, default False
1177811778
Include only `float`, `int` or `boolean` data.
1177911779
1178011780
Returns

pandas/core/missing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
)
4646

4747
if TYPE_CHECKING:
48+
from collections.abc import Callable
4849
from typing import TypeAlias
4950

5051
from pandas import Index
@@ -548,7 +549,7 @@ def _interpolate_scipy_wrapper(
548549
new_x = np.asarray(new_x)
549550

550551
# ignores some kwargs that could be passed along.
551-
alt_methods = {
552+
alt_methods: dict[str, Callable[..., np.ndarray]] = {
552553
"barycentric": interpolate.barycentric_interpolate,
553554
"krogh": interpolate.krogh_interpolate,
554555
"from_derivatives": _from_derivatives,
@@ -566,6 +567,7 @@ def _interpolate_scipy_wrapper(
566567
"cubic",
567568
"polynomial",
568569
]
570+
terp: Callable[..., np.ndarray] | None
569571
if method in interp1d_methods:
570572
if method == "polynomial":
571573
kind = order

pandas/core/nanops.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,10 @@ def nanmean(
693693
>>> nanops.nanmean(s.values)
694694
np.float64(1.5)
695695
"""
696+
if values.dtype == object and len(values) > 1_000 and mask is None:
697+
# GH#54754 if we are going to fail, try to fail-fast
698+
nanmean(values[:1000], axis=axis, skipna=skipna)
699+
696700
dtype = values.dtype
697701
values, mask = _get_values(values, skipna, fill_value=0, mask=mask)
698702
dtype_sum = _get_dtype_max(dtype)

0 commit comments

Comments
 (0)