Skip to content

Commit 90a5972

Browse files
committed
Merge branch 'main' into 37715-remove-mypy-ignore
2 parents 4a9bcb6 + 898ab21 commit 90a5972

File tree

88 files changed

+905
-783
lines changed

Some content is hidden

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

88 files changed

+905
-783
lines changed

.github/workflows/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
labels:
8+
- "CI"
9+
- "Dependencies"

.pre-commit-config.yaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828
types_or: [python, pyi]
2929
additional_dependencies: [black==23.1.0]
3030
- repo: https://github.com/charliermarsh/ruff-pre-commit
31-
rev: v0.0.255
31+
rev: v0.0.259
3232
hooks:
3333
- id: ruff
3434
args: [--exit-non-zero-on-fix]
@@ -392,14 +392,6 @@ repos:
392392
files: ^pandas/
393393
exclude: ^(pandas/_libs/|pandas/tests/|pandas/errors/__init__.py$|pandas/_version.py)
394394
types: [python]
395-
- id: flake8-pyi
396-
name: flake8-pyi
397-
entry: flake8 --extend-ignore=E301,E302,E305,E701,E704
398-
types: [pyi]
399-
language: python
400-
additional_dependencies:
401-
- flake8==5.0.4
402-
- flake8-pyi==22.8.1
403395
- id: future-annotations
404396
name: import annotations from __future__
405397
entry: 'from __future__ import annotations'
@@ -421,8 +413,8 @@ repos:
421413
language: python
422414
stages: [manual]
423415
additional_dependencies:
424-
- autotyping==22.9.0
425-
- libcst==0.4.7
416+
- autotyping==23.3.0
417+
- libcst==0.4.9
426418
- id: check-test-naming
427419
name: check that test names start with 'test'
428420
entry: python -m scripts.check_test_naming

ci/code_checks.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8686
MSG='Partially validate docstrings (EX01)' ; echo $MSG
8787
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
8888
pandas.Series.index \
89-
pandas.Series.hasnans \
90-
pandas.Series.to_list \
9189
pandas.Series.__iter__ \
9290
pandas.Series.keys \
9391
pandas.Series.item \
@@ -309,7 +307,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
309307
pandas_object \
310308
pandas.api.interchange.from_dataframe \
311309
pandas.Index.values \
312-
pandas.Index.hasnans \
313310
pandas.Index.dtype \
314311
pandas.Index.inferred_type \
315312
pandas.Index.shape \
5.17 KB
Loading

doc/source/getting_started/tutorials.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Various tutorials
113113
* `Wes McKinney's (pandas BDFL) blog <https://wesmckinney.com/archives.html>`_
114114
* `Statistical analysis made easy in Python with SciPy and pandas DataFrames, by Randal Olson <http://www.randalolson.com/2012/08/06/statistical-analysis-made-easy-in-python/>`_
115115
* `Statistical Data Analysis in Python, tutorial videos, by Christopher Fonnesbeck from SciPy 2013 <https://conference.scipy.org/scipy2013/tutorial_detail.php?id=109>`_
116-
* `Financial analysis in Python, by Thomas Wiecki <https://nbviewer.ipython.org/github/twiecki/financial-analysis-python-tutorial/blob/master/1.%20Pandas%20Basics.ipynb>`_
116+
* `Financial analysis in Python, by Thomas Wiecki <https://nbviewer.org/github/twiecki/financial-analysis-python-tutorial/blob/master/1.%20Pandas%20Basics.ipynb>`_
117117
* `Intro to pandas data structures, by Greg Reda <http://www.gregreda.com/2013/10/26/intro-to-pandas-data-structures/>`_
118118
* `Pandas and Python: Top 10, by Manish Amde <https://manishamde.github.io/blog/2013/03/07/pandas-and-python-top-10/>`_
119119
* `Pandas DataFrames Tutorial, by Karlijn Willems <https://www.datacamp.com/community/tutorials/pandas-tutorial-dataframe-python>`_

doc/source/user_guide/reshaping.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Reshaping by pivoting DataFrame objects
1313

1414
.. image:: ../_static/reshaping_pivot.png
1515

16-
Data is often stored in so-called "stacked" or "record" format:
16+
Data is often stored in so-called "stacked" or "record" format. In a "record" or "wide" format typically there is one row for each subject. In the "stacked" or "long" format there are multiple rows for each subject where applicable.
1717

1818
.. ipython:: python
1919

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ Timedelta
11901190
- Bug in :func:`to_timedelta` raising error when input has nullable dtype ``Float64`` (:issue:`48796`)
11911191
- Bug in :class:`Timedelta` constructor incorrectly raising instead of returning ``NaT`` when given a ``np.timedelta64("nat")`` (:issue:`48898`)
11921192
- Bug in :class:`Timedelta` constructor failing to raise when passed both a :class:`Timedelta` object and keywords (e.g. days, seconds) (:issue:`48898`)
1193+
- Bug in :class:`Timedelta` comparisons with very large ``datetime.timedelta`` objects incorrect raising ``OutOfBoundsTimedelta`` (:issue:`49021`)
11931194

11941195
Timezones
11951196
^^^^^^^^^

doc/source/whatsnew/v2.1.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Other enhancements
3636
- :class:`api.extensions.ExtensionArray` now has a :meth:`~api.extensions.ExtensionArray.map` method (:issue:`51809`)
3737
- Improve error message when having incompatible columns using :meth:`DataFrame.merge` (:issue:`51861`)
3838
- Improved error message when creating a DataFrame with empty data (0 rows), no index and an incorrect number of columns. (:issue:`52084`)
39+
- :meth:`DataFrame.applymap` now uses the :meth:`~api.extensions.ExtensionArray.map` method of underlying :class:`api.extensions.ExtensionArray` instances (:issue:`52219`)
3940
- :meth:`arrays.SparseArray.map` now supports ``na_action`` (:issue:`52096`).
4041

4142
.. ---------------------------------------------------------------------------
@@ -114,6 +115,7 @@ Deprecations
114115
- Deprecated 'method', 'limit', and 'fill_axis' keywords in :meth:`DataFrame.align` and :meth:`Series.align`, explicitly call ``fillna`` on the alignment results instead (:issue:`51856`)
115116
- Deprecated 'broadcast_axis' keyword in :meth:`Series.align` and :meth:`DataFrame.align`, upcast before calling ``align`` with ``left = DataFrame({col: left for col in right.columns}, index=right.index)`` (:issue:`51856`)
116117
- Deprecated the 'axis' keyword in :meth:`.GroupBy.idxmax`, :meth:`.GroupBy.idxmin`, :meth:`.GroupBy.fillna`, :meth:`.GroupBy.take`, :meth:`.GroupBy.skew`, :meth:`.GroupBy.rank`, :meth:`.GroupBy.cumprod`, :meth:`.GroupBy.cumsum`, :meth:`.GroupBy.cummax`, :meth:`.GroupBy.cummin`, :meth:`.GroupBy.pct_change`, :meth:`GroupBy.diff`, :meth:`.GroupBy.shift`, and :meth:`DataFrameGroupBy.corrwith`; for ``axis=1`` operate on the underlying :class:`DataFrame` instead (:issue:`50405`, :issue:`51046`)
118+
- Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`)
117119
-
118120

119121
.. ---------------------------------------------------------------------------

pandas/_config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def pp(name: str, ks: Iterable[str]) -> list[str]:
737737

738738

739739
@contextmanager
740-
def config_prefix(prefix) -> Generator[None, None, None]:
740+
def config_prefix(prefix: str) -> Generator[None, None, None]:
741741
"""
742742
contextmanager for multiple invocations of API with a common prefix
743743

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import warnings
44
cimport cython
55
from cpython.object cimport (
66
Py_EQ,
7+
Py_GE,
8+
Py_GT,
9+
Py_LE,
10+
Py_LT,
711
Py_NE,
812
PyObject,
913
PyObject_RichCompare,
@@ -1154,8 +1158,27 @@ cdef class _Timedelta(timedelta):
11541158
if isinstance(other, _Timedelta):
11551159
ots = other
11561160
elif is_any_td_scalar(other):
1157-
ots = Timedelta(other)
1158-
# TODO: watch out for overflows
1161+
try:
1162+
ots = Timedelta(other)
1163+
except OutOfBoundsTimedelta as err:
1164+
# GH#49021 pytimedelta.max overflows
1165+
if not PyDelta_Check(other):
1166+
# TODO: handle this case
1167+
raise
1168+
ltup = (self.days, self.seconds, self.microseconds, self.nanoseconds)
1169+
rtup = (other.days, other.seconds, other.microseconds, 0)
1170+
if op == Py_EQ:
1171+
return ltup == rtup
1172+
elif op == Py_NE:
1173+
return ltup != rtup
1174+
elif op == Py_LT:
1175+
return ltup < rtup
1176+
elif op == Py_LE:
1177+
return ltup <= rtup
1178+
elif op == Py_GT:
1179+
return ltup > rtup
1180+
elif op == Py_GE:
1181+
return ltup >= rtup
11591182

11601183
elif other is NaT:
11611184
return op == Py_NE

pandas/_testing/_random.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))
1111

1212

13-
def rands_array(nchars, size, dtype: NpDtype = "O", replace: bool = True) -> np.ndarray:
13+
def rands_array(
14+
nchars, size: int, dtype: NpDtype = "O", replace: bool = True
15+
) -> np.ndarray:
1416
"""
1517
Generate an array of byte strings.
1618
"""

pandas/_testing/contexts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def ensure_safe_environment_variables() -> Generator[None, None, None]:
154154

155155

156156
@contextmanager
157-
def with_csv_dialect(name, **kwargs) -> Generator[None, None, None]:
157+
def with_csv_dialect(name: str, **kwargs) -> Generator[None, None, None]:
158158
"""
159159
Context manager to temporarily register a CSV dialect for parsing CSV.
160160

pandas/compat/numpy/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def validate_take_with_convert(convert: ndarray | bool | None, args, kwargs) ->
342342
)
343343

344344

345-
def validate_groupby_func(name, args, kwargs, allowed=None) -> None:
345+
def validate_groupby_func(name: str, args, kwargs, allowed=None) -> None:
346346
"""
347347
'args' and 'kwargs' should be empty, except for allowed kwargs because all
348348
of their necessary parameters are explicitly listed in the function

pandas/core/accessor.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ class PandasDelegate:
5151
Abstract base class for delegating methods/properties.
5252
"""
5353

54-
def _delegate_property_get(self, name, *args, **kwargs):
54+
def _delegate_property_get(self, name: str, *args, **kwargs):
5555
raise TypeError(f"You cannot access the property {name}")
5656

57-
def _delegate_property_set(self, name, value, *args, **kwargs):
57+
def _delegate_property_set(self, name: str, value, *args, **kwargs):
5858
raise TypeError(f"The property {name} cannot be set")
5959

60-
def _delegate_method(self, name, *args, **kwargs):
60+
def _delegate_method(self, name: str, *args, **kwargs):
6161
raise TypeError(f"You cannot call method {name}")
6262

6363
@classmethod
@@ -91,7 +91,7 @@ def _add_delegate_accessors(
9191
False skips the missing accessor.
9292
"""
9393

94-
def _create_delegator_property(name):
94+
def _create_delegator_property(name: str):
9595
def _getter(self):
9696
return self._delegate_property_get(name)
9797

@@ -107,7 +107,7 @@ def _setter(self, new_values):
107107
doc=getattr(delegate, accessor_mapping(name)).__doc__,
108108
)
109109

110-
def _create_delegator_method(name):
110+
def _create_delegator_method(name: str):
111111
def f(self, *args, **kwargs):
112112
return self._delegate_method(name, *args, **kwargs)
113113

@@ -231,7 +231,7 @@ def __get__(self, obj, cls):
231231

232232

233233
@doc(klass="", others="")
234-
def _register_accessor(name, cls):
234+
def _register_accessor(name: str, cls):
235235
"""
236236
Register a custom accessor on {klass} objects.
237237
@@ -320,21 +320,21 @@ def decorator(accessor):
320320

321321

322322
@doc(_register_accessor, klass="DataFrame")
323-
def register_dataframe_accessor(name):
323+
def register_dataframe_accessor(name: str):
324324
from pandas import DataFrame
325325

326326
return _register_accessor(name, DataFrame)
327327

328328

329329
@doc(_register_accessor, klass="Series")
330-
def register_series_accessor(name):
330+
def register_series_accessor(name: str):
331331
from pandas import Series
332332

333333
return _register_accessor(name, Series)
334334

335335

336336
@doc(_register_accessor, klass="Index")
337-
def register_index_accessor(name):
337+
def register_index_accessor(name: str):
338338
from pandas import Index
339339

340340
return _register_accessor(name, Index)

pandas/core/arrays/_mixins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ def __getitem__(
291291
return result
292292

293293
def _fill_mask_inplace(
294-
self, method: str, limit, mask: npt.NDArray[np.bool_]
294+
self, method: str, limit: int | None, mask: npt.NDArray[np.bool_]
295295
) -> None:
296296
# (for now) when self.ndim == 2, we assume axis=0
297297
func = missing.get_fill_func(method, ndim=self.ndim)
298298
func(self._ndarray.T, limit=limit, mask=mask.T)
299299

300300
@doc(ExtensionArray.fillna)
301-
def fillna(self, value=None, method=None, limit=None) -> Self:
301+
def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
302302
value, method = validate_fillna_kwargs(
303303
value, method, validate_scalar_dict_value=False
304304
)

pandas/core/arrays/arrow/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ def _str_translate(self, table):
19521952
"str.translate not supported with pd.ArrowDtype(pa.string())."
19531953
)
19541954

1955-
def _str_wrap(self, width, **kwargs):
1955+
def _str_wrap(self, width: int, **kwargs):
19561956
raise NotImplementedError(
19571957
"str.wrap not supported with pd.ArrowDtype(pa.string())."
19581958
)

pandas/core/arrays/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ def _where(self, mask: npt.NDArray[np.bool_], value) -> Self:
15701570
return result
15711571

15721572
def _fill_mask_inplace(
1573-
self, method: str, limit, mask: npt.NDArray[np.bool_]
1573+
self, method: str, limit: int | None, mask: npt.NDArray[np.bool_]
15741574
) -> None:
15751575
"""
15761576
Replace values in locations specified by 'mask' using pad or backfill.

pandas/core/arrays/categorical.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,10 +2500,14 @@ def _validate(data):
25002500
if not is_categorical_dtype(data.dtype):
25012501
raise AttributeError("Can only use .cat accessor with a 'category' dtype")
25022502

2503-
def _delegate_property_get(self, name):
2503+
# error: Signature of "_delegate_property_get" incompatible with supertype
2504+
# "PandasDelegate"
2505+
def _delegate_property_get(self, name: str): # type: ignore[override]
25042506
return getattr(self._parent, name)
25052507

2506-
def _delegate_property_set(self, name, new_values):
2508+
# error: Signature of "_delegate_property_set" incompatible with supertype
2509+
# "PandasDelegate"
2510+
def _delegate_property_set(self, name: str, new_values): # type: ignore[override]
25072511
return setattr(self._parent, name, new_values)
25082512

25092513
@property
@@ -2515,7 +2519,7 @@ def codes(self) -> Series:
25152519

25162520
return Series(self._parent.codes, index=self._index)
25172521

2518-
def _delegate_method(self, name, *args, **kwargs):
2522+
def _delegate_method(self, name: str, *args, **kwargs):
25192523
from pandas import Series
25202524

25212525
method = getattr(self._parent, name)

pandas/core/arrays/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def tz_to_dtype(tz: tzinfo | None, unit: str = "ns"):
113113
return DatetimeTZDtype(tz=tz, unit=unit)
114114

115115

116-
def _field_accessor(name: str, field: str, docstring=None):
116+
def _field_accessor(name: str, field: str, docstring: str | None = None):
117117
def f(self):
118118
values = self._local_timestamps()
119119

pandas/core/arrays/interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def max(self, *, axis: AxisInt | None = None, skipna: bool = True) -> IntervalOr
889889
indexer = obj.argsort()[-1]
890890
return obj[indexer]
891891

892-
def fillna(self, value=None, method=None, limit=None) -> Self:
892+
def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
893893
"""
894894
Fill NA/NaN values using the specified method.
895895

pandas/core/arrays/masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __getitem__(self, item: PositionalIndexer) -> Self | Any:
162162

163163
@doc(ExtensionArray.fillna)
164164
@doc(ExtensionArray.fillna)
165-
def fillna(self, value=None, method=None, limit=None) -> Self:
165+
def fillna(self, value=None, method=None, limit: int | None = None) -> Self:
166166
value, method = validate_fillna_kwargs(value, method)
167167

168168
mask = self._mask

pandas/core/arrays/period.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
}
9999

100100

101-
def _field_accessor(name: str, docstring=None):
101+
def _field_accessor(name: str, docstring: str | None = None):
102102
def f(self):
103103
base = self.freq._period_dtype_code
104104
result = get_period_field_arr(name, self.asi8, base)
@@ -658,7 +658,7 @@ def searchsorted(
658658
m8arr = self._ndarray.view("M8[ns]")
659659
return m8arr.searchsorted(npvalue, side=side, sorter=sorter)
660660

661-
def fillna(self, value=None, method=None, limit=None) -> PeriodArray:
661+
def fillna(self, value=None, method=None, limit: int | None = None) -> PeriodArray:
662662
if method is not None:
663663
# view as dt64 so we get treated as timelike in core.missing,
664664
# similar to dtl._period_dispatch

pandas/core/arrays/sparse/accessor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def _validate(self, data):
4646
if not isinstance(data.dtype, SparseDtype):
4747
raise AttributeError(self._validation_msg)
4848

49-
def _delegate_property_get(self, name, *args, **kwargs):
49+
def _delegate_property_get(self, name: str, *args, **kwargs):
5050
return getattr(self._parent.array, name)
5151

52-
def _delegate_method(self, name, *args, **kwargs):
52+
def _delegate_method(self, name: str, *args, **kwargs):
5353
if name == "from_coo":
5454
return self.from_coo(*args, **kwargs)
5555
elif name == "to_coo":

0 commit comments

Comments
 (0)