Skip to content

Commit

Permalink
Fixed support for additional seaborn images (#1864)
Browse files Browse the repository at this point in the history
Co-authored-by: Sabine <sabine.nyholm@neptune.ai>
  • Loading branch information
SiddhantSadangi and normandy7 authored Oct 1, 2024
1 parent b62acb1 commit 2c5aaca
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/neptune_client_pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ style = "semver"
pattern = "default-unprefixed"

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"

# Python lack of functionalities from future versions
importlib-metadata = { version = "*", python = "<3.8" }
Expand Down Expand Up @@ -42,7 +42,7 @@ pandas = "*"

# Additional integrations
kedro-neptune = { version = "*", optional = true, python = "<3.11" }
neptune-detectron2 = { version = "*", optional = true, python = ">=3.7"}
neptune-detectron2 = { version = "*", optional = true, python = ">=3.8"}
neptune-fastai = { version = "*", optional = true }
neptune-lightgbm = { version = "*", optional = true }
pytorch-lightning = { version = "*", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/help-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
> Command | Description
> --- | ---
> /pre-commit-apply | Commit a pre-commit suggestions
> /run-unit | Run unittests on full matrix *(win, mac, linux x py3.7-3.12)
> /run-e2e | Run E2E tests on full matrix *(win, mac, linux x py3.7-3.12)
> /run-integrations | Run Client integrations on full matrix *(win, mac, linux x py3.7-3.12)
> /run-all-test | Run all tests on full matrix *(win, mac, linux x py3.7-3.12)
> /run-unit | Run unittests on full matrix *(win, mac, linux x py3.8-3.12)
> /run-e2e | Run E2E tests on full matrix *(win, mac, linux x py3.8-3.12)
> /run-integrations | Run Client integrations on full matrix *(win, mac, linux x py3.8-3.12)
> /run-all-test | Run all tests on full matrix *(win, mac, linux x py3.8-3.12)
reaction-type: hooray
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## neptune 1.12.0

### Changes
- Dropped support for Python 3.7 ([#1864](https://github.com/neptune-ai/neptune-client/pull/1864))

### Fixes
- Fixed support for additional Seaborn figure types ([#1864](https://github.com/neptune-ai/neptune-client/pull/1864))

## neptune 1.11.1

### Fixes
Expand Down
5 changes: 0 additions & 5 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ flags:
- src/neptune
carryforward: true

py3.7:
paths:
- src/neptune
carryforward: true

py3.8:
paths:
- src/neptune
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ style = "semver"
pattern = "default-unprefixed"

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"

# Python lack of functionalities from future versions
importlib-metadata = { version = "*", python = "<3.8" }
typing-extensions = ">=3.10.0"

# Missing compatibility layer between Python 2 and Python 3
Expand Down Expand Up @@ -43,7 +42,7 @@ pandas = "*"

# Additional integrations
kedro-neptune = { version = "*", optional = true, python = ">=3.9,<3.12" }
neptune-detectron2 = { version = "*", optional = true, python = ">=3.7"}
neptune-detectron2 = { version = "*", optional = true, python = ">=3.8"}
neptune-fastai = { version = "*", optional = true }
neptune-lightgbm = { version = "*", optional = true }
pytorch-lightning = { version = "*", optional = true }
Expand Down
4 changes: 3 additions & 1 deletion src/neptune/internal/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def _get_pil_image_data(image: PILImage) -> bytes:


def _get_figure_image_data(figure) -> bytes:
if figure.__class__.__name__ == "Axes":
figure = figure.figure
with io.BytesIO() as image_buffer:
figure.savefig(image_buffer, format="png", bbox_inches="tight")
return image_buffer.getvalue()
Expand Down Expand Up @@ -283,7 +285,7 @@ def is_pil_image(image) -> bool:


def is_matplotlib_figure(image):
return image.__class__.__module__.startswith("matplotlib.") and image.__class__.__name__ == "Figure"
return image.__class__.__module__.startswith("matplotlib.") and image.__class__.__name__ in ["Figure", "Axes"]


def is_plotly_figure(chart):
Expand Down
2 changes: 2 additions & 0 deletions src/neptune/legacy/internal/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def get_image_content(image):


def _get_figure_as_image(figure):
if figure.__class__.__name__ == "Axes":
figure = figure.figure
with io.BytesIO() as image_buffer:
figure.savefig(image_buffer, format="png", bbox_inches="tight")
return image_buffer.getvalue()
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/neptune/new/internal/utils/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@


class TestImage(unittest.TestCase):

TEST_DIR = "/tmp/neptune/{}".format(uuid4())

def setUp(self):
Expand Down Expand Up @@ -143,6 +142,12 @@ def test_get_image_content_from_seaborn_figure(self):
# then
self.assertEqual(get_image_content(grid), self._encode_figure(grid))

# given
figure = sns.lineplot(x=[1, 2, 3], y=[4, 5, 6])

# then
self.assertEqual(get_image_content(figure), self._encode_figure(figure))

def test_get_html_from_matplotlib_figure(self):
# given
fig = pyplot.figure()
Expand Down Expand Up @@ -262,6 +267,8 @@ def _encode_pil_image(image: Image) -> bytes:

@staticmethod
def _encode_figure(fig: Figure) -> bytes:
if fig.__class__.__name__ == "Axes":
fig = fig.figure
with io.BytesIO() as image_buffer:
fig.savefig(image_buffer, format="PNG", bbox_inches="tight")
return image_buffer.getvalue()
Expand Down

0 comments on commit 2c5aaca

Please sign in to comment.