Skip to content

Commit

Permalink
Merge branch 'main' into fix/232-fallback-for-simple-converters
Browse files Browse the repository at this point in the history
  • Loading branch information
druzsan committed Oct 26, 2023
2 parents 63a2845 + d16dbb3 commit 122015f
Show file tree
Hide file tree
Showing 15 changed files with 411 additions and 364 deletions.
22 changes: 20 additions & 2 deletions renumics/spotlight/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from typing_extensions import Annotated
from fastapi import Cookie, FastAPI, Request, status
from fastapi.datastructures import Headers
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, Response
from fastapi.staticfiles import StaticFiles
Expand Down Expand Up @@ -56,10 +57,23 @@

from renumics.spotlight.dtypes import DTypeMap


CURRENT_LAYOUT_KEY = "layout.current"


class UncachedStaticFiles(StaticFiles):
"""
FastAPI StaticFiles but without caching
"""

def is_not_modified(
self, response_headers: Headers, request_headers: Headers
) -> bool:
"""
Never Cache
"""
return False


class IssuesUpdatedMessage(Message):
"""
Notify about updated issues.
Expand Down Expand Up @@ -207,9 +221,13 @@ async def _(_: Request, problem: Problem) -> JSONResponse:
plugin.activate(self)

try:
# Mount frontend files as uncached,
# so that we always get the new frontend after updating spotlight.
# NOTE: we might not need this if we added a version hash
# to our built js files
self.mount(
"/static",
StaticFiles(packages=["renumics.spotlight.backend"]),
UncachedStaticFiles(packages=["renumics.spotlight.backend"]),
name="assets",
)
except AssertionError:
Expand Down
16 changes: 6 additions & 10 deletions renumics/spotlight/backend/tasks/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
import pandas as pd

from renumics.spotlight.dataset.exceptions import ColumnNotExistsError
from renumics.spotlight.data_store import DataStore
from renumics.spotlight import dtypes

Expand Down Expand Up @@ -80,10 +79,8 @@ def compute_umap(
Prepare data from table and compute U-Map on them.
"""

try:
data, indices = align_data(data_store, column_names, indices)
except (ColumnNotExistsError, ColumnNotEmbeddable):
return np.empty(0, np.float64), []
data, indices = align_data(data_store, column_names, indices)

if data.size == 0:
return np.empty(0, np.float64), []

Expand Down Expand Up @@ -116,14 +113,13 @@ def compute_pca(
Prepare data from table and compute PCA on them.
"""

from sklearn import preprocessing, decomposition
data, indices = align_data(data_store, column_names, indices)

try:
data, indices = align_data(data_store, column_names, indices)
except (ColumnNotExistsError, ColumnNotEmbeddable):
return np.empty(0, np.float64), []
if data.size == 0:
return np.empty(0, np.float64), []

from sklearn import preprocessing, decomposition

if data.shape[1] == 1:
return np.hstack((data, np.zeros_like(data))), indices
if normalization == "standardize":
Expand Down
11 changes: 8 additions & 3 deletions renumics/spotlight/backend/tasks/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import multiprocessing
from concurrent.futures import Future, ProcessPoolExecutor
from concurrent.futures.process import BrokenProcessPool
from typing import Any, Callable, List, Optional, Sequence, TypeVar, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, TypeVar, Union

from .exceptions import TaskCancelled
from .task import Task
Expand All @@ -30,16 +30,20 @@ def create_task(
self,
func: Callable,
args: Sequence[Any],
kwargs: Optional[Dict[str, Any]] = None,
name: Optional[str] = None,
tag: Optional[Union[str, int]] = None,
) -> Task:
"""
create and launch a new task
"""
if kwargs is None:
kwargs = {}

# cancel running task with same name
self.cancel(name=name)

future = self.pool.submit(func, *args)
future = self.pool.submit(func, *args, **kwargs)

task = Task(name, tag, future)
self.tasks.append(task)
Expand All @@ -59,14 +63,15 @@ async def run_async(
self,
func: Callable[..., T],
args: Sequence[Any],
kwargs: Optional[Dict[str, Any]] = None,
name: Optional[str] = None,
tag: Optional[Union[str, int]] = None,
) -> T:
"""
Launch a new task. Await and return result.
"""

task = self.create_task(func, args, name, tag)
task = self.create_task(func, args=args, kwargs=kwargs, name=name, tag=tag)
try:
return await asyncio.wrap_future(task.future)
except BrokenProcessPool as e:
Expand Down
Loading

0 comments on commit 122015f

Please sign in to comment.