Skip to content

Commit 871c562

Browse files
oguzhanogredenproost
authored andcommitted
DOC: Add docstring to the insertion method & add empty result note (pandas-dev#26872)
* Add docstring to the insertion method & fix pandas-dev#21364 Credit for empty result documentation goes to MagnetarAlex
1 parent 7c5d0c2 commit 871c562

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

doc/source/user_guide/io.rst

+23
Original file line numberDiff line numberDiff line change
@@ -5047,6 +5047,17 @@ Example of a callable using PostgreSQL `COPY clause
50475047
from io import StringIO
50485048

50495049
def psql_insert_copy(table, conn, keys, data_iter):
5050+
"""
5051+
Execute SQL statement inserting data
5052+
5053+
Parameters
5054+
----------
5055+
table : pandas.io.sql.SQLTable
5056+
conn : sqlalchemy.engine.Engine or sqlalchemy.engine.Connection
5057+
keys : list of str
5058+
Column names
5059+
data_iter : Iterable that iterates the values to be inserted
5060+
"""
50505061
# gets a DBAPI connection that can provide a cursor
50515062
dbapi_conn = conn.connection
50525063
with dbapi_conn.cursor() as cur:
@@ -5080,6 +5091,18 @@ table name and optionally a subset of columns to read.
50805091
50815092
pd.read_sql_table('data', engine)
50825093
5094+
.. note::
5095+
5096+
Note that pandas infers column dtypes from query outputs, and not by looking
5097+
up data types in the physical database schema. For example, assume ``userid``
5098+
is an integer column in a table. Then, intuitively, ``select userid ...`` will
5099+
return integer-valued series, while ``select cast(userid as text) ...`` will
5100+
return object-valued (str) series. Accordingly, if the query output is empty,
5101+
then all resulting columns will be returned as object-valued (since they are
5102+
most general). If you foresee that your query will sometimes generate an empty
5103+
result, you may want to explicitly typecast afterwards to ensure dtype
5104+
integrity.
5105+
50835106
You can also specify the name of the column as the ``DataFrame`` index,
50845107
and specify a subset of columns to be read.
50855108

0 commit comments

Comments
 (0)