Skip to content

Commit c460710

Browse files
Revert "enable multivalues insert (pandas-dev#19664)" (pandas-dev#21355)
This reverts commit 7c7bd56.
1 parent 649bfae commit c460710

File tree

4 files changed

+7
-57
lines changed

4 files changed

+7
-57
lines changed

doc/source/io.rst

-6
Original file line numberDiff line numberDiff line change
@@ -4719,12 +4719,6 @@ writes ``data`` to the database in batches of 1000 rows at a time:
47194719
47204720
data.to_sql('data_chunked', engine, chunksize=1000)
47214721
4722-
.. note::
4723-
4724-
The function :func:`~pandas.DataFrame.to_sql` will perform a multi-value
4725-
insert if the engine dialect ``supports_multivalues_insert``. This will
4726-
greatly speed up the insert in some cases.
4727-
47284722
SQL data types
47294723
++++++++++++++
47304724

doc/source/whatsnew/v0.23.1.txt

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and bug fixes. We recommend that all users upgrade to this version.
1616
Fixed Regressions
1717
~~~~~~~~~~~~~~~~~
1818

19+
20+
- Reverted the ability of :func:`~DataFrame.to_sql` to perform multivalue
21+
inserts as this caused regression in certain cases (:issue:`21103`).
22+
In the future this will be made configurable.
1923
- Fixed regression in the :attr:`DatetimeIndex.date` and :attr:`DatetimeIndex.time`
2024
attributes in case of timezone-aware data: :attr:`DatetimeIndex.time` returned
2125
a tz-aware time instead of tz-naive (:issue:`21267`) and :attr:`DatetimeIndex.date`

pandas/io/sql.py

+3-25
Original file line numberDiff line numberDiff line change
@@ -572,29 +572,8 @@ def create(self):
572572
else:
573573
self._execute_create()
574574

575-
def insert_statement(self, data, conn):
576-
"""
577-
Generate tuple of SQLAlchemy insert statement and any arguments
578-
to be executed by connection (via `_execute_insert`).
579-
580-
Parameters
581-
----------
582-
conn : SQLAlchemy connectable(engine/connection)
583-
Connection to recieve the data
584-
data : list of dict
585-
The data to be inserted
586-
587-
Returns
588-
-------
589-
SQLAlchemy statement
590-
insert statement
591-
*, optional
592-
Additional parameters to be passed when executing insert statement
593-
"""
594-
dialect = getattr(conn, 'dialect', None)
595-
if dialect and getattr(dialect, 'supports_multivalues_insert', False):
596-
return self.table.insert(data),
597-
return self.table.insert(), data
575+
def insert_statement(self):
576+
return self.table.insert()
598577

599578
def insert_data(self):
600579
if self.index is not None:
@@ -633,9 +612,8 @@ def insert_data(self):
633612
return column_names, data_list
634613

635614
def _execute_insert(self, conn, keys, data_iter):
636-
"""Insert data into this table with database connection"""
637615
data = [{k: v for k, v in zip(keys, row)} for row in data_iter]
638-
conn.execute(*self.insert_statement(data, conn))
616+
conn.execute(self.insert_statement(), data)
639617

640618
def insert(self, chunksize=None):
641619
keys, data_list = self.insert_data()

pandas/tests/io/test_sql.py

-26
Original file line numberDiff line numberDiff line change
@@ -1665,29 +1665,6 @@ class Temporary(Base):
16651665

16661666
tm.assert_frame_equal(df, expected)
16671667

1668-
def test_insert_multivalues(self):
1669-
# issues addressed
1670-
# https://github.com/pandas-dev/pandas/issues/14315
1671-
# https://github.com/pandas-dev/pandas/issues/8953
1672-
1673-
db = sql.SQLDatabase(self.conn)
1674-
df = DataFrame({'A': [1, 0, 0], 'B': [1.1, 0.2, 4.3]})
1675-
table = sql.SQLTable("test_table", db, frame=df)
1676-
data = [
1677-
{'A': 1, 'B': 0.46},
1678-
{'A': 0, 'B': -2.06}
1679-
]
1680-
statement = table.insert_statement(data, conn=self.conn)[0]
1681-
1682-
if self.supports_multivalues_insert:
1683-
assert statement.parameters == data, (
1684-
'insert statement should be multivalues'
1685-
)
1686-
else:
1687-
assert statement.parameters is None, (
1688-
'insert statement should not be multivalues'
1689-
)
1690-
16911668

16921669
class _TestSQLAlchemyConn(_EngineToConnMixin, _TestSQLAlchemy):
16931670

@@ -1702,7 +1679,6 @@ class _TestSQLiteAlchemy(object):
17021679
17031680
"""
17041681
flavor = 'sqlite'
1705-
supports_multivalues_insert = True
17061682

17071683
@classmethod
17081684
def connect(cls):
@@ -1751,7 +1727,6 @@ class _TestMySQLAlchemy(object):
17511727
17521728
"""
17531729
flavor = 'mysql'
1754-
supports_multivalues_insert = True
17551730

17561731
@classmethod
17571732
def connect(cls):
@@ -1821,7 +1796,6 @@ class _TestPostgreSQLAlchemy(object):
18211796
18221797
"""
18231798
flavor = 'postgresql'
1824-
supports_multivalues_insert = True
18251799

18261800
@classmethod
18271801
def connect(cls):

0 commit comments

Comments
 (0)