Skip to content

Commit 2f447b4

Browse files
committed
INTPYTHON-497 Extend rather than replace TypeRegistry in write function
1 parent bcd0d09 commit 2f447b4

File tree

3 files changed

+653
-473
lines changed

3 files changed

+653
-473
lines changed

.github/workflows/test-python.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,25 @@ jobs:
143143
run: just docs
144144
- name: Run linkcheck
145145
run: just docs-linkcheck
146+
test_minimum:
147+
runs-on: ubuntu-latest
148+
steps:
149+
- uses: actions/checkout@v5
150+
with:
151+
persist-credentials: false
152+
- name: Setup Python
153+
uses: actions/setup-python@v5
154+
with:
155+
python-version: 3.9
156+
cache: 'pip'
157+
cache-dependency-path: '**/pyproject.toml'
158+
- name: Install Deps
159+
run: |
160+
python -m pip install uv
161+
- name: Run tests
162+
shell: bash
163+
run: |
164+
uv venv
165+
source .venv/bin/activate
166+
uv pip install -e ".[test]" --resolution=lowest-direct
167+
pytest

bindings/python/pymongoarrow/api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
is_uint32,
5050
is_uint64,
5151
)
52+
from pymongo.collection import Collection
5253
from pymongo.common import MAX_WRITE_BATCH_SIZE
5354

5455
from pymongoarrow.context import PyMongoArrowContext
@@ -488,7 +489,9 @@ def transform_python(self, value):
488489
return Decimal128(value)
489490

490491

491-
def write(collection, tabular, *, exclude_none: bool = False, auto_convert: bool = True):
492+
def write(
493+
collection: Collection, tabular, *, exclude_none: bool = False, auto_convert: bool = True
494+
):
492495
"""Write data from `tabular` into the given MongoDB `collection`.
493496
494497
:Parameters:
@@ -559,10 +562,13 @@ def write(collection, tabular, *, exclude_none: bool = False, auto_convert: bool
559562

560563
# Add handling for special case types.
561564
codec_options = collection.codec_options
565+
base_codecs = []
566+
if hasattr(codec_options.type_registry, "codecs"):
567+
base_codecs = codec_options.type_registry.codecs
562568
if pd is not None:
563-
type_registry = TypeRegistry([_PandasNACodec(), _DecimalCodec()])
569+
type_registry = TypeRegistry([*base_codecs, _PandasNACodec(), _DecimalCodec()])
564570
else:
565-
type_registry = TypeRegistry([_DecimalCodec()])
571+
type_registry = TypeRegistry([*base_codecs, _DecimalCodec()])
566572
codec_options = codec_options.with_options(type_registry=type_registry)
567573

568574
while cur_offset < tab_size:

0 commit comments

Comments
 (0)