Skip to content
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

Update docs #233

Merged
merged 2 commits into from
Sep 18, 2023
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
1 change: 1 addition & 0 deletions docs/whitelist.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
index.md
layout/index.md
layout/lenses.md
dataset/index.md
dtypes/index.md
3 changes: 2 additions & 1 deletion renumics/spotlight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
from .viewer import Viewer, close, viewers, show
from .plugin_loader import load_plugins
from .settings import settings
from .analysis.typing import DataIssue
from . import cache, logging

if not settings.verbose:
logging.disable()

__plugins__ = load_plugins()

__all__ = ["show", "close", "viewers", "Viewer", "clear_caches"]
__all__ = ["show", "close", "viewers", "Viewer", "clear_caches", "DataIssue"]


def clear_caches() -> None:
Expand Down
2 changes: 1 addition & 1 deletion renumics/spotlight/analysis/analyzers/cleanlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def analyze_with_cleanlab(

if len(rows):
yield DataIssue(
severity="medium",
title="Outliers in embeddings",
rows=rows,
severity="medium",
columns=[column_name],
description=inspect.cleandoc(
"""
Expand Down
10 changes: 4 additions & 6 deletions renumics/spotlight/analysis/analyzers/cleanvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
import inspect
from typing import Iterable, List
from typing import Dict, Iterable, List, Tuple
from pathlib import Path
from tempfile import TemporaryDirectory
from contextlib import redirect_stderr, redirect_stdout
Expand All @@ -13,14 +13,12 @@
import cleanvision

from renumics.spotlight.dtypes import Image

from renumics.spotlight.data_store import DataStore

from ..decorator import data_analyzer
from ..typing import DataIssue
from ..typing import DataIssue, Severity


_issue_types = {
_issue_types: Dict[str, Tuple[str, Severity, str]] = {
"is_light_issue": (
"Bright images",
"medium",
Expand Down Expand Up @@ -83,9 +81,9 @@
def _make_issue(cleanvision_key: str, column: str, rows: List[int]) -> DataIssue:
title, severity, description = _issue_types[cleanvision_key]
return DataIssue(
severity=severity,
title=title,
rows=rows,
severity=severity,
columns=[column],
description=inspect.cleandoc(description),
)
Expand Down
10 changes: 7 additions & 3 deletions renumics/spotlight/analysis/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@

from typing import Callable, Iterable, List, Literal, Optional

from pydantic import BaseModel
from pydantic.dataclasses import dataclass

from renumics.spotlight.data_store import DataStore


class DataIssue(BaseModel):
Severity = Literal["low", "medium", "high"]


@dataclass
class DataIssue:
"""
An Issue affecting multiple rows of the dataset
"""

severity: Literal["low", "medium", "high"] = "medium"
title: str
rows: List[int]
severity: Severity = "medium"
columns: Optional[List[str]] = None
description: str = ""

Expand Down
5 changes: 4 additions & 1 deletion renumics/spotlight/dataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
video_dtype,
)


from . import exceptions
from .typing import (
OutputType,
Expand All @@ -119,6 +118,10 @@
ColumnInputType,
)


__all__ = ["Dataset"]


INTERNAL_COLUMN_NAMES = ["__last_edited_by__", "__last_edited_at__"]
INTERNAL_COLUMN_DTYPES = [str_dtype, datetime_dtype]

Expand Down
44 changes: 44 additions & 0 deletions renumics/spotlight/dtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@
from .legacy import Audio, Category, Embedding, Image, Mesh, Sequence1D, Video, Window


__all__ = [
"CategoryDType",
"Sequence1DDType",
"bool_dtype",
"int_dtype",
"float_dtype",
"str_dtype",
"datetime_dtype",
"category_dtype",
"window_dtype",
"embedding_dtype",
"array_dtype",
"image_dtype",
"audio_dtype",
"mesh_dtype",
"sequence_1d_dtype",
"video_dtype",
]


class DType:
_name: str

Expand All @@ -22,6 +42,10 @@ def name(self) -> str:


class CategoryDType(DType):
"""
Categorical dtype with predefined categories.
"""

_categories: Optional[Dict[str, int]]
_inverted_categories: Optional[Dict[int, str]]

Expand Down Expand Up @@ -57,6 +81,10 @@ def inverted_categories(self) -> Optional[Dict[int, str]]:


class Sequence1DDType(DType):
"""
1D-sequence dtype with predefined axis labels.
"""

x_label: str
y_label: str

Expand All @@ -78,36 +106,52 @@ def register_dtype(dtype: DType, aliases: list) -> None:


bool_dtype = DType("bool")
"""Bool dtype"""
register_dtype(bool_dtype, [bool])
int_dtype = DType("int")
"""Integer dtype"""
register_dtype(int_dtype, [int])
float_dtype = DType("float")
"""Float dtype"""
register_dtype(float_dtype, [float])
bytes_dtype = DType("bytes")
"""Bytes dtype"""
register_dtype(bytes_dtype, [bytes])
str_dtype = DType("str")
"""String dtype"""
register_dtype(str_dtype, [str])
datetime_dtype = DType("datetime")
"""Datetime dtype"""
register_dtype(datetime_dtype, [datetime])
category_dtype = CategoryDType()
"""Categorical dtype with arbitraty categories"""
register_dtype(category_dtype, [Category])
window_dtype = DType("Window")
"""Window dtype"""
register_dtype(window_dtype, [Window])
embedding_dtype = DType("Embedding")
"""Embedding dtype"""
register_dtype(embedding_dtype, [Embedding])
array_dtype = DType("array")
"""numpy array dtype"""
register_dtype(array_dtype, [np.ndarray])
image_dtype = DType("Image")
"""Image dtype"""
register_dtype(image_dtype, [Image])
audio_dtype = DType("Audio")
"""Audio dtype"""
register_dtype(audio_dtype, [Audio])
mesh_dtype = DType("Mesh")
"""Mesh dtype"""
register_dtype(mesh_dtype, [Mesh])
sequence_1d_dtype = Sequence1DDType()
"""1D-sequence dtype with arbitraty axis labels"""
register_dtype(sequence_1d_dtype, [Sequence1D])
video_dtype = DType("Video")
"""Video dtype"""
register_dtype(video_dtype, [Video])
mixed_dtype = DType("mixed")
"""Unknown or mixed dtype"""


DTypeMap = Dict[str, DType]
Expand Down
16 changes: 16 additions & 0 deletions renumics/spotlight/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@
)


__all__ = [
"layout",
"split",
"tab",
"histogram",
"inspector",
"scatterplot",
"similaritymap",
"table",
"issues",
"wordcloud",
"confusion_matrix",
"metric",
]


_WidgetLike = Union[_Widget, str]
_NodeLike = Union[Split, Tab, _WidgetLike, List]
_LayoutLike = Union[str, os.PathLike, Layout, _NodeLike]
Expand Down
2 changes: 1 addition & 1 deletion renumics/spotlight/layout/lenses.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Viewers (lenses) for Spotlight inspector widget.

For usage examples, see `renumics.spotlighth.layout.inspector`.
For usage examples, see `renumics.spotlight.layout.inspector`.
"""

import uuid
Expand Down