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

Reduce warnings in tests #1066

Open
heikoklein opened this issue Mar 19, 2024 · 5 comments
Open

Reduce warnings in tests #1066

heikoklein opened this issue Mar 19, 2024 · 5 comments
Labels
dependencies Issues related to pyaerocom dependencies
Milestone

Comments

@heikoklein
Copy link
Member

heikoklein commented Mar 19, 2024

This issue is a long term issue to address warnings appearing in the code, i.e. caused by deprecations.
Checklist:

  • In pyproject.toml turn warnings into errors, i.e. uncomment filterwarnings section

    pyaerocom/pyproject.toml

    Lines 105 to 117 in d714b10

    ## uncomment to raise errors from warnings
    #filterwarnings = [
    # # all warnings are errors
    # "error",
    # "ignore::pytest.PytestUnraisableExceptionWarning",
    # # except deprecation and future warnings ouside this packege
    # 'ignore::PendingDeprecationWarning:^(?!pyaerocom|tests).*:',
    # 'ignore::DeprecationWarning:^(?!pyaerocom|tests).*:',
    # 'ignore::FutureWarning:^(?!pyaerocom|tests).*:',
    # # and not on this list
    # "ignore:.*please install Basemap:UserWarning:geonum.*:",
    # "ignore:Using DEFAULT_SPHERICAL_EARTH_RADIUS:UserWarning:iris.*:",
    #]
  • Turn all errors into new issues to be done until next milestone
  • Move this issue to a issue 2 milestones/month ahead.
@heikoklein
Copy link
Member Author

Remove also warning:

  Expected `tuple[str, ...]` but got `list` - serialized value may not be as expected
  return self.__pydantic_serializer__.to_python(

@lewisblake
Copy link
Member

Remove also warning:

  Expected `tuple[str, ...]` but got `list` - serialized value may not be as expected
  return self.__pydantic_serializer__.to_python(

No, do not remove this warning. It is telling the user important information that their config file is misconfigured. This is the intended functionality and should remain in place.

@heikoklein
Copy link
Member Author

@lewisblake Sorry, to disagree. There are two things which make this warning wrong:

  1. The warning does not say which field is a supposed to be a tuple. It doesn't even say which Setup is wrong.
  2. and maybe more important. Configs are written dynamically, i regularly add/remove items to config lists before I send them to one of the Setups. The config-dictionary should be flexible. That you convert/deepcopy the config inside of collocation-setup to something immutable is fine, but before it is send, it needs to be flexible.

@heikoklein
Copy link
Member Author

@lewisblake Reading the manual of pydantic: https://docs.pydantic.dev/latest/concepts/conversion_table/, pydantic automatically converts iterators to tuples as one would expect in python. Above mentioned warning does not come from a modellers cfg-file, but must be generated by an error inside of the EvalSetup/CollocationSetup (or another class using BaseModel).

The code below highlights the problem. An iterator given to a tuple field in ys is converted to a tuple.
Only when ys2 uses a list (intentional bug) in the internal default-value, the pydantic validator/converter is circumvented and the error is given when model_dump() is called.

from pydantic import BaseModel, field_validator


class Years(BaseModel):
    years: tuple[int, ...] = []


cfg = {"years": range(2022, 2024)}

ys = Years(**cfg)
ys.model_dump()
print(ys.years)
# (2022, 2023)

ys2 = Years()
# []
ys2.model_dump()
# Pydantic serializer warnings:
#  Expected `tuple[int, ...]` but got `list` - serialized value may not be as expected

@heikoklein heikoklein mentioned this issue Jun 24, 2024
9 tasks
@lewisblake
Copy link
Member

lewisblake commented Jun 26, 2024

Yes, we knew the issue was in model_dump() based on just the warning. But given that we had neither ruled out user error nor had a bug report it made it a little hard to justify investing too much time upfront. This is an important fix though, because we need to uphold serializability and recoverability of the config files so that experiments are reproducible based on the config json, so thanks for the PR.

@thorbjoernl thorbjoernl self-assigned this Jul 18, 2024
@heikoklein heikoklein changed the title Remove warnings in tests Reduce warnings in tests Jul 23, 2024
@thorbjoernl thorbjoernl modified the milestones: m2024-08, m2024-10 Jul 29, 2024
@thorbjoernl thorbjoernl removed their assignment Jul 29, 2024
@lewisblake lewisblake modified the milestones: m2024-10, m2024-11 Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Issues related to pyaerocom dependencies
Projects
None yet
Development

No branches or pull requests

3 participants