MCPcopy
hub / github.com/pandas-dev/pandas / read_query

Method read_query

pandas/io/sql.py:1801–1883  ·  view source on GitHub ↗

Read SQL query into a DataFrame. Parameters ---------- sql : str SQL query to be executed. index_col : string, optional, default: None Column name to use as index for the returned DataFrame object. coerce_float : bool, default

(
        self,
        sql: str,
        index_col: str | list[str] | None = None,
        coerce_float: bool = True,
        parse_dates=None,
        params=None,
        chunksize: int | None = None,
        dtype: DtypeArg | None = None,
        dtype_backend: DtypeBackend | Literal["numpy"] = "numpy",
    )

Source from the content-addressed store, hash-verified

1799 )
1800
1801 def read_query(
1802 self,
1803 sql: str,
1804 index_col: str | list[str] | None = None,
1805 coerce_float: bool = True,
1806 parse_dates=None,
1807 params=None,
1808 chunksize: int | None = None,
1809 dtype: DtypeArg | None = None,
1810 dtype_backend: DtypeBackend | Literal["numpy"] = "numpy",
1811 ) -> DataFrame | Iterator[DataFrame]:
1812 """
1813 Read SQL query into a DataFrame.
1814
1815 Parameters
1816 ----------
1817 sql : str
1818 SQL query to be executed.
1819 index_col : string, optional, default: None
1820 Column name to use as index for the returned DataFrame object.
1821 coerce_float : bool, default True
1822 Attempt to convert values of non-string, non-numeric objects (like
1823 decimal.Decimal) to floating point, useful for SQL result sets.
1824 params : list, tuple or dict, optional, default: None
1825 List of parameters to pass to execute method. The syntax used
1826 to pass parameters is database driver dependent. Check your
1827 database driver documentation for which of the five syntax styles,
1828 described in PEP 249's paramstyle, is supported.
1829 Eg. for psycopg2, uses %(name)s so use params={'name' : 'value'}
1830 parse_dates : list or dict, default: None
1831 - List of column names to parse as dates.
1832 - Dict of ``{column_name: format string}`` where format string is
1833 strftime compatible in case of parsing string times, or is one of
1834 (D, s, ns, ms, us) in case of parsing integer timestamps.
1835 - Dict of ``{column_name: arg dict}``, where the arg dict
1836 corresponds to the keyword arguments of
1837 :func:`pandas.to_datetime` Especially useful with databases
1838 without native Datetime support, such as SQLite.
1839 chunksize : int, default None
1840 If specified, return an iterator where `chunksize` is the number
1841 of rows to include in each chunk.
1842 dtype : Type name or dict of columns
1843 Data type for data or columns. E.g. np.float64 or
1844 {'a': np.float64, 'b': np.int32, 'c': 'Int64'}
1845
1846 Returns
1847 -------
1848 DataFrame
1849
1850 See Also
1851 --------
1852 read_sql_table : Read SQL database table into a DataFrame.
1853 read_sql
1854
1855 """
1856 result = self.execute(sql, params)
1857 columns = result.keys()
1858

Callers

nothing calls this directly

Calls 4

executeMethod · 0.95
_query_iteratorMethod · 0.95
_wrap_resultFunction · 0.70
keysMethod · 0.45

Tested by

no test coverage detected