Skip to content

Use pandas.util.version so import pvlib works without packaging - #2941

Open
jayhemnani9910 wants to merge 3 commits into
pvlib:mainfrom
jayhemnani9910:fix/declare-packaging-dependency
Open

jayhemnani9910 wants to merge 3 commits into
pvlib:mainfrom
jayhemnani9910:fix/declare-packaging-dependency

Conversation

@jayhemnani9910

@jayhemnani9910 jayhemnani9910 commented Nov 10, 2026 •

Copy link
Copy Markdown
  • Closes #xxxx (no issue; found on a fresh install of main)
  • I am familiar with the contributing guidelines
  • I attest that all AI-generated material has been vetted for accuracy and is in compliance with the pvlib license
  • Tests added (no new test; a test run always has the test extra, which provides packaging)
  • Adds description and name entries in the appropriate "what's new" file
  • Pull request is nearly complete and ready for detailed review.

Since #2924, pvlib/tools.py imports packaging.version, but packaging is only in the test extra. On a fresh install of main, import pvlib fails with ModuleNotFoundError: No module named 'packaging'. 0.16.1 isn't affected, so this would ship in the next release.

pvlib/tools.py now imports Version from pandas.util.version, which every supported pandas has (it shipped in 1.3.0), so packaging stays a test-only dependency. In a fresh venv on Python 3.13 with pandas 3.1.1 and no packaging installed, import pvlib, a clear sky calculation and the infer_freq helper work. tests/test_tools.py passes.

@github-actions

Copy link
Copy Markdown

Hey @jayhemnani9910! 🎉

Thanks for opening your first pull request! We appreciate your
contribution. Please ensure you have reviewed and understood the
contributing guidelines.

If AI is used for any portion of this PR, you must vet the content
for technical accuracy.

Finally, be sure the PR description includes the PR
checklist,
and complete the items you are able to.

pvlib.tools imports packaging since pvlib#2924, but it was only in the test
extra, so a fresh install failed on import.
@jayhemnani9910
jayhemnani9910 force-pushed the fix/declare-packaging-dependency branch from c962c78 to 28d5eeb Compare November 10, 2026 05:36
@cwhanse

cwhanse commented Nov 10, 2026

Copy link
Copy Markdown
Member

@echedey-ls should packaging be a dependency, or is there a way around it?

@echedey-ls echedey-ls left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I oversaw where was packaging declared as a dependency.

Comment thread pyproject.toml
'pytest-timeout',
'pytest-rerunfailures',
'pytest-remotedata',
'packaging',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove this line please.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed in efecb3c.

@wholmgren

Copy link
Copy Markdown
Member

This is to support the pd.infer_freq deprecation? Could we instead stop using it? We already have a handful of functions that roll their own version of this. I don't recall exactly why in each case but my memory is that infer_freq historically hasn't been good enough for one reason or another.

@jayhemnani9910

Copy link
Copy Markdown
Author

packaging is only used for the pandas version check before pd.infer_freq at pvlib/tools.py:482. If you'd rather stop using infer_freq there, or compare the version without packaging, I can change the PR to do that instead.

@echedey-ls

Copy link
Copy Markdown
Member

This is to support the pd.infer_freq deprecation?

Yes.

Could we instead stop using it? We already have a handful of functions that roll their own version of this. I don't recall exactly why in each case but my memory is that infer_freq historically hasn't been good enough for one reason or another.

I don't have much time to invest now on new changes like that. Maybe we should first analyze what handful of functions do so, how similar each one of them is to infer_freq and, if necessary, harmonize the implementations.

infer_freq historically hasn't been good enough for one reason or another.

I rather have a concise list of the reasons. I presume infer_freq is well-tested, general-purpose, has clearer documentation, and provides stable error handling.

@jayhemnani9910

Copy link
Copy Markdown
Author

Since import pvlib fails on a fresh install of main right now, I would suggest merging this as the fix and looking at replacing infer_freq separately, if you decide to. If you would rather not add the dependency, the other small option is to drop packaging from pvlib/tools.py and check the pandas version by trying the future.infer_freq_returns_offset option and falling back when pandas does not know it. Happy to switch the PR to that.

@echedey-ls

Copy link
Copy Markdown
Member

Maybe we can consider using pandas.util.version.Version instead if anybody does not like adding a required dependency. It does not have a docs page thou, so it may not be as API stable, and we should look for which version first shipped it.

@jayhemnani9910

Copy link
Copy Markdown
Author

pandas.util.version.Version first shipped in pandas 1.3.0 (a copy of packaging.version), and pvlib needs pandas >= 1.5.0, so every supported pandas has it. It works with the Version("3.1.0rc0") comparison in pvlib/tools.py:482 as is. The catch is the one you mention: it isn't in the pandas API reference, so they could move it without a deprecation.

So the options are:

  1. keep packaging as a dependency (this PR as it is), or
  2. switch the import in tools.py to pandas.util.version and leave packaging in the test extra.

Either is a one-line change. Tell me which one you prefer and I'll update the PR.

@cwhanse

cwhanse commented Nov 15, 2026

Copy link
Copy Markdown
Member

Please switch the import to pandas.util.version, thank you.

@jayhemnani9910 jayhemnani9910 changed the title Declare packaging as a dependency Use pandas.util.version so import pvlib works without packaging Nov 15, 2026
@jayhemnani9910

Copy link
Copy Markdown
Author

Switched in c6baa0e. packaging is no longer added to dependencies and stays in the test extra, so I updated the title and description to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants