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
16 changes: 14 additions & 2 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -698,16 +698,28 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
expr: _str,
*,
parser: Literal["pandas", "python"] = ...,
engine: Literal["python", "numexpr"] | None = ...,
local_dict: dict[_str, Any] | None = ...,
global_dict: dict[_str, Any] | None = ...,
resolvers: list[Mapping] | None = ...,
level: int = ...,
target: object | None = ...,
inplace: Literal[True],
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1173
) -> None: ...
@overload
def query(
self,
expr: _str,
*,
inplace: Literal[False] = ...,
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1173
parser: Literal["pandas", "python"] = ...,
engine: Literal["python", "numexpr"] | None = ...,
local_dict: dict[_str, Any] | None = ...,
global_dict: dict[_str, Any] | None = ...,
resolvers: list[Mapping] | None = ...,
level: int = ...,
target: object | None = ...,
) -> Self: ...
@overload
def eval(self, expr: _str, *, inplace: Literal[True], **kwargs: Any) -> None: ...
Expand Down
17 changes: 17 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,23 @@ def test_types_query() -> None:
check(assert_type(df.query("col1 % col2 == 0", inplace=True), None), type(None))


def test_types_query_kwargs() -> None:
df = pd.DataFrame(data={"col1": [1, 2, 3, 4], "col2": [3, 0, 1, 7]})
check(
assert_type(
df.query("col1 > col2", parser="pandas", engine="numexpr"), pd.DataFrame
),
pd.DataFrame,
)
check(
assert_type(
df.query("col1 > col2", parser="pandas", engine="numexpr", inplace=True),
None,
),
type(None),
)


def test_types_eval() -> None:
df = pd.DataFrame(data={"col1": [1, 2, 3, 4], "col2": [3, 0, 1, 7]})
check(assert_type(df.eval("E = col1 > col2", inplace=True), None), type(None))
Expand Down