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

[BUG]: Pydantic model generation issues. #3945

Open
3 tasks done
icichainz opened this issue Mar 18, 2024 · 3 comments
Open
3 tasks done

[BUG]: Pydantic model generation issues. #3945

icichainz opened this issue Mar 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@icichainz
Copy link

pycaret version checks

Issue Description

When use create_api function , the generate code contains non annottated attributes . Thus pydentic is unable to perform the right validations thus rendering the generated api unable to work.

Reproducible Example

<script src="https://gist.github.com/icichainz/0a6d5040db1a465f39264e07bea874af.js"></script>

Expected Behavior

When using create_api , i expect a working api , generated with fastapi and pydantic.

Actual Results

/home/huncho/MLProjects/bc_pycart_fastapi/.venv/bin/python /home/huncho/MLProjects/bc_pycart_fastapi/diabetes_api.py
Transformation Pipeline and Model Successfully Loaded
Traceback (most recent call last):
  File "/home/huncho/MLProjects/bc_pycart_fastapi/diabetes_api.py", line 16, in <module>
    input_model = create_model(
  File "/home/huncho/MLProjects/bc_pycart_fastapi/.venv/lib/python3.10/site-packages/pydantic/main.py", line 1490, in create_model
    return meta(
  File "/home/huncho/MLProjects/bc_pycart_fastapi/.venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 92, in __new__
    private_attributes = inspect_namespace(
  File "/home/huncho/MLProjects/bc_pycart_fastapi/.venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 384, in inspect_namespace
    raise PydanticUserError(
pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `Plasma glucose concentration a 2 hours in an oral glucose tolerance test = 152.0`. All model fields require a type annotation; if `Plasma glucose concentration a 2 hours in an oral glucose tolerance test` is not meant to be a field, you may be able to resolve this error by annotating it as a `ClassVar` or updating `model_config['ignored_types']`.

For further information visit https://errors.pydantic.dev/2.6/u/model-field-missing-annotation
(.venv) huncho@DESKTOP-1T270KV:~/MLProjects/bc_pycart_fastapi$ /home/huncho/MLProjects/bc_pycart_fastapi/.venv/bin/python /home/huncho/MLProjects/bc_pycart_fastapi/diabetes_api.py
Transformation Pipeline and Model Successfully Loaded
Traceback (most recent call last):
  File "/home/huncho/MLProjects/bc_pycart_fastapi/diabetes_api.py", line 16, in <module>
    input_model = create_model("diabetes_api_input", **{'Number of times pregnant': 13.0, 'Plasma glucose concentration a 2 hours in an oral glucose tolerance test': 152.0, 'Diastolic blood pressure (mm Hg)': 90.0, 'Triceps skin fold thickness (mm)': 33.0, '2-Hour serum insulin (mu U/ml)': 29.0, 'Body mass index (weight in kg/(height in m)^2)': 26.799999237060547, 'Diabetes pedigree function': 0.7310000061988831, 'Age (years)': 43.0})
  File "/home/huncho/MLProjects/bc_pycart_fastapi/.venv/lib/python3.10/site-packages/pydantic/main.py", line 1490, in create_model
    return meta(
  File "/home/huncho/MLProjects/bc_pycart_fastapi/.venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 92, in __new__
    private_attributes = inspect_namespace(
  File "/home/huncho/MLProjects/bc_pycart_fastapi/.venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 384, in inspect_namespace
    raise PydanticUserError(
pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `Number of times pregnant = 13.0`. All model fields require a type annotation; if `Number of times pregnant` is not meant to be a field, you may be able to resolve this error by annotating it as a `ClassVar` or updating `model_config['ignored_types']`.

For further information visit https://errors.pydantic.dev/2.6/u/model-field-missing-annotation

Installed Versions

System:
python: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
executable: /home/huncho/MLProjects/bc_pycart_fastapi/.venv/bin/python
machine: Linux-5.15.146.1-microsoft-standard-WSL2-x86_64-with-glibc2.35

PyCaret required dependencies:
pip: 22.0.2
setuptools: 59.6.0
pycaret: 3.3.0
IPython: 8.22.2
ipywidgets: 8.1.2
tqdm: 4.66.2
numpy: 1.26.4
pandas: 2.1.4
jinja2: 3.1.3
scipy: 1.11.4
joblib: 1.3.2
sklearn: 1.4.1.post1
pyod: 1.1.3
imblearn: 0.12.0
category_encoders: 2.6.3
lightgbm: 4.3.0
numba: 0.59.0
requests: 2.31.0
matplotlib: 3.7.5
scikitplot: 0.3.7
yellowbrick: 1.5
plotly: 5.20.0
plotly-resampler: Not installed
kaleido: 0.2.1
schemdraw: 0.15
statsmodels: 0.14.1
sktime: 0.27.0
tbats: 1.1.3
pmdarima: 2.0.4
psutil: 5.9.8
markupsafe: 2.1.5
pickle5: Not installed
cloudpickle: 3.0.0
deprecation: 2.1.0
xxhash: 3.4.1
wurlitzer: 3.0.3

PyCaret optional dependencies:
shap: Not installed
interpret: Not installed
umap: Not installed
ydata_profiling: Not installed
explainerdashboard: Not installed
autoviz: Not installed
fairlearn: Not installed
deepchecks: Not installed
xgboost: Not installed
catboost: Not installed
kmodes: Not installed
mlxtend: Not installed
statsforecast: Not installed
tune_sklearn: Not installed
ray: Not installed
hyperopt: Not installed
optuna: Not installed
skopt: Not installed
mlflow: Not installed
gradio: Not installed
fastapi: 0.110.0
uvicorn: 0.28.0
m2cgen: Not installed
evidently: Not installed
fugue: Not installed
streamlit: Not installed
prophet: Not installed

@icichainz icichainz added the bug Something isn't working label Mar 18, 2024
@celestinoxp
Copy link
Contributor

pydantic is not a direct dependency on pycaret. Try manually installing an older version of pydantic. If you can, please tell me which version worked, so I can propose that Pycaret itself does version control in the dependency list.

@icichainz
Copy link
Author

Ok , i will check that and get back to you soon .

@JuanBaldemarG
Copy link

what version of pydantic requires pycaret... i have the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants