Skip to content

Commit 17f6d1b

Browse files
committed
Merge branch 'main' of github.com:pandas-dev/pandas-stubs into feature/cmp0xff/truediv
2 parents 2d42ecd + 42192e0 commit 17f6d1b

File tree

9 files changed

+36
-35
lines changed

9 files changed

+36
-35
lines changed

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import sys
23
from typing import (
34
Literal,
45
TypeAlias,
@@ -13,9 +14,7 @@ from pandas.core.series import Series
1314
from typing_extensions import Self
1415

1516
from pandas._libs.tslibs import NaTType
16-
from pandas._libs.tslibs.offsets import (
17-
BaseOffset,
18-
)
17+
from pandas._libs.tslibs.offsets import BaseOffset
1918
from pandas._libs.tslibs.timedeltas import Timedelta
2019
from pandas._libs.tslibs.timestamps import Timestamp
2120
from pandas._typing import (
@@ -92,8 +91,15 @@ class Period(PeriodMixin):
9291
def __add__(self, other: _PeriodAddSub) -> Self: ...
9392
@overload
9493
def __add__(self, other: NaTType) -> NaTType: ...
95-
@overload
96-
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc,unused-ignore]
94+
# Ignored due to indecipherable error from mypy:
95+
# Forward operator "__add__" is not callable [misc]
96+
if sys.version_info >= (3, 11):
97+
@overload
98+
def __radd__(self, other: _PeriodAddSub) -> Self: ...
99+
else:
100+
@overload
101+
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc]
102+
97103
@overload
98104
def __radd__(self, other: NaTType) -> NaTType: ...
99105
# ignore[misc] here because we know all other comparisons

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ from pandas.core.indexes.timedeltas import TimedeltaIndex
2121
from pandas.core.series import Series
2222
from typing_extensions import Self
2323

24-
from pandas._libs.tslibs import (
25-
NaTType,
26-
)
24+
from pandas._libs.tslibs import NaTType
2725
from pandas._libs.tslibs.period import Period
2826
from pandas._libs.tslibs.timestamps import Timestamp
2927
from pandas._typing import (
@@ -128,7 +126,7 @@ class Timedelta(timedelta):
128126
def to_timedelta64(self) -> np.timedelta64: ...
129127
@property
130128
def asm8(self) -> np.timedelta64: ...
131-
# TODO: round/floor/ceil could return NaT?
129+
# TODO: pandas-dev/pandas-stubs#1432 round/floor/ceil could return NaT?
132130
def round(self, freq: Frequency) -> Self: ...
133131
def floor(self, freq: Frequency) -> Self: ...
134132
def ceil(self, freq: Frequency) -> Self: ...
@@ -314,8 +312,6 @@ class Timedelta(timedelta):
314312
self, other: Series[int] | Series[float] | Series[Timedelta]
315313
) -> Series[Timedelta]: ...
316314
def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ...
317-
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
318-
# for le, lt ge and gt
319315
# Override due to more types supported than timedelta
320316
@overload # type: ignore[override]
321317
def __le__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class Timestamp(datetime, SupportsIndex):
228228
def __radd__(
229229
self, other: np_ndarray[ShapeT, np.timedelta64]
230230
) -> np_ndarray[ShapeT, np.datetime64]: ...
231-
# TODO: test dt64
231+
# TODO: pandas-dev/pandas-stubs#1432 test dt64
232232
@overload # type: ignore[override]
233233
def __sub__(self, other: datetime | np.datetime64) -> Timedelta: ...
234234
@overload
@@ -284,15 +284,15 @@ class Timestamp(datetime, SupportsIndex):
284284
@property
285285
def asm8(self) -> np.datetime64: ...
286286
def tz_convert(self, tz: TimeZones) -> Self: ...
287-
# TODO: could return NaT?
287+
# TODO: pandas-dev/pandas-stubs#1432 could return NaT?
288288
def tz_localize(
289289
self,
290290
tz: TimeZones,
291291
ambiguous: _Ambiguous = "raise",
292292
nonexistent: TimestampNonexistent = "raise",
293293
) -> Self: ...
294294
def normalize(self) -> Self: ...
295-
# TODO: round/floor/ceil could return NaT?
295+
# TODO: pandas-dev/pandas-stubs#1432 round/floor/ceil could return NaT?
296296
def round(
297297
self,
298298
freq: str,

pandas-stubs/io/orc.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def read_orc(
1414
path: FilePath | ReadBuffer[bytes],
1515
columns: list[HashableT] | None = None,
1616
dtype_backend: DtypeBackend | _NoDefaultDoNotUse = "numpy_nullable",
17-
# TODO: type with the correct pyarrow types
17+
# TODO: pandas-dev/pandas-stubs#1432 type with the correct pyarrow types
1818
# filesystem: pyarrow.fs.FileSystem | fsspec.spec.AbstractFileSystem
1919
filesystem: Any | None = None,
2020
**kwargs: Any,

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ fix = true
178178
[tool.ruff.lint]
179179
extend-select = ["ALL"]
180180
ignore = [
181+
# The following rules are ignored permanently for good reasons
181182
"COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com
182183
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
183184
"E501", # handled by black https://docs.astral.sh/ruff/rules/line-too-long/
@@ -199,10 +200,10 @@ ignore = [
199200
"A004", # https://docs.astral.sh/ruff/rules/builtin-import-shadowing/
200201
"PYI001", # https://docs.astral.sh/ruff/rules/unprefixed-type-param/
201202
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/
202-
"TD003", # https://docs.astral.sh/ruff/rules/missing-todo-link/
203203
"ERA001", "ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "PLR0402", "PLC0105"
204204
]
205205
"scripts/*" = [
206+
# The following rules are ignored permanently for good reasons
206207
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
207208
"S603", # https://docs.astral.sh/ruff/rules/subprocess-without-shell-equals-true/
208209
]
@@ -220,7 +221,7 @@ ignore = [
220221
"A001", # https://docs.astral.sh/ruff/rules/builtin-variable-shadowing/
221222
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/
222223
"SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/
223-
"ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901"
224+
"ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "S311", "C901"
224225
]
225226
"tests/test_io.py" = [
226227
# The following rules are ignored permanently for good reasons

tests/test_frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ def test_types_to_feather() -> None:
19921992
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
19931993
# Docstring and type were updated in 1.2.0.
19941994
# https://github.com/pandas-dev/pandas/pull/35408
1995-
with open(path, mode="wb") as file:
1995+
with Path(path).open("wb") as file:
19961996
df.to_feather(file)
19971997

19981998

tests/test_io.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import csv
44
from functools import partial
55
import io
6-
import os.path
76
import pathlib
87
from pathlib import Path
98
import sqlite3
@@ -65,7 +64,7 @@
6564
from pandas.io.stata import StataReader
6665

6766
DF = DataFrame({"a": [1, 2, 3], "b": [0.0, 0.0, 0.0]})
68-
CWD = os.path.split(os.path.abspath(__file__))[0]
67+
CWD = Path(__file__).parent.resolve()
6968

7069

7170
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
@@ -86,10 +85,10 @@ def test_orc_path() -> None:
8685
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
8786
def test_orc_buffer() -> None:
8887
with ensure_clean() as path:
89-
with open(path, "wb") as file_w:
88+
with Path(path).open("wb") as file_w:
9089
check(assert_type(DF.to_orc(file_w), None), type(None))
9190

92-
with open(path, "rb") as file_r:
91+
with Path(path).open("rb") as file_r:
9392
check(assert_type(read_orc(file_r), DataFrame), DataFrame)
9493

9594

@@ -109,7 +108,7 @@ def test_xml() -> None:
109108
with ensure_clean() as path:
110109
check(assert_type(DF.to_xml(path), None), type(None))
111110
check(assert_type(read_xml(path), DataFrame), DataFrame)
112-
with open(path, "rb") as f:
111+
with Path(path).open("rb") as f:
113112
check(assert_type(read_xml(f), DataFrame), DataFrame)
114113

115114

@@ -128,7 +127,7 @@ def test_pickle() -> None:
128127
def test_pickle_file_handle() -> None:
129128
with ensure_clean() as path:
130129
check(assert_type(DF.to_pickle(path), None), type(None))
131-
with open(path, "rb") as file:
130+
with Path(path).open("rb") as file:
132131
check(assert_type(read_pickle(file), Any), DataFrame)
133132

134133

@@ -562,9 +561,9 @@ def test_read_csv() -> None:
562561
with ensure_clean() as path:
563562
check(assert_type(DF.to_csv(path), None), type(None))
564563
check(assert_type(read_csv(path), DataFrame), DataFrame)
565-
with open(path) as csv_file:
564+
with Path(path).open() as csv_file:
566565
check(assert_type(read_csv(csv_file), DataFrame), DataFrame)
567-
with open(path) as csv_file:
566+
with Path(path).open() as csv_file:
568567
sio = io.StringIO(csv_file.read())
569568
check(assert_type(read_csv(sio), DataFrame), DataFrame)
570569
check(assert_type(read_csv(path, iterator=False), DataFrame), DataFrame)
@@ -917,15 +916,15 @@ def test_btest_read_fwf() -> None:
917916
check(assert_type(read_fwf(path), DataFrame), DataFrame)
918917
check(assert_type(read_fwf(pathlib.Path(path)), DataFrame), DataFrame)
919918

920-
with open(path) as fwf_file:
919+
with Path(path).open() as fwf_file:
921920
check(
922921
assert_type(read_fwf(fwf_file), DataFrame),
923922
DataFrame,
924923
)
925-
with open(path) as fwf_file:
924+
with Path(path).open() as fwf_file:
926925
sio = io.StringIO(fwf_file.read())
927926
check(assert_type(read_fwf(sio), DataFrame), DataFrame)
928-
with open(path, "rb") as fwf_file:
927+
with Path(path).open("rb") as fwf_file:
929928
bio = io.BytesIO(fwf_file.read())
930929
check(assert_type(read_fwf(bio), DataFrame), DataFrame)
931930
with read_fwf(path, iterator=True) as fwf_iterator:
@@ -1228,7 +1227,7 @@ def test_to_string() -> None:
12281227
with ensure_clean() as path:
12291228
check(assert_type(DF.to_string(path), None), type(None))
12301229
check(assert_type(DF.to_string(pathlib.Path(path)), None), type(None))
1231-
with open(path, "w") as df_string:
1230+
with Path(path).open("w") as df_string:
12321231
check(assert_type(DF.to_string(df_string), None), type(None))
12331232
sio = io.StringIO()
12341233
check(assert_type(DF.to_string(sio), None), type(None))

tests/test_styler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

3-
import os
4-
import pathlib
3+
from pathlib import Path
54
from typing import TYPE_CHECKING
65

76
from jinja2.environment import (
@@ -31,7 +30,7 @@
3130

3231
DF = DataFrame({"a": [1, 2, 3], "b": [3.14, 2.72, 1.61]})
3332

34-
PWD = pathlib.Path(os.path.split(os.path.abspath(__file__))[0])
33+
PWD = Path(__file__).parent.resolve()
3534

3635
if TYPE_CHECKING:
3736
from pandas.io.formats.style_render import StyleExportDict

tests/test_testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import os.path
3+
from pathlib import Path
44

55
import pandas as pd
66
from pandas.testing import (
@@ -62,4 +62,4 @@ def test_ensure_clean() -> None:
6262
with ensure_clean() as path:
6363
check(assert_type(path, str), str)
6464
pd.DataFrame({"x": [1, 2, 3]}).to_csv(path)
65-
assert not os.path.exists(path)
65+
assert not Path(path).exists()

0 commit comments

Comments
 (0)