Skip to content

Commit

Permalink
refactor: Simplify obsolete paths in CsvCache
Browse files Browse the repository at this point in the history
They were an artifact of *previously* using multiple `vega-dataset` versions in `.paquet` - but only the most recent in `.csv.gz`

Currently both store the same range of names, so this error handling never triggered
  • Loading branch information
dangotbanned committed Jan 29, 2025
1 parent b606a7d commit 2203972
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions altair/datasets/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
from collections import defaultdict
from importlib.util import find_spec
from pathlib import Path
from typing import TYPE_CHECKING, ClassVar, TypeVar, cast, get_args
from typing import TYPE_CHECKING, ClassVar, TypeVar, cast

import narwhals.stable.v1 as nw

from altair.datasets._exceptions import AltairDatasetsError
from altair.datasets._typing import Dataset

if sys.version_info >= (3, 12):
from typing import Protocol
Expand All @@ -34,7 +33,7 @@
from narwhals.stable.v1.dtypes import DType
from narwhals.stable.v1.typing import IntoExpr

from altair.datasets._typing import Metadata
from altair.datasets._typing import Dataset, Metadata

if sys.version_info >= (3, 12):
from typing import Unpack
Expand Down Expand Up @@ -188,31 +187,17 @@ def rotated(self) -> Mapping[str, Sequence[Any]]:
self._rotated[k].append(v)
return self._rotated

# TODO: Evaluate which errors are now obsolete
def __getitem__(self, key: _Dataset, /) -> Metadata:
if meta := self.get(key, None):
return meta
msg = f"{key!r} does not refer to a known dataset."
raise TypeError(msg)

if key in get_args(Dataset):
msg = f"{key!r} cannot be loaded via {type(self).__name__!r}."
raise TypeError(msg)
else:
msg = f"{key!r} does not refer to a known dataset."
raise TypeError(msg)

# TODO: Evaluate which errors are now obsolete
def url(self, name: _Dataset, /) -> str:
if meta := self.get(name, None):
if meta["suffix"] == ".parquet" and not find_spec("vegafusion"):
raise AltairDatasetsError.from_url(meta)
return meta["url"]

if name in get_args(Dataset):
msg = f"{name!r} cannot be loaded via url."
raise TypeError(msg)
else:
msg = f"{name!r} does not refer to a known dataset."
raise TypeError(msg)
meta = self[name]
if meta["suffix"] == ".parquet" and not find_spec("vegafusion"):
raise AltairDatasetsError.from_url(meta)
return meta["url"]

def __repr__(self) -> str:
return f"<{type(self).__name__}: {'COLLECTED' if self._mapping else 'READY'}>"
Expand Down

0 comments on commit 2203972

Please sign in to comment.