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

Update dependencies 2024/04 #68

Merged
merged 8 commits into from
Apr 12, 2024
Merged

Update dependencies 2024/04 #68

merged 8 commits into from
Apr 12, 2024

Conversation

glatterf42
Copy link
Member

This PR completes most open dependency updates, most notably removing the pin on pandas < 2.2.0.

Two notes:

  1. It doesn't bump httpx to 0.27 yet because that introduces a DeprecationWarning in an upstream dependency. Starlette already has a release resolving this issue (v0.37), but fastpi still pins starlette to below this version. Thus, I think it's fine if we keep from updating httpx just yet.
  2. I'm not happy with my current workaround for an upcoming pandas deprecation. In two places in the code, I've seen the same DeprecationWarning:
/home/fridolin/ixmp4/ixmp4/data/db/meta/repository.py:175: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
    return df.groupby("type").apply(map_value_column)

So I started tinkering with the options, but I couldn't figure out how to successfully select the grouping columns so that apply works on them. groupby(as_index=False, ...) doesn't seem to have an effect, which might suggest that pandas is treating our apply call as a transformation in the background. Simply including apply.(include_groups=False, ...) resulted in an error that the 'type' column was missing from the dataframe. Finally, I came across this suggestion: https://stackoverflow.com/a/78100669/23037943 (see in particular the first reply). The suggested workaround copies the column we want to groupby and then group(s)by the copied column, thus leaving the original open to be passed to apply as usual. Of course, this is temporarily creating extra data columns which we don't need, so it very much feels like there should be a better solution hiding somewhere. @meksor and @danielhuppmann, please let me know if you have any idea.

Apart from this, we probably want to release 0.7.4 after merging this PR to resolve the issue @phackstock had downstream.

FYI @pmussak

@glatterf42 glatterf42 added the enhancement New feature or request label Mar 18, 2024
@glatterf42 glatterf42 self-assigned this Mar 18, 2024
@phackstock
Copy link
Contributor

Thanks a lot for the quick fix @glatterf42 👍

@meksor
Copy link
Contributor

meksor commented Apr 9, 2024

Hello I removed the copied columns and put them back in each map function. From my side this looks good and can be merged! I also updated dask because there is a brand new python3.11 bug.

pyproject.toml Outdated
openpyxl = "^3.0.9"
pandas = "~2.1.2"
pandas = "^2.2.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the fix not work with pandas 2.1? Seems very tight to depend on a package version that was released less than 2 months ago.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial trigger for this PR was to remove the version pin of pandas. ~2.1.2 translates to >=2.1.2, <2.2.0, but climate-processor needs pandas 2.2.0 (if I understand correctly). Updating dependencies in poetry is usually done by running something like poetry add pandas@latest, which resolves to the latest version and uses the ^ notation, where ^2.2.1 translates to >=2.2.1, <3.0.0.
In other words, what we have now is simply the default. We could manually lower the requirement to ^2.1.2, which would allow climate-processor to resolve to the newer versions, too. However, it looks like pandas is releasing v2.2.2 today, so we won't only support the latest version either way. I think it's fine to keep the dependency as it is right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, ixmp4 is now a crucial dependency of pyam and that package is used by many people, so we should be as relaxed as possible - unless there is a good reason to be strict.
See this user feedback IAMconsortium/pyam#840

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this.

Copy link
Member Author

@glatterf42 glatterf42 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so I have now used uv's wonderful lowest-direct dependency resolution to arrive at a requirements.txt file with version pins for python3.10 that are compatible with our project. This process needs as input a requirements.in file, which I generated from our current pyproject.toml by replacing all version specifiers with >=. At first, I was a bit too radical in keeping only the major version; so if we required a project's 2.1.12 version, I'd keep >= 2.0 in my requirements.in. This produced problems at times and wasn't applicable to projects with versions starting with 0.. In those cases, I looked at pypi and chose a version more or less at random that is some good six months old.
Next, I created a new venv with python 3.10 and installed all versions that were pinned in the requirements.txt (see below). And the tests are successful :)
So I could now hijack this PR and poetry add all these dependencies with >= marks to expand the dependencies we support somewhat in time. For example, we can still support

  • pandas 2.0.0
  • dask 2023.9.0
  • fastapi 0.100.0

and several others. Please let me know what you think, @danielhuppmann

requirements.txt

The versions in here pass our test suite with python 3.10 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meksor Please also let me know what you think and whether we should revert some more internal dependencies to ^ again. The dev, docs, server groups come to mind as groups that might warrant more stringent dependency limits.

@glatterf42 glatterf42 changed the title Update dependencies 2024/03 Update dependencies 2024/04 Apr 10, 2024
Copy link
Member

@danielhuppmann danielhuppmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @glatterf42, this is super-helpful!

From my point of view, we should add a nightly test (running once a week or so) to alert us when a new release of some dependency package breaks something - but given that ixmp4 is now quite stable and used in production by more and more people, better to be lenient with dependencies...

@glatterf42
Copy link
Member Author

@meksor please let me know what you think of the dependency changes.

@meksor
Copy link
Contributor

meksor commented Apr 12, 2024

Has something changed from my last comment 3d ago?

@glatterf42
Copy link
Member Author

Yes, we now support some older versions, i.e. several dependencies are now not as strict as they used to be.

@glatterf42
Copy link
Member Author

Also, I removed essentially all upper version bounds.

@meksor
Copy link
Contributor

meksor commented Apr 12, 2024

Ah I see, well if the tests pass its fine with me, but then daniels suggestion for nightly builds seems even more salient now!

@glatterf42
Copy link
Member Author

But we can do that in another PR :)

@glatterf42 glatterf42 merged commit 8b0c1dc into main Apr 12, 2024
7 checks passed
@glatterf42 glatterf42 deleted the update/dependencies-2024-3 branch April 12, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants