Skip to content

Commit 0d96e9b

Browse files
GH61405 Expose arguments in DataFrame.query
1 parent ddcec67 commit 0d96e9b

File tree

1 file changed

+58
-7
lines changed

1 file changed

+58
-7
lines changed

pandas/core/frame.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4477,18 +4477,62 @@ def _get_item(self, item: Hashable) -> Series:
44774477

44784478
@overload
44794479
def query(
4480-
self, expr: str, *, inplace: Literal[False] = ..., **kwargs
4480+
self,
4481+
expr: str,
4482+
*,
4483+
parser: Literal["pandas", "python"] = ...,
4484+
engine: Literal["python", "numexpr"] | None = ...,
4485+
local_dict: dict[str, Any] | None = ...,
4486+
global_dict: dict[str, Any] | None = ...,
4487+
resolvers: list[Mapping] | None = ...,
4488+
level: int = ...,
4489+
target: None = ...,
4490+
inplace: Literal[False] = ...,
44814491
) -> DataFrame: ...
44824492

44834493
@overload
4484-
def query(self, expr: str, *, inplace: Literal[True], **kwargs) -> None: ...
4494+
def query(
4495+
self,
4496+
expr: str,
4497+
*,
4498+
parser: Literal["pandas", "python"] = ...,
4499+
engine: Literal["python", "numexpr"] | None = ...,
4500+
local_dict: dict[str, Any] | None = ...,
4501+
global_dict: dict[str, Any] | None = ...,
4502+
resolvers: list[Mapping] | None = ...,
4503+
level: int = ...,
4504+
target: None = ...,
4505+
inplace: Literal[True],
4506+
) -> None: ...
44854507

44864508
@overload
44874509
def query(
4488-
self, expr: str, *, inplace: bool = ..., **kwargs
4510+
self,
4511+
expr: str,
4512+
*,
4513+
parser: Literal["pandas", "python"] = ...,
4514+
engine: Literal["python", "numexpr"] | None = ...,
4515+
local_dict: dict[str, Any] | None = ...,
4516+
global_dict: dict[str, Any] | None = ...,
4517+
resolvers: list[Mapping] | None = ...,
4518+
level: int = ...,
4519+
target: None = ...,
4520+
inplace: bool = ...,
44894521
) -> DataFrame | None: ...
44904522

4491-
def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | None:
4523+
def query(
4524+
self,
4525+
expr: str,
4526+
*,
4527+
parser: Literal["pandas", "python"] = ...,
4528+
engine: Literal["python", "numexpr"] | None = None,
4529+
local_dict: dict[str, Any] | None = None,
4530+
global_dict: dict[str, Any] | None = None,
4531+
resolvers: list[Mapping] | None = None,
4532+
level: int = 0,
4533+
target: None = None,
4534+
inplace: bool = False,
4535+
) -> DataFrame | None:
44924536
"""
44934537
Query the columns of a DataFrame with a boolean expression.
44944538
@@ -4624,10 +4668,17 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
46244668
if not isinstance(expr, str):
46254669
msg = f"expr must be a string to be evaluated, {type(expr)} given"
46264670
raise ValueError(msg)
4627-
kwargs["level"] = kwargs.pop("level", 0) + 1
4628-
kwargs["target"] = None
46294671

4630-
res = self.eval(expr, **kwargs)
4672+
res = self.eval(
4673+
expr,
4674+
parser,
4675+
engine,
4676+
local_dict,
4677+
global_dict,
4678+
resolvers,
4679+
level + 1,
4680+
target,
4681+
)
46314682

46324683
try:
46334684
result = self.loc[res]

0 commit comments

Comments
 (0)