python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.55k stars 2.26k forks source link

Poetry will lock with two different versions of pandas if numpy is pinned #4703

Open J-France opened 2 years ago

J-France commented 2 years ago

Issue

Poetry will lock to two different versions of pandas if numpy is set to a fixed version. The following command will install pandas 1.3.4 into the virtual environment

poetry add numpy=1.20.1 pandas="*"

However the lock file contains two versions (1.3.3 and 1.3.4) as well as various poetry commands returning different versions

zachliu commented 2 years ago

not sure if it's related, i just had this error msg:

  SolverProblemError

  Because pandas (1.3.4) depends on numpy (>=1.21.0)
   and <my-stuff> depends on numpy (1.20.3), pandas is forbidden.
  So, because <my-stuff> depends on pandas (1.3.4), version solving failed.

then i checked pandas 1.3.4, it doesn't actually depends on numpy >= 1.21.0 if i'm using python 3.8 https://github.com/pandas-dev/pandas/blob/945c9ed766a61c7d2c0a7cbb251b6edebf9cb7d5/setup.cfg#L35-L38 it seems poetry is unable to recognize the new syntax there, so only the last row numpy >= 1.21.0 is registered :thinking:

setu4993 commented 2 years ago

it seems poetry is unable to recognize the new syntax there, so only the last row numpy >= 1.21.0 is registered 🤔.

I think @zachliu is onto something here.

I'm seeing SolverProblemError when trying to install awswrangler in a project with python = "^3.6.2,<3.10". awswrangler specifies different versions of pandas for 3.6 and 3.7 respectively as:

pandas = [
    { version = "~1.1.0", optional = true, python = "~=3.6.2" },
    { version = "^1.2.0", optional = true, python = ">=3.7.1,<3.10" },
]

Which can also be confirmed by looking at the metadata in the distributed package by running curl -sL https://pypi.org/pypi/awswrangler/json | jq '.info.requires_dist':

[
...
  "pandas (>=1.1.0,<1.2.0); python_full_version ~= \"3.6.2\"",
  "pandas (>=1.2.0,<2.0.0); python_full_version >= \"3.7.1\" and python_full_version < \"4.0.0\"",
...
]
setu4993 commented 2 years ago

This is still a problem, any help?

zachliu commented 2 years ago

same here... i noticed this issue because i've been trying to transform apache/airflow provided constraints file into a pyproject.toml

They have

pandas==1.3.4
numpy==1.20.3

in the constraint file. When I added them into my pyproject.toml I just got this SolverProblemError error. Right now I have to keep pandas==1.3.3

dimbleby commented 2 years ago

pandas later than 1.3.3 have numpy>=1.21.0; python_version>='3.10'. This is not compatible with the requested numpy=1.20.1 (nor, in the most recent comment, with numpy==1.20.3)

That is: numpy==1.20.3 and pandas==1.3.4 are not compatible if you're supporting python >= 3.10.

re the original report, the solver seems to get into some sort of muddle where it goes:

I'm not sure how this is supposed to work, I suspect that the solution poetry ought to find would be to use pandas 1.3.3.

artingithug commented 11 months ago

Tip in of some info from my encountering the same issue:

My temporary workaround was obviously changing python version constrain in pyproject.toml.

[tool.poetry.dependencies]
# Due to poetry's issue 4703 (https://github.com/python-poetry/poetry/issues/4703)
# modified python version constrain to install pandas.
#python = "^3.10"
python = ">=3.10,<3.12"
$ poetry add pandas                                                                                                                                                                            
Using version ^2.1.3 for pandas                                                                                                                                                                                    

Updating dependencies                                                                                                                                                                                              
Resolving dependencies... (1.7s)                                                                                                                                                                                   

Package operations: 3 installs, 0 updates, 0 removals                                                                                                                                                              

  • Installing python-dateutil (2.8.2)                                                                                                                                                                             
  • Installing pytz (2023.3.post1)                                                                       
  • Installing pandas (2.1.3)                                                                                                                                                                                      

Writing lock file 

$ poetry show --tree | grep -A3 -E '^pandas'
pandas 2.1.3 Powerful data structures for data analysis, time series, and statistics
├── numpy >=1.22.4,<2
├── numpy >=1.23.2,<2
├── python-dateutil >=2.8.2