Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyrightconfig-strict.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"enableTypeIgnoreComments": false,
"reportUnnecessaryTypeIgnoreComment": true,
"reportMissingModuleSource": true,
"useLibraryCodeForTypes": false
"useLibraryCodeForTypes": false,
"reportUnknownLambdaType": false
}
2 changes: 1 addition & 1 deletion scripts/_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Step:
rollback: Callable[[], None] | None = None


def __rollback_job(steps: deque[Step]):
def __rollback_job(steps: deque[Step]) -> None:
"""
Responsible to run rollback of steps.
"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test(
src: bool = False,
dist: bool = False,
type_checker: Literal["", "mypy", "pyright"] = "",
):
) -> None:
steps = []
if src:
steps.extend(_SRC_STEPS)
Expand Down
38 changes: 19 additions & 19 deletions scripts/test/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@
import sys


def mypy_src():
def mypy_src() -> None:
cmd = ["mypy", "pandas-stubs", "tests", "--no-incremental"]
subprocess.run(cmd, check=True)


def pyright_src():
def pyright_src() -> None:
cmd = ["pyright"]
subprocess.run(cmd, check=True)


def pyright_src_strict():
def pyright_src_strict() -> None:
cmd = ["pyright", "--project", "pyrightconfig-strict.json"]
subprocess.run(cmd, check=True)


def pytest():
def pytest() -> None:
cmd = ["pytest", "--cache-clear"]
subprocess.run(cmd, check=True)


def style():
def style() -> None:
cmd = ["pre-commit", "run", "--all-files", "--verbose"]
subprocess.run(cmd, check=True)


def stubtest(allowlist: str = "", check_missing: bool = False):
def stubtest(allowlist: str = "", check_missing: bool = False) -> None:
cmd = [
sys.executable,
"-m",
Expand All @@ -47,47 +47,47 @@ def stubtest(allowlist: str = "", check_missing: bool = False):
subprocess.run(cmd, check=True)


def build_dist():
def build_dist() -> None:
cmd = ["poetry", "build", "-f", "wheel"]
subprocess.run(cmd, check=True)


def install_dist():
def install_dist() -> None:
path = sorted(Path("dist/").glob("pandas_stubs-*.whl"))[-1]
cmd = [sys.executable, "-m", "pip", "install", "--force-reinstall", str(path)]
subprocess.run(cmd, check=True)


def rename_src():
def rename_src() -> None:
if Path(r"pandas-stubs").exists():
Path(r"pandas-stubs").rename("_pandas-stubs")
else:
raise FileNotFoundError("'pandas-stubs' folder does not exists.")


def mypy_dist():
def mypy_dist() -> None:
cmd = ["mypy", "tests", "--no-incremental"]
subprocess.run(cmd, check=True)


def pyright_dist():
def pyright_dist() -> None:
cmd = ["pyright", "tests"]
subprocess.run(cmd, check=True)


def uninstall_dist():
def uninstall_dist() -> None:
cmd = [sys.executable, "-m", "pip", "uninstall", "-y", "pandas-stubs"]
subprocess.run(cmd, check=True)


def restore_src():
def restore_src() -> None:
if Path(r"_pandas-stubs").exists():
Path(r"_pandas-stubs").rename("pandas-stubs")
else:
raise FileNotFoundError("'_pandas-stubs' folder does not exists.")


def nightly_pandas():
def nightly_pandas() -> None:
cmd = [
sys.executable,
"-m",
Expand All @@ -110,13 +110,13 @@ def _get_version_from_pyproject(program: str) -> str:
return version_line.split('"')[1]


def released_pandas():
def released_pandas() -> None:
version = _get_version_from_pyproject("pandas")
cmd = [sys.executable, "-m", "pip", "install", f"pandas=={version}"]
subprocess.run(cmd, check=True)


def nightly_mypy():
def nightly_mypy() -> None:
cmd = [
sys.executable,
"-m",
Expand All @@ -138,7 +138,7 @@ def nightly_mypy():
)


def released_mypy():
def released_mypy() -> None:
version = _get_version_from_pyproject("mypy")
cmd = [sys.executable, "-m", "pip", "install", f"mypy=={version}"]
subprocess.run(cmd, check=True)
Expand All @@ -152,7 +152,7 @@ def released_mypy():
)


def ty():
def ty() -> None:
cmd = [
"ty",
"check",
Expand All @@ -163,6 +163,6 @@ def ty():
subprocess.run(cmd, check=True)


def pyrefly():
def pyrefly() -> None:
cmd = ["pyrefly", "check", "pandas-stubs"]
subprocess.run(cmd, check=True)
20 changes: 10 additions & 10 deletions tests/indexes/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_index_rename_inplace() -> None:
assert ind2 is None


def test_index_dropna():
def test_index_dropna() -> None:
idx = pd.Index([1, 2])

check(assert_type(idx.dropna(how="all"), "pd.Index[int]"), pd.Index)
Expand All @@ -235,7 +235,7 @@ def test_index_dropna():
check(assert_type(midx.dropna(how="any"), pd.MultiIndex), pd.MultiIndex)


def test_index_neg():
def test_index_neg() -> None:
# GH 253
idx = pd.Index([1, 2])
check(assert_type(-idx, "pd.Index[int]"), pd.Index)
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_index_relops() -> None:
check(assert_type(ind > 2, np_1darray[np.bool]), np_1darray[np.bool])


def test_range_index_union():
def test_range_index_union() -> None:
check(
assert_type(
pd.RangeIndex(0, 10).union(pd.RangeIndex(10, 20)),
Expand Down Expand Up @@ -342,14 +342,14 @@ def test_index_union_sort() -> None:
)


def test_range_index_start_stop_step():
def test_range_index_start_stop_step() -> None:
idx = pd.RangeIndex(3)
check(assert_type(idx.start, int), int)
check(assert_type(idx.stop, int), int)
check(assert_type(idx.step, int), int)


def test_interval_range():
def test_interval_range() -> None:
check(
assert_type(pd.interval_range(0, 10), "pd.IntervalIndex[pd.Interval[int]]"),
pd.IntervalIndex,
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_interval_range():
)


def test_interval_index_breaks():
def test_interval_index_breaks() -> None:
check(
assert_type(
pd.IntervalIndex.from_breaks([1, 2, 3, 4]),
Expand Down Expand Up @@ -632,7 +632,7 @@ def test_interval_index_breaks():
)


def test_interval_index_arrays():
def test_interval_index_arrays() -> None:
check(
assert_type(
pd.IntervalIndex.from_arrays([1, 2, 3, 4], [2, 3, 4, 5]),
Expand Down Expand Up @@ -761,7 +761,7 @@ def test_interval_index_arrays():
)


def test_interval_index_tuples():
def test_interval_index_tuples() -> None:
check(
assert_type(
pd.IntervalIndex.from_tuples([(1, 2), (2, 3)]),
Expand Down Expand Up @@ -1082,13 +1082,13 @@ def test_range_index_range() -> None:
check(assert_type(iri, pd.RangeIndex), pd.RangeIndex, int)


def test_multiindex_dtypes():
def test_multiindex_dtypes() -> None:
# GH-597
mi = pd.MultiIndex.from_tuples([(1, 2.0), (2, 3.0)], names=["foo", "bar"])
check(assert_type(mi.dtypes, "pd.Series[Dtype]"), pd.Series)


def test_index_constructors():
def test_index_constructors() -> None:
# See if we can pick up the different index types in 2.0
# Eventually should be using a generic index
ilist = [1, 2, 3]
Expand Down
2 changes: 1 addition & 1 deletion tests/scalars/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_interval_math() -> None:
) # pyright: ignore[reportOperatorIssue]


def test_interval_cmp():
def test_interval_cmp() -> None:
interval_i = pd.Interval(0, 1, closed="left")
interval_f = pd.Interval(0.0, 1.0, closed="right")
interval_ts = pd.Interval(
Expand Down
6 changes: 3 additions & 3 deletions tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ def test_types_to_dict() -> None:
assert_type(s.to_dict(), dict[Any, str])


def test_categorical_codes():
def test_categorical_codes() -> None:
# GH-111
cat = pd.Categorical(["a", "b", "a"])
check(assert_type(cat.codes, np_1darray[np.signedinteger]), np_1darray[np.int8])
Expand Down Expand Up @@ -1942,7 +1942,7 @@ def test_squeeze() -> None:
check(assert_type(s2.squeeze(), "pd.Series[int] | Scalar"), np.integer)


def test_to_xarray():
def test_to_xarray() -> None:
s = pd.Series([1, 2])
check(assert_type(s.to_xarray(), xr.DataArray), xr.DataArray)

Expand Down Expand Up @@ -3549,7 +3549,7 @@ def test_diff() -> None:
# str -> TypeError: unsupported operand type(s) for -: 'str' and 'str'
pd.Series(["a", "b"]).diff() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue]

def _diff_invalid0(): # pyright: ignore[reportUnusedFunction]
def _diff_invalid0() -> None: # pyright: ignore[reportUnusedFunction]
# interval -> TypeError: IntervalArray has no 'diff' method. Convert to a suitable dtype prior to calling 'diff'.
assert_type(pd.Series([pd.Interval(0, 2), pd.Interval(1, 4)]).diff(), Never)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def test_union_categoricals() -> None:

def test_check_extension_dtypes() -> None:
# GH 315
def check_ext_dtype(etype: type[ExtensionDtype]):
def check_ext_dtype(etype: type[ExtensionDtype]) -> None:
assert issubclass(etype, ExtensionDtype)

check_ext_dtype(pd.Int64Dtype)
Expand Down
Loading