Cribber
Cribber

Reputation: 2943

poetry add using a caret and a @ symbol

I am confused as to what the "@" operator actually does in poetry add pandas@^1.3.0.

Both following commands install pandas version 1.5.3 and set the dependency in my pyproject.toml to pandas = "^1.3.0":

poetry add pandas@^1.3.0
poetry add pandas^1.3.0

I have no other dependencies listed (aside from Python 3.8).

I thought that using the "@" symbol signifies a strict requirement for a specific version and its compatible releases. With "pandas@^1.3.0," shouldn't Poetry install exactly the version 1.3.0 of the "pandas" package?

The official documentation says:

When adding dependencies via poetry add, you can use the @ operator. This is understood similarly to the == syntax, but also allows prefixing any specifiers that are valid in pyproject.toml. For example:

Upvotes: 3

Views: 1566

Answers (3)

KarelHusa
KarelHusa

Reputation: 2258

The "@" operator in the add command is a delimiter between the package name and the version.

If the "@" operator is followed by its required version, e.g.

poetry add [email protected]

is the same as:

poetry add pendulum==2.0.5

If you use caret, e.g.:

poetry add requests@^2.13.0

Then you specify a version range.

The "@" symbol signifies a strict requirement only if you don't use any other specifier afterwards. The poetry documentation for "@" operator is a bit confusing.

Upvotes: 3

halfwind22
halfwind22

Reputation: 371

If the intention is to pin the package to a specific version, then "==" is what we must be using, and it clearly outlined in : https://python-poetry.org/docs/dependency-specification/#exact-requirements

Coming to your question, what you have attempted are the below:

poetry add pandas@^1.3.0

poetry add pandas^1.3.0

The caret(^) symbol allows upgrades to a later version as long as it doesn't modify the left most non-zero(major version) digit. So even though you say ^1.3.0, it finds the latest version of pandas with major version 1 (https://pypi.org/project/pandas/#history), which is 1.5.3.

If you are keen on using @ ,please do give a try with "poetry add [email protected]".

Upvotes: 0

OrenIshShalom
OrenIshShalom

Reputation: 7162

With "pandas@^1.3.0," shouldn't Poetry install exactly the version 1.3.0 of the "pandas" package?

No. According to the docs it requires that the minimal version is 1.3.0 and the maximal is strictly less than 2.0.0. Reference:

# Allow >=2.0.5, <3.0.0 versions
poetry add pendulum@^2.0.5

Upvotes: 0

Related Questions