Skip to content

[SC-7587] Add logging image example to implement_custom_tests.ipynb notebook #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions notebooks/code_samples/custom_tests/implement_custom_tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -362,7 +362,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -395,7 +395,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -806,6 +806,44 @@
"![screenshot showing image custom test](../../images/image-in-custom-metric.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want to log an image as a test result, you can do so by passing the path to the image as a parameter to the custom test and then opening the file in the test function. Here's an example:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"@vm.test(\"my_custom_tests.MyPNGCorrelationMatrix\")\n",
"def Image(path: str):\n",
" \"\"\"Opens a png image file and logs it as a test result to ValidMind\"\"\"\n",
" if not path.endswith(\".png\"):\n",
" raise ValueError(\"Image must be a PNG file\")\n",
"\n",
" # return raw image bytes\n",
" with open(path, \"rb\") as f:\n",
" return f.read()\n",
" \n",
"run_test(\n",
" \"my_custom_tests.MyPNGCorrelationMatrix\",\n",
" params={\"path\": \"../../images/pearson-correlation-matrix.png\"},\n",
").log()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The image is displayed in the test result:\n",
"\n",
"![screenshot showing image from file](../../images/pearson-correlation-matrix-test-output.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -906,7 +944,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added notebooks/images/pearson-correlation-matrix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "ValidMind Library"
license = "Commercial License"
name = "validmind"
readme = "README.pypi.md"
version = "2.6.3"
version = "2.6.4"

[tool.poetry.dependencies]
python = ">=3.8.1,<3.12"
Expand Down
2 changes: 1 addition & 1 deletion validmind/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.6.3"
__version__ = "2.6.4"