Skip to content

NDArray doesn't handle types with custom core schemas properly #58

@NeejWeej

Description

@NeejWeej

Describe the bug
NDArray type does not handle classes with custom pydantic core schemas properly

To Reproduce

# /// script
# dependencies = [
#   "csp",
#   "ccflow>=0.5.1",
# ]
# ///


from csp import Enum
from ccflow import NDArray
from pydantic import TypeAdapter

import numpy as np

class MyEnum(Enum):
    X = Enum.auto()
    Y = Enum.auto()

ta_my_array = TypeAdapter(NDArray[MyEnum])

my_array = ta_my_array.validate_python(np.array([MyEnum.X]))
print(f'{my_array = }')
print(ta_my_array.dump_json(my_array))

Expected behavior
This should serialize properly

Error Message
Reading inline script metadata from /test_ccflow.py
my_array = array([<MyEnum.X: 0>], dtype=object)
Traceback (most recent call last):
File "/test_ccflow.py", line 23, in
print(ta_my_array.dump_json(my_array))
File "pydantic/type_adapter.py", line 581, in dump_json
return self.serializer.to_json(
pydantic_core._pydantic_core.PydanticSerializationError: Error serializing to JSON: PydanticSerializationError: Unable to serialize unknown type: <class 'main.MyEnum'>

Runtime Environment

0.5.1
3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:39:03) 
[GCC 11.3.0]
linux

ccflow version 0.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang: pythonPRs or issues related to Pythontype: bugConcrete, reproducible bugs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions