Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn PackagingVersion

From Leeroopedia


Knowledge Sources
Domains Utilities, Packaging
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for parsing and comparing PEP 440 version strings provided by scikit-learn (vendored from the packaging library).

Description

This module is a vendored copy of the packaging library's version module. It provides the Version class for parsing PEP 440-compliant version strings and comparing them. It also includes the LegacyVersion class for handling non-PEP 440 version strings. The module defines a parse() function that returns the appropriate version object and supports all PEP 440 version specifiers including pre-releases, post-releases, dev releases, and local versions.

Usage

Use this module to parse, compare, and validate Python package version strings within scikit-learn's codebase without requiring the external packaging library as a runtime dependency.

Code Reference

Source Location

Signature

def parse(version: str) -> Union["LegacyVersion", "Version"]:
    ...

class Version(_BaseVersion):
    _regex = re.compile(r"^\s*" + VERSION_PATTERN + r"\s*$", re.VERBOSE | re.IGNORECASE)

    def __init__(self, version: str) -> None:
        ...

class LegacyVersion(_BaseVersion):
    def __init__(self, version: str) -> None:
        ...

Import

from sklearn.externals._packaging.version import parse, Version

I/O Contract

Inputs

Name Type Required Description
version str Yes Version string to parse (e.g., '1.2.3', '2.0.0rc1')

Outputs

Name Type Description
Version Version or LegacyVersion Parsed version object supporting comparison operators
major int Major version number
minor int Minor version number
micro int Micro (patch) version number
is_prerelease bool Whether this is a pre-release version

Usage Examples

Basic Usage

from sklearn.externals._packaging.version import parse, Version

v1 = parse("1.2.3")
v2 = parse("1.3.0")
print(v1 < v2)   # True
print(v1.major)   # 1
print(v1.minor)   # 2

# Direct Version class usage
v = Version("2.0.0rc1")
print(v.is_prerelease)  # True

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment