Skip to content

Commit 4b7e466

Browse files
Document support for BSON types (#24)
1 parent edcf00f commit 4b7e466

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

bindings/python/docs/source/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ know to use **PyMongoArrow**.
1818
:doc:`quickstart`
1919
Start here for a quick overview.
2020

21+
:doc:`supported_types`
22+
A list of BSON types that are supported by PyMongoArrow.
23+
2124
:doc:`api/index`
2225
The complete API documentation, organized by module.
2326

@@ -76,6 +79,7 @@ Indices and tables
7679

7780
installation
7881
quickstart
82+
supported_types
7983
api/index
8084
changelog
8185
developer/index

bindings/python/docs/source/quickstart.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ to type-specifiers, e.g.::
6666
from pymongoarrow.api import Schema
6767
schema = Schema({'_id': int, 'amount': float, 'last_updated': datetime})
6868

69-
There are multiple permissible type-specifiers for each supported BSON type.
70-
For a full-list of supported types and associated type-specifiers see
71-
:doc:`supported-types`.
69+
There are multiple permissible type-identifiers for each supported BSON type.
70+
For a full-list of supported types and associated type-identifiers see
71+
:doc:`supported_types`.
7272

7373
Find operations
7474
---------------
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.. _type support:
2+
3+
Supported Types
4+
===============
5+
6+
PyMongoArrow currently supports a small subset of all BSON types.
7+
Support for additional types will be added in subsequent releases.
8+
9+
.. note:: For more information about BSON types, see the
10+
`BSON specification <http://bsonspec.org/spec.html>`_.
11+
12+
.. list-table::
13+
:widths: auto
14+
:header-rows: 1
15+
16+
* - BSON Type
17+
- Type Identifiers
18+
* - 64-bit binary floating point
19+
- :class:`py.float`, an instance of :meth:`pyarrow.float64`
20+
* - 32-bit integer
21+
- an instance of :meth:`pyarrow.int32`
22+
* - 64-bit integer
23+
- :class:`~py.int`, :class:`bson.int64.Int64`, an instance of :meth:`pyarrow.int64`
24+
* - UTC datetime
25+
- an instance of :class:`~pyarrow.timestamp` with ``ms`` resolution, :class:`py.datetime.datetime`
26+
27+
Type identifiers can be used to specify that a field is of a certain type
28+
during :class:`pymongoarrow.api.Schema` declaration. For example, if your data
29+
has fields 'f1' and 'f2' bearing types 32-bit integer and UTC datetime
30+
respectively, your schema can be defined as::
31+
32+
schema = Schema({'f1': pyarrow.int32(), 'f2': pyarrow.timestamp('ms')})

bindings/python/pymongoarrow/schema.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,29 @@
1717

1818

1919
class Schema:
20-
"""A mapping of field names to data types."""
21-
def __init__(self, schema):
22-
"""Create a :class:`~pymongoarrow.schema.Schema` instance from a
23-
mapping or an iterable.
20+
"""A mapping of field names to data types.
21+
22+
To create a schema, provide its constructor a mapping or an iterable
23+
containing field names and their expected types, e.g.::
2424
25-
If ``schema`` is a mapping, each key must be a field name and the
26-
corresponding value must be the expected data type of the named field.
27-
If ``schema`` is an iterable, it must be comprised entirely of 2-member
28-
sub-iterables. The first member of each sub-iterable must be a field
29-
name and the second value must be the corresponding data type.
25+
schema1 = Schema({'field_1': int, 'field_2': float})
26+
schema2 = Schema([('field_1', int), ('field_2', float)])
3027
31-
Data types can be specified as pyarrow type instances (e.g.
32-
an instance of :class:`pyarrow.int64`), bson types (e.g.
33-
:class:`bson.Int64`), or python type identifiers (e.g. ``int``,
34-
``float``). The following data types are currently supported:
28+
If ``schema`` is a mapping, each key must be a field name and the
29+
corresponding value must be the expected data type of the named field.
30+
If ``schema`` is an iterable, it must be comprised entirely of 2-member
31+
sub-iterables. The first member of each sub-iterable must be a field
32+
name and the second value must be the corresponding data type.
3533
36-
- 32-bit signed integers
37-
- 64-bit signed integers
38-
- 64-bit floating point integers
39-
- timestamps with millisecond or second resolution
34+
Data types can be specified as pyarrow type instances (e.g.
35+
an instance of :class:`pyarrow.int64`), bson types (e.g.
36+
:class:`bson.Int64`), or python type-identifiers (e.g. ``int``,
37+
``float``). To see a complete list of supported data types and their
38+
corresponding type-identifiers, see :ref:`type support`.
39+
"""
40+
def __init__(self, schema):
41+
"""Create a :class:`~pymongoarrow.schema.Schema` instance from a
42+
mapping or an iterable.
4043
4144
:Parameters:
4245
- `schema`: A mapping or an iterable.

0 commit comments

Comments
 (0)