Skip to content

Commit 451b85b

Browse files
Merge pull request #15 from devrimcavusoglu/warn-for-next-version
README.md updated with future Python3.8 support.
2 parents a5e164b + b127c52 commit 451b85b

9 files changed

Lines changed: 74 additions & 6 deletions

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Light weight toolkit for bounding boxes providing conversion between bounding bo
1515
- **voc** : [Pascal VOC](http://host.robots.ox.ac.uk/pascal/VOC/)
1616
- **yolo** : [YOLO](https://github.com/ultralytics/yolov5)
1717

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

2026
Through pip (recommended),

pybboxes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
YoloBoundingBox,
99
)
1010

11-
__version__ = "0.1.0"
11+
__version__ = "0.1.1"

pybboxes/types/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import warnings
12
from abc import ABC, abstractmethod
23
from typing import List, Tuple, Union
34

45
import numpy as np
56

7+
from pybboxes.utils import find_stack_level
8+
69

710
class Box:
811
def __init__(self, x_tl: int, y_tl: int, x_br: int, y_br: int):
@@ -136,6 +139,13 @@ def from_array(cls, ar: Union[Tuple, List, np.ndarray], **kwargs):
136139
"""
137140
This method is intended to be "final", and should not be overridden in child classes.
138141
"""
142+
warnings.warn(
143+
"The functionality of the `from_array()` method is changed from only supporting a single box values to "
144+
"support (arbitrary) n-dimensional array of box values starting from 0.2 onward "
145+
"requiring Python3.8 or higher.",
146+
FutureWarning,
147+
stacklevel=find_stack_level(),
148+
)
139149
if len(ar) != 4:
140150
raise ValueError(f"Given array must be length of 4, got length {len(ar)}.")
141151
return cls(*ar, **kwargs)

pybboxes/utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import importlib.util
2+
import inspect
3+
import os.path
24
from pathlib import Path
35
from typing import Union
46

@@ -8,3 +10,28 @@ def import_module(module_name: str, filepath: Union[str, Path]):
810
module = importlib.util.module_from_spec(spec)
911
spec.loader.exec_module(module)
1012
return module
13+
14+
15+
def find_stack_level() -> int:
16+
"""
17+
Taken and adapted from pandas exception utility module.
18+
ref:
19+
https://github.com/pandas-dev/pandas/blob/22cb3793b47ed5b1f98156b58e0bfc109acebdc9/pandas/util/_exceptions.py#L27
20+
"""
21+
22+
import pybboxes as pbx
23+
24+
pkg_dir = os.path.dirname(pbx.__file__)
25+
test_dir = os.path.join(pkg_dir, "tests")
26+
27+
# https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slow
28+
frame = inspect.currentframe()
29+
n = 0
30+
while frame:
31+
fname = inspect.getfile(frame)
32+
if fname.startswith(pkg_dir) and not fname.startswith(test_dir):
33+
frame = frame.f_back
34+
n += 1
35+
else:
36+
break
37+
return n

tests/pybboxes/types/test_albumentations_bounding_box.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from pybboxes import BoundingBox
4+
from pybboxes import AlbumentationsBoundingBox, BoundingBox
55
from tests.utils import assert_almost_equal
66

77

@@ -29,6 +29,11 @@ def albumentations_area_computations_expected_output():
2929
}
3030

3131

32+
def test_from_array(albumentations_bbox, image_size):
33+
with pytest.warns(FutureWarning):
34+
AlbumentationsBoundingBox.from_array(albumentations_bbox, image_size=image_size)
35+
36+
3237
def test_to_coco(albumentations_bounding_box, coco_bbox):
3338
alb2coco_bbox = albumentations_bounding_box.to_coco()
3439
assert_almost_equal(actual=list(alb2coco_bbox.values), desired=coco_bbox)

tests/pybboxes/types/test_coco_bounding_box.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from pybboxes import BoundingBox
4+
from pybboxes import BoundingBox, CocoBoundingBox
55
from tests.utils import assert_almost_equal
66

77

@@ -29,6 +29,11 @@ def coco_area_computations_expected_output():
2929
}
3030

3131

32+
def test_from_array(coco_bbox, image_size):
33+
with pytest.warns(FutureWarning):
34+
CocoBoundingBox.from_array(coco_bbox, image_size=image_size)
35+
36+
3237
def test_to_coco(coco_bounding_box, albumentations_bbox):
3338
coco2albumentations_bbox = coco_bounding_box.to_albumentations()
3439
assert_almost_equal(actual=list(coco2albumentations_bbox.values), desired=albumentations_bbox)

tests/pybboxes/types/test_fiftyone_bounding_box.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from pybboxes import BoundingBox
4+
from pybboxes import BoundingBox, FiftyoneBoundingBox
55
from tests.utils import assert_almost_equal
66

77

@@ -29,6 +29,11 @@ def fiftyone_area_computations_expected_output():
2929
}
3030

3131

32+
def test_from_array(fiftyone_bbox, image_size):
33+
with pytest.warns(FutureWarning):
34+
FiftyoneBoundingBox.from_array(fiftyone_bbox, image_size=image_size)
35+
36+
3237
def test_to_albumentations(fiftyone_bounding_box, albumentations_bbox):
3338
fiftyone2albumentations_bbox = fiftyone_bounding_box.to_albumentations()
3439
assert_almost_equal(actual=list(fiftyone2albumentations_bbox.values), desired=albumentations_bbox)

tests/pybboxes/types/test_voc_bounding_box.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from pybboxes import BoundingBox
4+
from pybboxes import BoundingBox, VocBoundingBox
55
from tests.utils import assert_almost_equal
66

77

@@ -29,6 +29,11 @@ def voc_area_computations_expected_output():
2929
}
3030

3131

32+
def test_from_array(voc_bbox, image_size):
33+
with pytest.warns(FutureWarning):
34+
VocBoundingBox.from_array(voc_bbox, image_size=image_size)
35+
36+
3237
def test_to_albumentations(voc_bounding_box, albumentations_bbox):
3338
voc2albumentations_bbox = voc_bounding_box.to_albumentations()
3439
assert_almost_equal(actual=list(voc2albumentations_bbox.values), desired=albumentations_bbox)

tests/pybboxes/types/test_yolo_bounding_box.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from pybboxes import BoundingBox
4+
from pybboxes import BoundingBox, YoloBoundingBox
55
from tests.utils import assert_almost_equal
66

77

@@ -29,6 +29,11 @@ def yolo_area_computations_expected_output():
2929
}
3030

3131

32+
def test_from_array(yolo_bbox, image_size):
33+
with pytest.warns(FutureWarning):
34+
YoloBoundingBox.from_array(yolo_bbox, image_size=image_size)
35+
36+
3237
def test_to_albumentations(yolo_bounding_box, albumentations_bbox):
3338
yolo2albumentations_bbox = yolo_bounding_box.to_albumentations()
3439
assert_almost_equal(actual=list(yolo2albumentations_bbox.values), desired=albumentations_bbox)

0 commit comments

Comments
 (0)