Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 30 additions & 2 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -698,16 +698,44 @@ 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[True],
**kwargs: Any,
) -> 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 query(
self,
expr: _str,
*,
inplace: Literal[False] = ...,
**kwargs: Any,
) -> Self: ...
@overload
def eval(self, expr: _str, *, inplace: Literal[True], **kwargs: Any) -> None: ...
Expand Down
23 changes: 23 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,29 @@ 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"), pd.DataFrame
),
pd.DataFrame,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

kwargs = {"parser": "pandas", "engine": "numexpr"}
check(
assert_type(df.query("col1 > col2", inplace=False, **kwargs), pd.DataFrame),
pd.DataFrame,
)

check(assert_type(df.query("col1 % col2 == 0", 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