Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Type Mismatch Conversion to NaN #246

Open
brunofirnkes opened this issue Oct 25, 2024 · 1 comment
Open

Avoid Type Mismatch Conversion to NaN #246

brunofirnkes opened this issue Oct 25, 2024 · 1 comment

Comments

@brunofirnkes
Copy link

When using find methods with a defined schema, values in MongoDB documents that don’t match the specified schema types (e.g., strings in a field expected to be int64) are silently converted to NaN in the results. This behavior can lead to unintended data loss and inconsistency, as there’s no indication of the type mismatch or a warning about the data conversion.

Ideally, the function should raise an error indicating that a type mismatch has been detected in the value field, rather than converting to NaN. This would make the find method more robust and prevent data integrity issues due to unintentional type mismatches.

Example:

from pymongoarrow.monkey import patch_all
patch_all()
from pymongo import MongoClient
from pymongoarrow.api import Schema
import pyarrow as pa

coll = MongoClient().test.test
coll.insert_many([{"value": 1}, {"value": "1"}, {"value": 1.1}, {"value": None}, {"value": False}, {}])

schema = {"value": pa.int64()}
projection = {"_id": 0, "value": 1}
df = coll.find_pandas_all(query={}, schema=Schema(schema), projection=projection)
print(df)

Output:

   value
0    1.0
1    NaN
2    1.0
3    NaN
4    0.0
5    NaN
@aclark4life
Copy link
Contributor

Thank you for the report, @brunofirnkes! We are now tracking this issue in Jira.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants