Skip to content

Commit 073a400

Browse files
authored
INTPYTHON-497 Extend rather than replace TypeRegistry in write function (#346)
1 parent bcd0d09 commit 073a400

File tree

8 files changed

+681
-480
lines changed

8 files changed

+681
-480
lines changed

.github/workflows/test-python.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,33 @@ jobs:
143143
run: just docs
144144
- name: Run linkcheck
145145
run: just docs-linkcheck
146+
test_minimum:
147+
runs-on: ubuntu-latest
148+
permissions:
149+
contents: read
150+
steps:
151+
- uses: actions/checkout@v5
152+
with:
153+
persist-credentials: false
154+
- name: Setup Python
155+
uses: actions/setup-python@v5
156+
with:
157+
python-version: 3.9
158+
cache: 'pip'
159+
cache-dependency-path: '**/pyproject.toml'
160+
- name: Install Deps
161+
run: |
162+
python -m pip install uv rust-just
163+
- name: Set up env
164+
run: |
165+
echo "LIBBSON_INSTALL_DIR=$PWD/libbson" >> $GITHUB_ENV
166+
echo "LD_LIBRARY_PATH=$PWD/libbson/lib" >> $GITHUB_ENV
167+
- name: Install libbson
168+
run: just build-libbson
169+
- name: Run tests
170+
shell: bash
171+
run: |
172+
uv venv
173+
source .venv/bin/activate
174+
uv pip install -e ".[test]" --resolution=lowest-direct
175+
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:

bindings/python/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Source = "https://github.com/mongodb-labs/mongo-arrow/tree/main/bindings/python"
5151
Tracker = "https://jira.mongodb.org/projects/INTPYTHON/issues"
5252

5353
[project.optional-dependencies]
54-
test = ["pytz", "pytest"]
55-
test-polars = ["polars"]
54+
test = ["pytz>=2025.2", "pytest>=8.0"]
55+
test-polars = ["polars>=1.10"]
5656
test-pandas = ["pandas>=1.3.5,<3"]
5757

5858
[tool.setuptools]
@@ -106,6 +106,7 @@ xfail_strict = true
106106
filterwarnings = [
107107
"error",
108108
"module:The global interpreter lock:RuntimeWarning", # from pandas
109+
"module:matching against an empty string will:pytest.PytestWarning", # from pandas
109110
]
110111

111112
[tool.ruff]

bindings/python/test/pandas_types/test_binary.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def test_contains(self):
9191
# We cannot compare a Binary object to an array.
9292
pass
9393

94+
def test_array_interface_copy(self):
95+
# We cannot avoid copying with our extension arrays.
96+
pass
97+
9498

9599
class TestConstructors(base.BaseConstructorsTests):
96100
def test_array_from_scalars(self):

bindings/python/test/pandas_types/test_code.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def test_contains(self):
8787
# We cannot compare a Code object to an array.
8888
pass
8989

90+
def test_array_interface_copy(self):
91+
# We cannot avoid copying with our extension arrays.
92+
pass
93+
9094

9195
class TestConstructors(base.BaseConstructorsTests):
9296
pass

bindings/python/test/pandas_types/test_decimal128.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def test_is_not_object_type(self, data):
8484

8585

8686
class TestInterface(base.BaseInterfaceTests):
87-
pass
87+
def test_array_interface_copy(self):
88+
# We cannot avoid copying with our extension arrays.
89+
pass
8890

8991

9092
class TestConstructors(base.BaseConstructorsTests):

bindings/python/test/pandas_types/test_objectid.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def test_is_not_object_type(self, data):
8383

8484

8585
class TestInterface(base.BaseInterfaceTests):
86-
pass
86+
def test_array_interface_copy(self):
87+
# We cannot avoid copying with our extension arrays.
88+
pass
8789

8890

8991
class TestConstructors(base.BaseConstructorsTests):

bindings/python/uv.lock

Lines changed: 625 additions & 473 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)