Skip to content

Commit d349d84

Browse files
Doc improvements.
1 parent 857fafa commit d349d84

File tree

12 files changed

+1006
-943
lines changed

12 files changed

+1006
-943
lines changed

doc/src/api_manual/dataframe.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _oracledataframe:
22

3-
****************
4-
API: Data Frames
5-
****************
3+
**********************
4+
API: DataFrame Objects
5+
**********************
66

77
.. currentmodule:: oracledb
88

@@ -26,8 +26,10 @@ DataFrame Class
2626
.. autoclass:: DataFrame
2727

2828
A DataFrame object is returned by the methods
29-
:meth:`Connection.fetch_df_all()` and
30-
:meth:`Connection.fetch_df_batches()`.
29+
:meth:`Connection.fetch_df_all()`,
30+
:meth:`Connection.fetch_df_batches()`,
31+
:meth:`AsyncConnection.fetch_df_all()`, or
32+
:meth:`AsyncConnection.fetch_df_batches()`.
3133

3234
Each column in a DataFrame exposes an `Apache Arrow PyCapsule
3335
<https://arrow.apache.org/docs/format/CDataInterface/

doc/src/api_manual/module.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,14 +1643,14 @@ Other Types
16431643

16441644
All of these types are extensions to the DB API definition.
16451645

1646-
.. data:: ApiType
1646+
.. autoclass:: ApiType
16471647

16481648
This type object is the Python type of the database API type constants
16491649
:data:`BINARY`, :data:`DATETIME`, :data:`NUMBER`, :data:`ROWID` and
16501650
:data:`STRING`.
16511651

16521652

1653-
.. data:: DbType
1653+
.. autoclass:: DbType
16541654

16551655
This type object is the Python type of the
16561656
:ref:`database type constants <dbtypes>`.

doc/src/api_manual/pipeline.rst

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,66 +34,30 @@ Pipeline Methods
3434

3535
.. automethod:: Pipeline.add_callfunc
3636

37-
:ref:`pipelineopattrs` can be used to examine the operation, if needed.
38-
39-
.. seealso::
40-
41-
:ref:`PipelineOp object <pipelineopobjs>` and
42-
:ref:`PipelineOpResult object <pipelineopresultobjs>`
43-
4437
.. automethod:: Pipeline.add_callproc
4538

46-
:ref:`pipelineopattrs` can be used to examine the operation, if needed.
47-
48-
.. seealso::
49-
50-
:ref:`PipelineOp object <pipelineopobjs>`
51-
5239
.. automethod:: Pipeline.add_commit
5340

5441
.. automethod:: Pipeline.add_execute
5542

56-
:ref:`pipelineopattrs` can be used to examine the operation, if needed.
57-
58-
.. seealso::
59-
60-
:ref:`PipelineOp object <pipelineopobjs>`
61-
6243
.. automethod:: Pipeline.add_executemany
6344

64-
:ref:`pipelineopattrs` can be used to examine the operation, if needed.
65-
6645
.. seealso::
6746

68-
:ref:`batchstmnt` and :ref:`PipelineOp object <pipelineopobjs>`
47+
:ref:`batchstmnt`
6948

7049
.. automethod:: Pipeline.add_fetchall
7150

72-
:ref:`pipelineopattrs` can be used to examine the operation, if needed.
73-
74-
.. seealso::
75-
76-
:ref:`PipelineOp object <pipelineopobjs>` and
77-
:ref:`PipelineOpResult object <pipelineopresultobjs>`
78-
7951
.. automethod:: Pipeline.add_fetchmany
8052

81-
:ref:`pipelineopattrs` can be used to examine the operation, if needed.
82-
8353
.. seealso::
8454

85-
:ref:`PipelineOp object <pipelineopobjs>`,
86-
:ref:`PipelineOpResult object <pipelineopresultobjs>`,
8755
:ref:`roundtrips`, and :ref:`rowlimit`
8856

8957
.. automethod:: Pipeline.add_fetchone
9058

91-
:ref:`pipelineopattrs` can be used to examine the operation, if needed.
92-
9359
.. seealso::
9460

95-
:ref:`PipelineOp object <pipelineopobjs>`,
96-
:ref:`PipelineOpResult object <pipelineopresultobjs>`, and
9761
:ref:`rowlimit`
9862

9963
Pipeline Attributes

doc/src/user_guide/dataframes.rst

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ as `Apache PyArrow <https://arrow.apache.org/docs/python/index.html>`__,
1616
<https://parquet.apache.org/>`__ format.
1717

1818
Python-oracledb has a :ref:`DataFrame <oracledataframeobj>` object that exposes
19-
an Apache Arrow PyCapsule Interface. This enables zero-copy data interchanges
20-
to the data frame objects of other libraries.
19+
an Apache Arrow ArrowArrayStream PyCapsule Interface. This enables zero-copy
20+
data interchanges to the data frame objects of other libraries.
2121

2222
.. note::
2323

@@ -29,28 +29,30 @@ to the data frame objects of other libraries.
2929
Fetching Data Frames
3030
====================
3131

32-
Data frames can be fetched by using a standard SQL query.
32+
Data frames can be fetched by using a standard SQL query with :ref:`Connection
33+
<connobj>` or :ref:`AsyncConnection <asyncconnobj>` methods.
3334

3435
Data Frame Queries
3536
------------------
3637

37-
Python-oracledb has two methods for fetching rows into data frames:
38+
The python-oracledb methods for fetching rows into data frames are:
3839

3940
- :meth:`Connection.fetch_df_all()` fetches all rows from a query
4041
- :meth:`Connection.fetch_df_batches()` implements an iterator for fetching
4142
batches of rows
4243

43-
The methods return python-oracledb :ref:`DataFrame <oracledataframeobj>`
44-
objects.
44+
These methods can also be called from :ref:`AsyncConnection
45+
<asyncconnobj>`. The methods all return python-oracledb :ref:`DataFrame
46+
<oracledataframeobj>` objects.
4547

4648
For example, to fetch all rows from a query and print some information about
4749
the results:
4850

4951
.. code-block:: python
5052
51-
sql = "select * from departments"
53+
sql = "select * from departments where department_id > :1"
5254
# Adjust arraysize to tune the query fetch performance
53-
odf = connection.fetch_df_all(statement=sql, arraysize=100)
55+
odf = connection.fetch_df_all(statement=sql, parameters=[100], arraysize=100)
5456
5557
print(odf.column_names())
5658
print(f"{odf.num_columns()} columns")
@@ -60,20 +62,20 @@ With Oracle Database's standard DEPARTMENTS table, this would display::
6062

6163
['DEPARTMENT_ID', 'DEPARTMENT_NAME', 'MANAGER_ID', 'LOCATION_ID']
6264
4 columns
63-
27 rows
65+
17 rows
6466

6567
To fetch in batches, use an iterator:
6668

6769
.. code-block:: python
6870
6971
import pyarrow
7072
71-
sql = "select * from departments where department_id < 80"
73+
sql = "select * from departments where department_id < :1"
7274
# Adjust "size" to tune the query fetch performance
7375
# Here it is small to show iteration
74-
for odf in connection.fetch_df_batches(statement=sql, size=4):
75-
pdf = pyarrow.table(odf).to_pandas()
76-
print(pdf)
76+
for odf in connection.fetch_df_batches(statement=sql, parameters=[80], size=4):
77+
df = pyarrow.table(odf).to_pandas()
78+
print(df)
7779
7880
With Oracle Database's standard DEPARTMENTS table, this would display::
7981

@@ -90,6 +92,24 @@ With Oracle Database's standard DEPARTMENTS table, this would display::
9092
Converting to other data frame formats is :ref:`shown later <convertingodf>` in
9193
this chapter.
9294

95+
**Asynchronous Data Frame Queries**
96+
97+
With :ref:`asynchronous programming <asyncio>`, use the appropriate syntax. For
98+
example, to fetch all rows at once:
99+
100+
.. code-block:: python
101+
102+
connection = await oracledb.connect_async(...)
103+
odf = await connection.fetch_df_all(sql="select ...", parameters=..., arraysize=...)
104+
105+
Or to iterate:
106+
107+
.. code-block:: python
108+
109+
connection = await oracledb.connect_async(...)
110+
async for odf in connection.fetch_df_batches(sql="select ...", parameters=..., size=...):
111+
do_something(odf)
112+
93113
.. _dftypemapping:
94114

95115
Data Frame Type Mapping

src/oracledb/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
from . import base_impl, thick_impl, thin_impl
4444

4545
from .base_impl import (
46+
# type classes
47+
ApiType as ApiType,
48+
DbType as DbType,
4649
# database types
4750
DB_TYPE_BFILE as DB_TYPE_BFILE,
4851
DB_TYPE_BINARY_DOUBLE as DB_TYPE_BINARY_DOUBLE,

0 commit comments

Comments
 (0)