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

Numpy dtype support breaks between pydantic 1.7 to 1.8 #2483

Closed
3 tasks done
dazza-codes opened this issue Mar 5, 2021 · 0 comments · Fixed by #2502
Closed
3 tasks done

Numpy dtype support breaks between pydantic 1.7 to 1.8 #2483

dazza-codes opened this issue Mar 5, 2021 · 0 comments · Fixed by #2502
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@dazza-codes
Copy link

dazza-codes commented Mar 5, 2021

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Numpy dtype support breaks between pydantic versions:

-version = "1.7.3"
+version = "1.8.1"
$ poetry show pydantic
name         : pydantic
version      : 1.8.1
description  : Data validation and settings management using python 3.6 type hinting

dependencies
 - python-dotenv >=0.10.4
 - typing-extensions >=3.7.4.3

$ poetry show numpy
name         : numpy
version      : 1.20.1
description  : NumPy is the fundamental package for array computing with Python.

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

$ python -c "import pydantic.utils; print(pydantic.utils.version_info())"
             pydantic version: 1.8.1
            pydantic compiled: True
                 install path: /opt/conda/envs/jupiter-gis/lib/python3.7/site-packages/pydantic
               python version: 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37)  [GCC 9.3.0]
                     platform: Linux-4.15.0-136-generic-x86_64-with-debian-buster-sid
     optional deps. installed: ['dotenv', 'typing-extensions']
import pydantic
import numpy as np

class Bin(BaseModel):
    lower: float
    upper: float
    dtype: np.dtype = Field(default=np.dtype("uint8"))

    class Config:
        allow_mutation = False
        # this is required for numpy.dtype
        arbitrary_types_allowed = True

While loading pytest root conftest.py there is an error on import like:

pydantic/fields.py:249: in pydantic.fields.Field
    ???
pydantic/fields.py:172: in pydantic.fields.FieldInfo._validate
    ???
E   TypeError: Cannot interpret 'PydanticUndefined' as a data type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant