@@ -12,30 +12,32 @@ PyMongoArrow
12
12
for loading MongoDB query result sets as Apache Arrow tables, Pandas
13
13
DataFrames or NumPy arrays.
14
14
15
- .. code-block :: python
15
+ .. code-block :: pycon
16
16
17
17
>>> from pymongoarrow.monkey import patch_all
18
- >> > patch_all()
19
- >> > from pymongoarrow.api import Schema
20
- >> > schema = Schema({' _id' : int , ' qty' : float })
21
- >> > from pymongo import MongoClient
22
- >> > client = MongoClient()
23
- >> > client.db.data.insert_many([{' _id' : 1 , ' qty' : 25.4 }, {' _id' : 2 , ' qty' : 16.9 }, {' _id' : 3 , ' qty' : 2.3 }])
24
- >> > data_frame = client.db.test.find_pandas_all({}, schema = schema)
25
- >> > data_frame
18
+ ... patch_all()
19
+ ... from pymongoarrow.api import Schema
20
+ ... schema = Schema({"_id": int, "qty": float})
21
+ ... from pymongo import MongoClient
22
+ ... client = MongoClient()
23
+ ... client.db.data.insert_many(
24
+ ... [{"_id": 1, "qty": 25.4}, {"_id": 2, "qty": 16.9}, {"_id": 3, "qty": 2.3}]
25
+ ... )
26
+ ... data_frame = client.db.test.find_pandas_all({}, schema=schema)
27
+ ... data_frame
26
28
_id qty
27
29
0 1 25.4
28
30
1 2 16.9
29
31
2 3 2.3
30
- >> > arrow_table = client.db.test.find_arrow_all({}, schema = schema)
32
+ ... arrow_table = client.db.test.find_arrow_all({}, schema=schema)
31
33
# The schema may also be omitted
32
- >> > arrow_table = client.db.test.find_arrow_all({})
33
- >> > arrow_table
34
+ ... arrow_table = client.db.test.find_arrow_all({})
35
+ ... arrow_table
34
36
pyarrow.Table
35
37
_id: int64
36
38
qty: double
37
- >> > ndarrays = client.db.test.find_numpy_all({}, schema = schema)
38
- >> > ndarrays
39
+ ... ndarrays = client.db.test.find_numpy_all({}, schema=schema)
40
+ ... ndarrays
39
41
{'_id': array([1, 2, 3]), 'qty': array([25.4, 16.9, 2.3])}
40
42
41
43
**PyMongoArrow ** is the recommended way to
0 commit comments