From 4f4d6b166e6986bfd3d7031376a2cb5878fa0be8 Mon Sep 17 00:00:00 2001 From: preetham Date: Thu, 6 Feb 2025 17:57:08 +0530 Subject: [PATCH] Fix: Add error handling for query with duplicate columns --- pandas/core/frame.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 72fc099f57599..d38636ca06ffc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4616,6 +4616,8 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No 0 1 10 10 1 2 8 9 """ + if self.columns.duplicated().any(): + raise ValueError("DataFrame contains duplicate column names.") inplace = validate_bool_kwarg(inplace, "inplace") if not isinstance(expr, str): msg = f"expr must be a string to be evaluated, {type(expr)} given"