Skip to content

Commit 1ce8906

Browse files
GH1173 Experiment with fuller typing (#1193)
* GH1173 Experiment with fuller typing * GH1173 PR feedback * GH1173 PR feedback * GH1173 PR Feedback * GH1173 PR Feedback
1 parent ce8c7b6 commit 1ce8906

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

‎pandas-stubs/core/frame.pyi

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,16 +698,28 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
698698
self,
699699
expr: _str,
700700
*,
701+
parser: Literal["pandas", "python"] = ...,
702+
engine: Literal["python", "numexpr"] | None = ...,
703+
local_dict: dict[_str, Any] | None = ...,
704+
global_dict: dict[_str, Any] | None = ...,
705+
resolvers: list[Mapping] | None = ...,
706+
level: int = ...,
707+
target: object | None = ...,
701708
inplace: Literal[True],
702-
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1173
703709
) -> None: ...
704710
@overload
705711
def query(
706712
self,
707713
expr: _str,
708714
*,
709715
inplace: Literal[False] = ...,
710-
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1173
716+
parser: Literal["pandas", "python"] = ...,
717+
engine: Literal["python", "numexpr"] | None = ...,
718+
local_dict: dict[_str, Any] | None = ...,
719+
global_dict: dict[_str, Any] | None = ...,
720+
resolvers: list[Mapping] | None = ...,
721+
level: int = ...,
722+
target: object | None = ...,
711723
) -> Self: ...
712724
@overload
713725
def eval(self, expr: _str, *, inplace: Literal[True], **kwargs: Any) -> None: ...

‎tests/test_frame.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,23 @@ def test_types_query() -> None:
514514
check(assert_type(df.query("col1 % col2 == 0", inplace=True), None), type(None))
515515

516516

517+
def test_types_query_kwargs() -> None:
518+
df = pd.DataFrame(data={"col1": [1, 2, 3, 4], "col2": [3, 0, 1, 7]})
519+
check(
520+
assert_type(
521+
df.query("col1 > col2", parser="pandas", engine="numexpr"), pd.DataFrame
522+
),
523+
pd.DataFrame,
524+
)
525+
check(
526+
assert_type(
527+
df.query("col1 > col2", parser="pandas", engine="numexpr", inplace=True),
528+
None,
529+
),
530+
type(None),
531+
)
532+
533+
517534
def test_types_eval() -> None:
518535
df = pd.DataFrame(data={"col1": [1, 2, 3, 4], "col2": [3, 0, 1, 7]})
519536
check(assert_type(df.eval("E = col1 > col2", inplace=True), None), type(None))

0 commit comments

Comments
 (0)