Skip to content

Commit

Permalink
fix building issue for open source version
Browse files Browse the repository at this point in the history
Summary:
After long investigation I've found the rootcause: prophet needs holiday lib interface no later that 0.024 and we have only lower bound inside.
I've added this bound and built open source version it it internal (on my laptop).
I've also added comaptibility for new packaging packaet version for future updates

Reviewed By: souravc83

Differential Revision: D49636163

fbshipit-source-id: e8e6ff117fb1e0e55addd6ac04e5f50bfce91b3a
  • Loading branch information
irumata authored and facebook-github-bot committed Sep 26, 2023
1 parent df0806b commit 8751bbb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
31 changes: 23 additions & 8 deletions kats/compat/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,34 @@
# Python < 3.8
import importlib_metadata as metadata

from typing import Callable, Union
from typing import Any, Callable, Type, Union

import packaging

from packaging import version as pv

OLD_PACKAGING_VERSION: bool = pv.parse(packaging.__version__) <= pv.parse("21.3")

# type: ignore
VERSION_TYPE: Type[Any] = (
Union[pv.Version, pv.LegacyVersion] if OLD_PACKAGING_VERSION else pv.Version
)

V = Union[str, "Version", pv.Version, pv.LegacyVersion]
if OLD_PACKAGING_VERSION:
V = Union[str, "Version", pv.Version, pv.LegacyVersion]
else:
V = Union[str, "Version", pv.Version]


class Version:
"""Extend packaging Version to allow comparing to version strings.
Wraps instead of extends, because pv.parse can return either a
pv.Version or a pv.LegacyVersion.
pv.Version or a pv.LegacyVersion for version under 21.3
"""

version: Union[pv.Version, pv.LegacyVersion]
# type: ignore
version: VERSION_TYPE

def __init__(self, version: V) -> None:
"""Parse a version.
Expand All @@ -36,11 +48,14 @@ def __init__(self, version: V) -> None:
version object.
"""
if isinstance(version, str):
self.version = self._parse(version)
# type: ignore
self.version: VERSION_TYPE = self._parse(version)
elif isinstance(version, Version):
self.version = version.version
# type: ignore
self.version: VERSION_TYPE = version.version
else:
self.version = version
# type: ignore
self.version: VERSION_TYPE = version

def _parse(self, version: str) -> Union[pv.Version, pv.LegacyVersion]:
try:
Expand Down Expand Up @@ -73,6 +88,6 @@ def _compare(self, other: V, method: Callable[[V, V], bool]) -> bool:
elif isinstance(other, str):
other = self._parse(other)
try:
return method(self.version._key, other._key)
return method(self.version._key, other._key) # type: ignore
except (AttributeError, TypeError):
return NotImplemented
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
attrs>=21.2.0
deprecated>=1.2.12
importlib_metadata; python_version < '3.8'
holidays<=0.24
matplotlib>=2.0.0
numpy>=1.21,<1.22
pandas>=1.0.4,<=1.3.5
Expand Down

0 comments on commit 8751bbb

Please sign in to comment.