Skip to content

Commit 0e89370

Browse files
author
Matt Roeschke
committed
clarify documentation and whatsnew
1 parent 8025248 commit 0e89370

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

doc/source/io.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4777,7 +4777,7 @@ writes ``data`` to the database in batches of 1000 rows at a time:
47774777
data.to_sql('data_chunked', engine, chunksize=1000)
47784778
47794779
SQL data types
4780-
''''''''''''''
4780+
++++++++++++++
47814781

47824782
:func:`~pandas.DataFrame.to_sql` will try to map your data to an appropriate
47834783
SQL data type based on the dtype of the data. When you have columns of dtype
@@ -4809,13 +4809,19 @@ default ``Text`` type for string columns:
48094809
Because of this, reading the database table back in does **not** generate
48104810
a categorical.
48114811

4812+
.. _io.sql_datetime_data:
4813+
48124814
Datetime data types
48134815
'''''''''''''''''''
48144816

48154817
Using SQLAlchemy, :func:`~pandas.DataFrame.to_sql` is capable of writing
48164818
datetime data that is timezone naive or timezone aware. However, the resulting
4817-
data stored in the database ultimately depends on the corresponding,
4818-
supported data type for datetime data.
4819+
data stored in the database ultimately depends on the supported data type
4820+
for datetime data of the database system being used.
4821+
4822+
The following table lists supported data types for datetime data for some
4823+
common databases. Other database dialects may have different data types for
4824+
datetime data.
48194825

48204826
=========== ============================================= ===================
48214827
Database SQL Datetime Types Timezone Support
@@ -4830,7 +4836,7 @@ the data will be written as timezone naive timestamps that are in local time
48304836
with respect to the timezone.
48314837

48324838
:func:`~pandas.read_sql_table` is also capable of reading datetime data that is
4833-
timezone aware of naive. When reading ``TIMESTAMP WITH TIME ZONE`` types, pandas
4839+
timezone aware or naive. When reading ``TIMESTAMP WITH TIME ZONE`` types, pandas
48344840
will convert the data to UTC.
48354841

48364842
Reading Tables

doc/source/whatsnew/v0.24.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Other Enhancements
183183
- :class:`IntervalIndex` has gained the :meth:`~IntervalIndex.set_closed` method to change the existing ``closed`` value (:issue:`21670`)
184184
- :func:`~DataFrame.to_csv`, :func:`~Series.to_csv`, :func:`~DataFrame.to_json`, and :func:`~Series.to_json` now support ``compression='infer'`` to infer compression based on filename extension (:issue:`15008`).
185185
The default compression for ``to_csv``, ``to_json``, and ``to_pickle`` methods has been updated to ``'infer'`` (:issue:`22004`).
186-
- :meth:`DataFrame.to_sql` now supports writing ``TIMESTAMP WITH TIME ZONE`` types for supported databases. See the `io reference <https://pandas.pydata.org/pandas-docs/stable/io.html#sql-queries>`__ for implications (:issue:`9086`).
186+
- :meth:`DataFrame.to_sql` now supports writing ``TIMESTAMP WITH TIME ZONE`` types for supported databases. For databases that don't support timezones, datetime data will be stored as timezone unaware local timestamps. See the :ref:`io.sql_datetime_data` for implications (:issue:`9086`).
187187
- :func:`to_timedelta` now supports iso-formated timedelta strings (:issue:`21877`)
188188
- :class:`Series` and :class:`DataFrame` now support :class:`Iterable` in constructor (:issue:`2193`)
189189
- :class:`DatetimeIndex` gained :attr:`DatetimeIndex.timetz` attribute. Returns local time with timezone information. (:issue:`21358`)

pandas/core/generic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,10 @@ def to_sql(self, name, con, schema=None, if_exists='fail', index=True,
23162316
-----
23172317
Timezone aware datetime columns will be written as
23182318
``Timestamp with timezone`` type with SQLAlchemy if supported by the
2319-
database. Otherwise, the datetimes will stored in the closest available
2320-
type as timezone unaware timestamps local to the original timezone.
2319+
database. Otherwise, the datetimes will be stored as timezone unaware
2320+
timestamps local to the original timezone.
2321+
2322+
.. versionadded:: 0.24.0
23212323
23222324
References
23232325
----------

0 commit comments

Comments
 (0)