From 47890ece0b85503ea12e997d3e73e939fab24b80 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 31 Oct 2020 14:43:22 +0100 Subject: [PATCH 1/6] remove no parameters --- pandas/io/sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 51888e5021d80..ed4ae877235c9 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1159,7 +1159,7 @@ def run_transaction(self): def execute(self, *args, **kwargs): """Simple passthrough to SQLAlchemy connectable""" - return self.connectable.execution_options(no_parameters=True).execute( + return self.connectable.execution_options().execute( *args, **kwargs ) From 766b2d95b97193d542a346e7b8b0a2350a68e48a Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 31 Oct 2020 14:45:58 +0100 Subject: [PATCH 2/6] changes black --- pandas/io/sql.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index ed4ae877235c9..465ff352895f9 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1159,9 +1159,7 @@ def run_transaction(self): def execute(self, *args, **kwargs): """Simple passthrough to SQLAlchemy connectable""" - return self.connectable.execution_options().execute( - *args, **kwargs - ) + return self.connectable.execution_options().execute(*args, **kwargs) def read_table( self, From 9dd5ec981fe9d92a55e892b195681c8506e69cf0 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 1 Nov 2020 13:46:48 +0100 Subject: [PATCH 3/6] add test for column percentage --- pandas/tests/io/test_sql.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 19eb64be1be29..a640b927c0241 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -952,7 +952,6 @@ def test_escaped_table_name(self): tm.assert_frame_equal(res, df) - @pytest.mark.single @pytest.mark.skipif(not SQLALCHEMY_INSTALLED, reason="SQLAlchemy not installed") class TestSQLApi(SQLAlchemyMixIn, _TestSQLApi): @@ -1118,6 +1117,15 @@ def test_query_by_select_obj(self): all_names = set(iris_df["Name"]) assert all_names == {"Iris-setosa"} + def test_column_with_percentage(self): + # GH 37157 + df = DataFrame({"A": [0, 1, 2], "%_variation": [3, 4, 5]}) + df.to_sql("test_column_percentage", self.conn, index=False) + + res = sql.read_sql_table("test_column_percentage", self.conn) + + tm.assert_frame_equal(res, df) + class _EngineToConnMixin: """ From c8fdd2b5210c6f637a4b844ce33baf1206ba4550 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 1 Nov 2020 13:49:16 +0100 Subject: [PATCH 4/6] add blank line --- pandas/tests/io/test_sql.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index a640b927c0241..78306d4b6c244 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -952,6 +952,7 @@ def test_escaped_table_name(self): tm.assert_frame_equal(res, df) + @pytest.mark.single @pytest.mark.skipif(not SQLALCHEMY_INSTALLED, reason="SQLAlchemy not installed") class TestSQLApi(SQLAlchemyMixIn, _TestSQLApi): From abb3abcaa0ba035ceeb8add0a2a0adcd2f56fb9f Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 1 Nov 2020 13:54:48 +0100 Subject: [PATCH 5/6] added whatsnew entry --- doc/source/whatsnew/v1.1.5.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.1.5.rst b/doc/source/whatsnew/v1.1.5.rst index cf728d94b2a55..1d6e5d7a5ab6e 100644 --- a/doc/source/whatsnew/v1.1.5.rst +++ b/doc/source/whatsnew/v1.1.5.rst @@ -14,8 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ -- -- +- Fixed regression in :func:`read_sql_table` raising a ``sqlalchemy.exc.OperationalError`` when column names contained a percentage sign (:issue:`37517`) .. --------------------------------------------------------------------------- From e4616879ac7a8a998f2ad9557bead81bb8d5b523 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 22 Dec 2020 13:26:34 +0100 Subject: [PATCH 6/6] moved to 1.2.0 and as bug --- doc/source/whatsnew/v1.1.5.rst | 1 - doc/source/whatsnew/v1.2.0.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.5.rst b/doc/source/whatsnew/v1.1.5.rst index 321be4cab5fa7..002e1f85f4127 100644 --- a/doc/source/whatsnew/v1.1.5.rst +++ b/doc/source/whatsnew/v1.1.5.rst @@ -29,7 +29,6 @@ Fixed regressions - Fixed performance regression in ``df.groupby(..).rolling(..)`` (:issue:`38038`) - Fixed regression in :meth:`MultiIndex.intersection` returning duplicates when at least one of the indexes had duplicates (:issue:`36915`) - Fixed regression in :meth:`.GroupBy.first` and :meth:`.GroupBy.last` where ``None`` was considered a non-NA value (:issue:`38286`) -- Fixed regression in :func:`read_sql_table` raising a ``sqlalchemy.exc.OperationalError`` when column names contained a percentage sign (:issue:`37517`) .. --------------------------------------------------------------------------- diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index bbdcd183f65e1..d34175b9c4feb 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -748,6 +748,7 @@ I/O - Bumped minimum xarray version to 0.12.3 to avoid reference to the removed ``Panel`` class (:issue:`27101`) - :meth:`DataFrame.to_csv` was re-opening file-like handles that also implement ``os.PathLike`` (:issue:`38125`) - Bug in the conversion of a sliced ``pyarrow.Table`` with missing values to a DataFrame (:issue:`38525`) +- Bug in :func:`read_sql_table` raising a ``sqlalchemy.exc.OperationalError`` when column names contained a percentage sign (:issue:`37517`) Period ^^^^^^