Skip to content

Commit

Permalink
feat: better handle spotlight.show() without a dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
neindochoh committed Feb 20, 2024
1 parent 6c9c954 commit bfd23aa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
10 changes: 5 additions & 5 deletions renumics/spotlight/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ def update(self, config: AppConfig) -> None:
self.filebrowsing_allowed = config.filebrowsing_allowed

if config.dtypes is not None or config.dataset is not None:
assert self._data_source is not None
self._data_store = DataStore(self._data_source, self._user_dtypes)
self._broadcast(RefreshMessage())
self._update_issues()
self._update_embeddings()
if self._data_source is not None:
self._data_store = DataStore(self._data_source, self._user_dtypes)
self._broadcast(RefreshMessage())
self._update_issues()
self._update_embeddings()
if config.layout is not None:
if self._data_store is not None:
dataset_uid = self._data_store.uid
Expand Down
2 changes: 1 addition & 1 deletion renumics/spotlight/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(

def show(
self,
dataset: Union[PathType, pd.DataFrame, None],
dataset: Union[PathType, pd.DataFrame, None] = None,
folder: Optional[PathType] = None,
layout: Optional[_LayoutLike] = None,
no_browser: bool = False,
Expand Down
20 changes: 12 additions & 8 deletions renumics/spotlight_plugins/core/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ComputedColumnNotReady,
FilebrowsingNotAllowed,
InvalidPath,
Problem,
)
from renumics.spotlight.io.path import is_path_relative_to
from renumics.spotlight.reporting import emit_timed_event
Expand Down Expand Up @@ -50,6 +51,16 @@ class Table(BaseModel):
router = APIRouter()


class NoDataSource(Problem):
def __init__(self, filebrowsing_allowed: bool):
if filebrowsing_allowed:
text = "No dataset provided. Please select a dataset with `.show(dataset)` or with the filebrowser."
else:
text = "No dataset provided. Please select a dataset with `.show(dataset)`."

super().__init__("No Dataset", text, 404)


@router.get(
"/",
response_model=Table,
Expand All @@ -65,14 +76,7 @@ def get_table(request: Request) -> ORJSONResponse:
app: SpotlightApp = request.app
data_store = app.data_store
if data_store is None:
return ORJSONResponse(
Table(
uid="",
filename="",
columns=[],
generation_id=-1,
).model_dump()
)
raise NoDataSource(app.filebrowsing_allowed)

columns = []
for column_name in data_store.column_names:
Expand Down
2 changes: 2 additions & 0 deletions src/stores/dataset/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export const useDataset = create(
filename,
length: dataframe.length,
loading: false,
loadingError: undefined,
columns: dataframe.columns,
columnsByKey: _.keyBy(dataframe.columns, 'key'),
columnData: dataframe.data,
Expand Down Expand Up @@ -321,6 +322,7 @@ export const useDataset = create(
filename,
length: dataframe.length,
loading: false,
loadingError: undefined,
columns: dataframe.columns,
columnsByKey: _.keyBy(dataframe.columns, 'key'),
columnData: dataframe.data,
Expand Down

0 comments on commit bfd23aa

Please sign in to comment.