Skip to content

Commit

Permalink
Merge pull request #15 from devrimcavusoglu/warn-for-next-version
Browse files Browse the repository at this point in the history
README.md updated with future Python3.8 support.
  • Loading branch information
devrimcavusoglu authored Jun 18, 2022
2 parents a5e164b + b127c52 commit 451b85b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Light weight toolkit for bounding boxes providing conversion between bounding bo
- **voc** : [Pascal VOC](http://host.robots.ox.ac.uk/pascal/VOC/)
- **yolo** : [YOLO](https://github.com/ultralytics/yolov5)

### Important Notice
Support for Python<3.8 will be dropped starting version `0.2` though the development for Python3.6 and Python3.7 may
continue where it will be developed under version `0.1.x` for future versions. This may introduce; however, certain
discrepancies and/or unsupported operations in the `0.1.x` versions. To fully utilize and benefit from the entire
package, we recommend using Python3.8 at minimum (`Python>=3.8`).

## Installation

Through pip (recommended),
Expand Down
2 changes: 1 addition & 1 deletion pybboxes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
YoloBoundingBox,
)

__version__ = "0.1.0"
__version__ = "0.1.1"
10 changes: 10 additions & 0 deletions pybboxes/types/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import warnings
from abc import ABC, abstractmethod
from typing import List, Tuple, Union

import numpy as np

from pybboxes.utils import find_stack_level


class Box:
def __init__(self, x_tl: int, y_tl: int, x_br: int, y_br: int):
Expand Down Expand Up @@ -136,6 +139,13 @@ def from_array(cls, ar: Union[Tuple, List, np.ndarray], **kwargs):
"""
This method is intended to be "final", and should not be overridden in child classes.
"""
warnings.warn(
"The functionality of the `from_array()` method is changed from only supporting a single box values to "
"support (arbitrary) n-dimensional array of box values starting from 0.2 onward "
"requiring Python3.8 or higher.",
FutureWarning,
stacklevel=find_stack_level(),
)
if len(ar) != 4:
raise ValueError(f"Given array must be length of 4, got length {len(ar)}.")
return cls(*ar, **kwargs)
27 changes: 27 additions & 0 deletions pybboxes/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import importlib.util
import inspect
import os.path
from pathlib import Path
from typing import Union

Expand All @@ -8,3 +10,28 @@ def import_module(module_name: str, filepath: Union[str, Path]):
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


def find_stack_level() -> int:
"""
Taken and adapted from pandas exception utility module.
ref:
https://github.com/pandas-dev/pandas/blob/22cb3793b47ed5b1f98156b58e0bfc109acebdc9/pandas/util/_exceptions.py#L27
"""

import pybboxes as pbx

pkg_dir = os.path.dirname(pbx.__file__)
test_dir = os.path.join(pkg_dir, "tests")

# https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slow
frame = inspect.currentframe()
n = 0
while frame:
fname = inspect.getfile(frame)
if fname.startswith(pkg_dir) and not fname.startswith(test_dir):
frame = frame.f_back
n += 1
else:
break
return n
7 changes: 6 additions & 1 deletion tests/pybboxes/types/test_albumentations_bounding_box.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pybboxes import BoundingBox
from pybboxes import AlbumentationsBoundingBox, BoundingBox
from tests.utils import assert_almost_equal


Expand Down Expand Up @@ -29,6 +29,11 @@ def albumentations_area_computations_expected_output():
}


def test_from_array(albumentations_bbox, image_size):
with pytest.warns(FutureWarning):
AlbumentationsBoundingBox.from_array(albumentations_bbox, image_size=image_size)


def test_to_coco(albumentations_bounding_box, coco_bbox):
alb2coco_bbox = albumentations_bounding_box.to_coco()
assert_almost_equal(actual=list(alb2coco_bbox.values), desired=coco_bbox)
Expand Down
7 changes: 6 additions & 1 deletion tests/pybboxes/types/test_coco_bounding_box.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pybboxes import BoundingBox
from pybboxes import BoundingBox, CocoBoundingBox
from tests.utils import assert_almost_equal


Expand Down Expand Up @@ -29,6 +29,11 @@ def coco_area_computations_expected_output():
}


def test_from_array(coco_bbox, image_size):
with pytest.warns(FutureWarning):
CocoBoundingBox.from_array(coco_bbox, image_size=image_size)


def test_to_coco(coco_bounding_box, albumentations_bbox):
coco2albumentations_bbox = coco_bounding_box.to_albumentations()
assert_almost_equal(actual=list(coco2albumentations_bbox.values), desired=albumentations_bbox)
Expand Down
7 changes: 6 additions & 1 deletion tests/pybboxes/types/test_fiftyone_bounding_box.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pybboxes import BoundingBox
from pybboxes import BoundingBox, FiftyoneBoundingBox
from tests.utils import assert_almost_equal


Expand Down Expand Up @@ -29,6 +29,11 @@ def fiftyone_area_computations_expected_output():
}


def test_from_array(fiftyone_bbox, image_size):
with pytest.warns(FutureWarning):
FiftyoneBoundingBox.from_array(fiftyone_bbox, image_size=image_size)


def test_to_albumentations(fiftyone_bounding_box, albumentations_bbox):
fiftyone2albumentations_bbox = fiftyone_bounding_box.to_albumentations()
assert_almost_equal(actual=list(fiftyone2albumentations_bbox.values), desired=albumentations_bbox)
Expand Down
7 changes: 6 additions & 1 deletion tests/pybboxes/types/test_voc_bounding_box.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pybboxes import BoundingBox
from pybboxes import BoundingBox, VocBoundingBox
from tests.utils import assert_almost_equal


Expand Down Expand Up @@ -29,6 +29,11 @@ def voc_area_computations_expected_output():
}


def test_from_array(voc_bbox, image_size):
with pytest.warns(FutureWarning):
VocBoundingBox.from_array(voc_bbox, image_size=image_size)


def test_to_albumentations(voc_bounding_box, albumentations_bbox):
voc2albumentations_bbox = voc_bounding_box.to_albumentations()
assert_almost_equal(actual=list(voc2albumentations_bbox.values), desired=albumentations_bbox)
Expand Down
7 changes: 6 additions & 1 deletion tests/pybboxes/types/test_yolo_bounding_box.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pybboxes import BoundingBox
from pybboxes import BoundingBox, YoloBoundingBox
from tests.utils import assert_almost_equal


Expand Down Expand Up @@ -29,6 +29,11 @@ def yolo_area_computations_expected_output():
}


def test_from_array(yolo_bbox, image_size):
with pytest.warns(FutureWarning):
YoloBoundingBox.from_array(yolo_bbox, image_size=image_size)


def test_to_albumentations(yolo_bounding_box, albumentations_bbox):
yolo2albumentations_bbox = yolo_bounding_box.to_albumentations()
assert_almost_equal(actual=list(yolo2albumentations_bbox.values), desired=albumentations_bbox)
Expand Down

0 comments on commit 451b85b

Please sign in to comment.