Skip to content

Commit 222dff8

Browse files
jorisvandenbosscheTomAugspurger
authored andcommitted
Revert "enable multivalues insert (pandas-dev#19664)" (pandas-dev#21355)
This reverts commit 7c7bd56. (cherry picked from commit c460710)
1 parent 12e9ef6 commit 222dff8

File tree

4 files changed

+19
-72
lines changed

4 files changed

+19
-72
lines changed

doc/source/io.rst

-8
Original file line numberDiff line numberDiff line change
@@ -4719,14 +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 multivalue
4725-
insert if the engine dialect ``supports_multivalues_insert``. This will
4726-
greatly speed up the insert in some cases.
4727-
4728-
SQL data types
4729-
++++++++++++++
47304722
47314723
:func:`~pandas.DataFrame.to_sql` will try to map your data to an appropriate
47324724
SQL data type based on the dtype of the data. When you have columns of dtype

doc/source/whatsnew/v0.23.1.txt

+16-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ and bug fixes. We recommend that all users upgrade to this version.
1010
:local:
1111
:backlinks: none
1212

13-
.. _whatsnew_0231.enhancements:
14-
15-
New features
16-
~~~~~~~~~~~~
17-
18-
19-
.. _whatsnew_0231.deprecations:
20-
21-
Deprecations
22-
~~~~~~~~~~~~
23-
24-
-
25-
-
13+
.. _whatsnew_0231.fixed_regressions:
14+
15+
Fixed Regressions
16+
17+
- Reverted the ability of :func:`~DataFrame.to_sql` to perform multivalue
18+
inserts as this caused regression in certain cases (:issue:`21103`).
19+
In the future this will be made configurable.
20+
- Fixed regression in the :attr:`DatetimeIndex.date` and :attr:`DatetimeIndex.time`
21+
attributes in case of timezone-aware data: :attr:`DatetimeIndex.time` returned
22+
a tz-aware time instead of tz-naive (:issue:`21267`) and :attr:`DatetimeIndex.date`
23+
returned incorrect date when the input date has a non-UTC timezone (:issue:`21230`).
24+
- Fixed regression in :meth:`pandas.io.json.json_normalize` when called with ``None`` values
25+
in nested levels in JSON (:issue:`21158`).
26+
- Bug in :meth:`~DataFrame.to_csv` causes encoding error when compression and encoding are specified (:issue:`21241`, :issue:`21118`)
27+
- Bug preventing pandas from being importable with -OO optimization (:issue:`21071`)
28+
- Bug in :meth:`Categorical.fillna` incorrectly raising a ``TypeError`` when `value` the individual categories are iterable and `value` is an iterable (:issue:`21097`, :issue:`19788`)
2629

2730
.. _whatsnew_0231.performance:
2831

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)