crate 2.0.0.dev4__tar.gz → 2.0.0.dev6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/CHANGES.rst +11 -5
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/PKG-INFO +1 -1
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/client/__init__.py +1 -1
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/client/http.py +29 -7
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate.egg-info/PKG-INFO +1 -1
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/CONTRIBUTING.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/DEVELOP.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/LICENSE +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/MANIFEST.in +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/NOTICE +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/README.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/_extra/robots.txt +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/backlog.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/blobs.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/by-example/blob.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/by-example/client.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/by-example/connection.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/by-example/cursor.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/by-example/http.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/by-example/https.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/by-example/index.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/conf.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/connect.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/data-types.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/docutils.conf +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/getting-started.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/index-all.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/index.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/other-options.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/query.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/requirements.txt +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/docs/sqlalchemy.rst +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/pyproject.toml +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/requirements.txt +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/setup.cfg +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/setup.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/client/_pep440.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/client/blob.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/client/connection.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/client/converter.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/client/cursor.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/client/exceptions.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/testing/__init__.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/testing/layer.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate/testing/util.py +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate.egg-info/SOURCES.txt +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate.egg-info/dependency_links.txt +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate.egg-info/requires.txt +0 -0
- {crate-2.0.0.dev4 → crate-2.0.0.dev6}/src/crate.egg-info/top_level.txt +0 -0
@@ -7,15 +7,21 @@ Unreleased
|
|
7
7
|
|
8
8
|
- Switched JSON encoder to use the `orjson`_ library, to improve JSON
|
9
9
|
marshalling performance. Thanks, @widmogrod.
|
10
|
+
|
10
11
|
orjson is fast and in some spots even more correct when compared against
|
11
12
|
Python's stdlib ``json`` module. Contrary to the stdlib variant, orjson
|
12
|
-
will serialize to ``bytes`` instead of ``str``.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
will serialize to ``bytes`` instead of ``str``. When sending data to CrateDB,
|
14
|
+
``crate-python`` uses a custom encoder to add support for additional data
|
15
|
+
types.
|
16
|
+
|
17
|
+
- Python's ``Decimal`` type will be serialized to ``str``.
|
18
|
+
- Python's ``dt.datetime`` and ``dt.date`` types will be serialized to
|
19
|
+
``int`` (``LONG``) after converting to milliseconds since epoch, to
|
20
|
+
optimally accommodate CrateDB's `TIMESTAMP`_ representation.
|
21
|
+
- NumPy's data types will be handled by ``orjson`` without any ado.
|
17
22
|
|
18
23
|
.. _orjson: https://github.com/ijl/orjson
|
24
|
+
.. _TIMESTAMP: https://cratedb.com/docs/crate/reference/en/latest/general/ddl/data-types.html#type-timestamp
|
19
25
|
|
20
26
|
2024/11/23 1.0.1
|
21
27
|
================
|
@@ -20,6 +20,8 @@
|
|
20
20
|
# software solely pursuant to the terms of the relevant commercial agreement.
|
21
21
|
|
22
22
|
|
23
|
+
import calendar
|
24
|
+
import datetime as dt
|
23
25
|
import heapq
|
24
26
|
import io
|
25
27
|
import logging
|
@@ -84,19 +86,35 @@ def super_len(o):
|
|
84
86
|
return None
|
85
87
|
|
86
88
|
|
87
|
-
|
89
|
+
epoch_aware = dt.datetime(1970, 1, 1, tzinfo=dt.timezone.utc)
|
90
|
+
epoch_naive = dt.datetime(1970, 1, 1)
|
91
|
+
|
92
|
+
|
93
|
+
def json_encoder(obj: t.Any) -> t.Union[int, str]:
|
88
94
|
"""
|
89
95
|
Encoder function for orjson, with additional type support.
|
90
96
|
|
91
|
-
- Python's `Decimal` type
|
92
|
-
-
|
97
|
+
- Python's `Decimal` type will be serialized to `str`.
|
98
|
+
- Python's `dt.datetime` and `dt.date` types will be
|
99
|
+
serialized to `int` after converting to milliseconds
|
100
|
+
since epoch.
|
93
101
|
|
94
102
|
https://github.com/ijl/orjson#default
|
103
|
+
https://cratedb.com/docs/crate/reference/en/latest/general/ddl/data-types.html#type-timestamp
|
95
104
|
"""
|
96
105
|
if isinstance(obj, Decimal):
|
97
106
|
return str(obj)
|
98
|
-
|
99
|
-
|
107
|
+
if isinstance(obj, dt.datetime):
|
108
|
+
if obj.tzinfo is not None:
|
109
|
+
delta = obj - epoch_aware
|
110
|
+
else:
|
111
|
+
delta = obj - epoch_naive
|
112
|
+
return int(
|
113
|
+
delta.microseconds / 1000.0
|
114
|
+
+ (delta.seconds + delta.days * 24 * 3600) * 1000.0
|
115
|
+
)
|
116
|
+
if isinstance(obj, dt.date):
|
117
|
+
return calendar.timegm(obj.timetuple()) * 1000
|
100
118
|
raise TypeError
|
101
119
|
|
102
120
|
|
@@ -108,8 +126,12 @@ def json_dumps(obj: t.Any) -> bytes:
|
|
108
126
|
"""
|
109
127
|
return orjson.dumps(
|
110
128
|
obj,
|
111
|
-
default=
|
112
|
-
option=
|
129
|
+
default=json_encoder,
|
130
|
+
option=(
|
131
|
+
orjson.OPT_PASSTHROUGH_DATETIME
|
132
|
+
| orjson.OPT_NON_STR_KEYS
|
133
|
+
| orjson.OPT_SERIALIZE_NUMPY
|
134
|
+
),
|
113
135
|
)
|
114
136
|
|
115
137
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|