Skip to content

Use packaging.version.Version in tests #3652

@dangotbanned

Description

@dangotbanned

Description

Just discovered that pytest has a hard dependency on (https://github.com/pypa/packaging)

I was about to reinvent the Version class after forgetting how tuple worked.
But it seems like there's not any blockers to switching to it instead?

Examples

Use properties for testing parts of a version:

-           "pyarrow_table" in str(constructor) and PYARROW_VERSION < (14,),
+           "pyarrow_table" in str(constructor) and PYARROW_VERSION.major < 14,

Compare between instances:

-       PYARROW_VERSION == (0, 0, 0) or PANDAS_VERSION < (2, 2)
+       PYARROW_VERSION == (0, 0, 0) or PANDAS_VERSION < Version("2.2")

Although for that, I'd probably write it as:

+       PANDAS_SUPPORTS_DECIMAL = Version("2.2")
-       PYARROW_VERSION == (0, 0, 0) or PANDAS_VERSION < (2, 2)
+       PYARROW_VERSION.major == 0 or PANDAS_VERSION < PANDAS_SUPPORTS_DECIMAL

There's more features like handling pre-release versions too - which might be handy in ci

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions