Skip to content

Commit b3cf1f8

Browse files
committed
pyrefly
1 parent 1888528 commit b3cf1f8

10 files changed

Lines changed: 38 additions & 20 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
- id: ruff-check
99
args: [--exit-non-zero-on-fix]
1010
- repo: https://github.com/codespell-project/codespell
11-
rev: v2.4.2
11+
rev: v2.4.3
1212
hooks:
1313
- id: codespell
1414
args: [-L, "THIRDPARTY"]

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import numpy as np
1818
from pandas import Timestamp
1919

2020
from pandas._typing import (
21+
Frequency,
2122
ShapeT,
2223
np_ndarray_object,
2324
)
@@ -104,6 +105,11 @@ class BaseOffset:
104105

105106
class SingleConstructorOffset(BaseOffset): ...
106107

108+
@overload
109+
def to_offset(freq: None, is_period: bool = False) -> None: ...
110+
@overload
111+
def to_offset(freq: Frequency | timedelta, is_period: bool = False) -> BaseOffset: ...
112+
107113
class Tick(SingleConstructorOffset):
108114
def __init__(self, n: int = ..., normalize: bool = ...) -> None: ...
109115
@property

pandas-stubs/core/series.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ from pandas.core.window.rolling import (
128128
Rolling,
129129
Window,
130130
)
131+
from typing_extensions import override
131132
import xarray as xr
132133

133134
from pandas._libs.interval import Interval
@@ -1874,7 +1875,8 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
18741875
@final
18751876
def last_valid_index(self) -> Scalar: ...
18761877
@overload
1877-
def value_counts( # pyrefly: ignore
1878+
@override
1879+
def value_counts(
18781880
self,
18791881
normalize: Literal[False] = False,
18801882
sort: _bool = ...,
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
from datetime import timedelta
2-
from typing import overload
1+
from pandas.core.indexes.datetimes import DatetimeIndex
2+
from pandas.core.indexes.timedeltas import TimedeltaIndex
3+
from pandas.core.series import Series
34

4-
from pandas import (
5-
DatetimeIndex,
6-
Series,
7-
TimedeltaIndex,
8-
)
5+
from pandas._libs.tslibs.offsets import to_offset as to_offset
96

10-
from pandas._typing import Frequency
11-
12-
from pandas.tseries.offsets import BaseOffset
13-
14-
@overload
15-
def to_offset(freq: None, is_period: bool = False) -> None: ...
16-
@overload
17-
def to_offset(freq: Frequency | timedelta, is_period: bool = False) -> BaseOffset: ...
187
def infer_freq(index: Series | DatetimeIndex | TimedeltaIndex) -> str | None: ...

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,12 @@ filterwarnings = [
347347
project-includes = ["pandas-stubs", "tests"]
348348
enabled-ignores = ["pyrefly"]
349349
python-version = "3.11"
350+
min-severity = "warn"
350351

351352
[tool.pyrefly.errors]
352353
explicit-any = false # We do use implicit Any
353354
implicit-any-type-argument = false # We do use implicit Any
355+
implicit-bool = false # We do use implicit bool
354356
untyped-import = false # Import discovery
355357

356358
[tool.ty.environment]

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ def check(
9191
value: Any
9292
if isinstance(actual, pd.Series):
9393
# cast is by design microsoft/pyright#11191
94+
# pyrefly: ignore[redundant-cast]
9495
value = cast(pd.Series, actual).iloc[index_to_check_for_type]
9596
elif isinstance(actual, pd.Index):
97+
# pyrefly: ignore[redundant-cast]
9698
# cast is by design microsoft/pyright#11191
9799
value = cast(pd.Index, actual)[index_to_check_for_type]
98100
elif isinstance(actual, BaseGroupBy):

tests/frame/test_frame.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ def test_assign() -> None:
297297
df = pd.DataFrame({"a": [1, 2, 3], 1: [4, 5, 6]})
298298

299299
my_unnamed_func = ( # pyright: ignore[reportUnknownVariableType]
300-
lambda df: df["a"] * 2 # pyright: ignore[reportUnknownLambdaType]
300+
lambda df: df[ # pyright: ignore[reportUnknownLambdaType] # pyrefly: ignore[implicit-any-lambda]
301+
"a"
302+
]
303+
* 2
301304
)
302305

303306
def my_named_func_1(df: pd.DataFrame) -> pd.Series[str]:
@@ -4572,12 +4575,14 @@ def func_e(x: pd.DataFrame, k: int) -> pd.Series:
45724575
return x.max() - k * x.min()
45734576

45744577
check(
4578+
# pyrefly: ignore[implicity-any-lambda]
45754579
assert_type(df.rolling(2).pipe(lambda x: x.min() - x.max()), pd.DataFrame),
45764580
pd.DataFrame,
45774581
)
45784582
check(assert_type(df.rolling(2).pipe(func_r, k=2), pd.DataFrame), pd.DataFrame)
45794583

45804584
check(
4585+
# pyrefly: ignore[implicity-any-lambda]
45814586
assert_type(df.expanding().pipe(lambda x: x.min() - x.max()), pd.DataFrame),
45824587
pd.DataFrame,
45834588
)

tests/test_groupby.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def df2series(val: DataFrame) -> Series:
156156
return val.mean()
157157

158158
def df2scalar(val: DataFrame) -> float:
159+
# pyrefly: ignore[unnecessary-type-conversion]
159160
return float(val.mean().mean())
160161

161162
check(assert_type(GB_DF.resample("ME").aggregate(np.sum), DataFrame), DataFrame)
@@ -245,6 +246,7 @@ def h(val: Resampler[DataFrame]) -> Series:
245246

246247
def i(val: Resampler[DataFrame]) -> float:
247248
assert isinstance(val, Resampler)
249+
# pyrefly: ignore[unnecessary-type-conversion]
248250
return float(val.mean().mean().mean())
249251

250252
check(assert_type(GB_DF.resample("ME").pipe(i), float), float)
@@ -367,6 +369,7 @@ def f(val: Series) -> float:
367369
# pipe
368370
def g(val: Resampler[Series]) -> float:
369371
assert isinstance(val, Resampler)
372+
# pyrefly: ignore[unnecessary-type-conversion]
370373
return float(val.mean().mean())
371374

372375
check(assert_type(GB_S.resample("ME").pipe(g), float), float)
@@ -382,6 +385,7 @@ def s2series(val: Series) -> Series:
382385
return Series(val)
383386

384387
def s2scalar(val: Series) -> float:
388+
# pyrefly: ignore[unnecessary-type-conversion]
385389
return float(val.mean())
386390

387391
check(assert_type(GB_S.resample("ME").aggregate(np.sum), Series), Series)
@@ -477,6 +481,7 @@ def df2series(val: DataFrame) -> Series:
477481
return val.mean()
478482

479483
def df2scalar(val: DataFrame) -> float:
484+
# pyrefly: ignore[unnecessary-type-conversion]
480485
return float(val.mean().mean())
481486

482487
check(assert_type(GB_DF.rolling(1).aggregate(np.sum), DataFrame), DataFrame)
@@ -578,6 +583,7 @@ def f(val: Series) -> float:
578583
check(assert_type(GB_S.rolling(1).aggregate(f), Series), Series)
579584

580585
def s2scalar(val: Series) -> float:
586+
# pyrefly: ignore[unnecessary-type-conversion]
581587
return float(val.mean())
582588

583589
check(assert_type(GB_S.rolling(1).aggregate(s2scalar), Series), Series)
@@ -652,6 +658,7 @@ def df2series(val: DataFrame) -> Series:
652658
return val.mean()
653659

654660
def df2scalar(val: DataFrame) -> float:
661+
# pyrefly: ignore[unnecessary-type-conversion]
655662
return float(val.mean().mean())
656663

657664
check(assert_type(GB_DF.expanding(1).aggregate(np.sum), DataFrame), DataFrame)
@@ -757,6 +764,7 @@ def f(val: Series) -> float:
757764
check(assert_type(GB_S.expanding(1).aggregate(f), Series), Series)
758765

759766
def s2scalar(val: Series) -> float:
767+
# pyrefly: ignore[unnecessary-type-conversion]
760768
return float(val.mean())
761769

762770
check(assert_type(GB_S.expanding(1).aggregate(s2scalar), Series), Series)

tests/test_resampler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def h(val: "DatetimeIndexResampler[DataFrame]") -> Series:
160160

161161
def i(val: "DatetimeIndexResampler[DataFrame]") -> float:
162162
assert isinstance(val, DatetimeIndexResampler)
163+
# pyrefly: ignore[unnecessary-type-conversion]
163164
return float(val.mean().mean().mean())
164165

165166
check(assert_type(DF.resample("ME").pipe(i), float), float)
@@ -304,6 +305,7 @@ def f(val: "DatetimeIndexResampler[Series]") -> Series:
304305

305306
def g(val: "DatetimeIndexResampler[Series]") -> float:
306307
assert isinstance(val, DatetimeIndexResampler)
308+
# pyrefly: ignore[unnecessary-type-conversion]
307309
return float(val.mean().mean())
308310

309311
check(assert_type(S.resample("ME").pipe(g), float), float)
@@ -327,6 +329,7 @@ def s2series(val: Series) -> Series:
327329
return Series(val)
328330

329331
def s2scalar(val: Series) -> float:
332+
# pyrefly: ignore[unnecessary-type-conversion]
330333
return float(val.mean())
331334

332335
check(assert_type(S.resample("ME").aggregate(np.sum), Series), Series)
@@ -361,6 +364,7 @@ def df2series(val: DataFrame) -> Series:
361364
return val.mean()
362365

363366
def df2scalar(val: DataFrame) -> float:
367+
# pyrefly: ignore[unnecessary-type-conversion]
364368
return float(val.mean().mean())
365369

366370
check(assert_type(DF.resample("ME").aggregate(np.sum), DataFrame), DataFrame)

tests/test_typing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def _to_type(t: Any) -> type:
4242
if isinstance(t, ExtensionDtype):
4343
return type(t)
4444
if issubclass(type(t), np.dtype):
45-
return t.type # type: ignore[no-any-return]
46-
return t # type: ignore[no-any-return]
45+
return t.type # type: ignore[no-any-return] # pyrefly: ignore[no-any-return-explicit]
46+
return t # type: ignore[no-any-return] # pyrefly: ignore[no-any-return-explicit]
4747

4848

4949
@pytest.mark.parametrize(("dtype_arg", "alias_map"), DTYPE_ARG_ALIAS_MAPS.items())

0 commit comments

Comments
 (0)