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

refactor: Remove toolz dependency #3426

Merged
merged 34 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
546b4e0
refactor: Remove `toolz.curried.pipe` dependency in `vegalite.v5.api`
dangotbanned May 26, 2024
3caf7ff
refactor: Remove unneeded `@curried.curry` from `to_values`
dangotbanned May 26, 2024
d36a2c4
refactor: Remove `toolz.curried.pipe` dependency in `_magics`
dangotbanned May 26, 2024
d6dce19
refactor: Replaced attribute checks with instance checks for `Support…
dangotbanned May 26, 2024
aae983a
refactor: Simplified `check_data_type`
dangotbanned May 26, 2024
b9dc070
refactor: Remove `@curried.curry` dependency from `limit_rows`
dangotbanned May 26, 2024
c33433f
refactor: Remove `@curried.curry` dependency from `sample`
dangotbanned May 26, 2024
8a9d593
refactor: Remove `@curried.curry` dependency from `to_json`, `to_csv`
dangotbanned May 26, 2024
bf99d72
refactor: Remove top-level `toolz` dependency from `utils.data`
dangotbanned May 26, 2024
26e77c4
refactor: Remove `toolz` dependency in `vegalite.data`
dangotbanned May 26, 2024
3800fc5
refactor: Remove `@curried.curry` dependency in `utils._vegafusion_data`
dangotbanned May 26, 2024
b706a94
fix: Update `DataTransformerType` to describe currying
dangotbanned May 26, 2024
cf54ec2
refactor: Remove `toolz.curry` dependency in `utils.plugin_registry`
dangotbanned May 26, 2024
78d1a7c
fix: Ignore special form not a type
dangotbanned May 26, 2024
8cd40e2
fix: drop `type` subscript, not available in earlier versions
dangotbanned May 26, 2024
8bfaf41
fix: Use 3.8 compatible `typing.Callable` over `collections.abc`
dangotbanned May 26, 2024
f34eb6f
test: Remove `toolz.pipe` dependency in `test_data`
dangotbanned Jun 6, 2024
48eb2aa
build: drop `toolz` dependency
dangotbanned Jun 6, 2024
1e8167b
refactor: Implement optional `toolz` imports
dangotbanned Jun 6, 2024
2f5aa56
test: adds `test_toolz` covering both `pipe`, `curry`
dangotbanned Jun 6, 2024
60b8231
test: fix assert match on `test_toolz`
dangotbanned Jun 6, 2024
a8e537f
refactor(typing): Replace `Literal[None]` -> `None
dangotbanned Jun 13, 2024
b0d0e5c
refactor(typing): Replace single-use `NonLikeDataType` alias with `Un…
dangotbanned Jun 13, 2024
6484161
feat: Remove `alt.curry`, `alt.pipe`
dangotbanned Jun 14, 2024
3e4edcb
test: add `F821` ignores in `test_toolz`
dangotbanned Jun 14, 2024
650ee0e
maint: Remove `test_toolz`
dangotbanned Jun 14, 2024
ed13af6
Merge branch 'main' into remove-toolz-depend
dangotbanned Jun 18, 2024
7b6e0d7
chore: merge main
dangotbanned Jun 18, 2024
7b0e5d8
Merge branch 'remove-toolz-depend' of https://github.com/dangotbanned…
dangotbanned Jun 18, 2024
88fbd11
revert: remove now-uneeded `import_toolz_function`
dangotbanned Jun 18, 2024
bd949a9
fix(typing): add missing `...` for some overloads
dangotbanned Jun 18, 2024
5780f21
docs(typing): Remove `NonGeoDataType` and amend error message in `_da…
dangotbanned Jun 19, 2024
9f0d58a
fix: ensure `SupportsGeoInterface` branch is triggered in `vegafusion…
dangotbanned Jun 19, 2024
7a84764
Merge branch 'vega:main' into remove-toolz-depend
dangotbanned Jun 19, 2024
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
2 changes: 0 additions & 2 deletions altair/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@
"concat",
"condition",
"core",
"curry",
"data",
"data_transformers",
"datum",
Expand All @@ -591,7 +590,6 @@
"overload",
"param",
"parse_shorthand",
"pipe",
"renderers",
"repeat",
"sample",
Expand Down
5 changes: 3 additions & 2 deletions altair/_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import IPython
from IPython.core import magic_arguments
import pandas as pd
from toolz import curried

from altair.vegalite import v5 as vegalite_v5

Expand Down Expand Up @@ -41,7 +40,9 @@ def _prepare_data(data, data_transformers):
if data is None or isinstance(data, dict):
return data
elif isinstance(data, pd.DataFrame):
return curried.pipe(data, data_transformers.get())
if func := data_transformers.get():
data = func(data)
return data
elif isinstance(data, str):
return {"url": data}
else:
Expand Down
3 changes: 2 additions & 1 deletion altair/utils/_importers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from importlib.metadata import version as importlib_version
from types import ModuleType

from packaging.version import Version
from importlib.metadata import version as importlib_version


def import_vegafusion() -> ModuleType:
Expand Down
53 changes: 41 additions & 12 deletions altair/utils/_vegafusion_data.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
from toolz import curried
from __future__ import annotations
import uuid
from weakref import WeakValueDictionary

from typing import (
Any,
Optional,
Union,
Dict,
Set,
MutableMapping,
TypedDict,
Final,
TYPE_CHECKING,
overload,
Callable,
)

from altair.utils._importers import import_vegafusion
from altair.utils.core import DataFrameLike
from altair.utils.data import DataType, ToValuesReturnType, MaxRowsError
from altair.utils.data import (
DataType,
ToValuesReturnType,
MaxRowsError,
SupportsGeoInterface,
)
from altair.vegalite.data import default_data_transformer

if TYPE_CHECKING:
import pandas as pd
from vegafusion.runtime import ChartState # type: ignore

# Temporary storage for dataframes that have been extracted
Expand All @@ -36,21 +45,41 @@ class _ToVegaFusionReturnUrlDict(TypedDict):
url: str


@curried.curry
_VegaFusionReturnType = Union[_ToVegaFusionReturnUrlDict, ToValuesReturnType]


@overload
def vegafusion_data_transformer(
data: None = ..., max_rows: int = ...
) -> Callable[..., Any]: ...


@overload
def vegafusion_data_transformer(
data: DataFrameLike, max_rows: int
) -> ToValuesReturnType: ...


@overload
def vegafusion_data_transformer(
data: DataType, max_rows: int = 100000
) -> Union[_ToVegaFusionReturnUrlDict, ToValuesReturnType]:
data: Union[dict, pd.DataFrame, SupportsGeoInterface], max_rows: int
) -> _VegaFusionReturnType: ...


def vegafusion_data_transformer(
data: Optional[DataType] = None, max_rows: int = 100000
) -> Union[Callable[..., Any], _VegaFusionReturnType]:
"""VegaFusion Data Transformer"""
if hasattr(data, "__geo_interface__"):
dangotbanned marked this conversation as resolved.
Show resolved Hide resolved
# Use default transformer for geo interface objects
# # (e.g. a geopandas GeoDataFrame)
return default_data_transformer(data)
elif isinstance(data, DataFrameLike):
if data is None:
return vegafusion_data_transformer
elif isinstance(data, DataFrameLike) and not isinstance(data, SupportsGeoInterface):
table_name = f"table_{uuid.uuid4()}".replace("-", "_")
extracted_inline_tables[table_name] = data
return {"url": VEGAFUSION_PREFIX + table_name}
else:
# Use default transformer if we don't recognize data type
# Use default transformer for geo interface objects
# # (e.g. a geopandas GeoDataFrame)
# Or if we don't recognize data type
return default_data_transformer(data)


Expand Down
Loading