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

[proposal] Rename rust-to-python exports to be cleaner, normalize exception names #2663

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 5 additions & 4 deletions rust/perspective-python/perspective/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

__version__ = "2.10.1"
__all__ = [
"PySyncClient",
"Client",
"PerspectivePythonError",
"PerspectiveBaseException",
"PerspectiveError",
"PerspectivePyError",
"PerspectiveWidget",
"PerspectiveViewer",
"PerspectiveTornadoHandler",
Expand All @@ -25,8 +26,8 @@
"create_sync_client",
]

from .perspective import PySyncClient, PerspectivePyError
from .core.exception import PerspectiveError
from .perspective import Client, PerspectiveError, PerspectiveBaseException
from .core.exception import PerspectivePythonError

from .legacy import (
PerspectiveManager,
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-python/perspective/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

from .exception import PerspectiveError
from .exception import PerspectivePythonError
4 changes: 3 additions & 1 deletion rust/perspective-python/perspective/core/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

from ..perspective import PerspectiveBaseException

class PerspectiveError(Exception):

class PerspectivePythonError(PerspectiveBaseException):
"""Raised for issues within Perspective, i.e. illegal operations."""

pass
2 changes: 1 addition & 1 deletion rust/perspective-python/perspective/core/globalpsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Awaitable, Callable
import perspective

_psp_server = perspective.PySyncServer()
_psp_server = perspective.Server()


class Session:
Expand Down
4 changes: 2 additions & 2 deletions rust/perspective-python/perspective/handlers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from abc import ABC, abstractmethod
import functools

from ..core.exception import PerspectiveError
from ..core.exception import PerspectivePythonError


class PerspectiveHandlerBase(ABC):
Expand All @@ -34,7 +34,7 @@ def __init__(self, **kwargs):
"""
self._manager = kwargs.pop("manager", None)
if self._manager is None:
raise PerspectiveError("A `PerspectiveManager` instance must be provided to the handler!")
raise PerspectivePythonError("A `PerspectiveManager` instance must be provided to the handler!")

self._check_origin = kwargs.pop("check_origin", False)

Expand Down
6 changes: 3 additions & 3 deletions rust/perspective-python/perspective/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

from .perspective import PySyncServer, PySyncClient
from .perspective import Server, Client
import types
import sys

Expand All @@ -27,9 +27,9 @@ def handle_sync_client(bytes):
def handle_new_session(bytes):
local_sync_client.handle_response(bytes)

sync_server = PySyncServer()
sync_server = Server()
sync_session = sync_server.new_session(handle_new_session)
local_sync_client = PySyncClient(handle_sync_client)
local_sync_client = Client(handle_sync_client)
return local_sync_client


Expand Down
4 changes: 2 additions & 2 deletions rust/perspective-python/perspective/tests/core/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from functools import partial

import tornado.ioloop
from perspective import PerspectiveError, PerspectiveManager, Table, create_sync_client
from perspective import PerspectivePythonError, PerspectiveManager, Table, create_sync_client
from pytest import mark, raises


Expand Down Expand Up @@ -116,7 +116,7 @@ def test_async_call_loop_error_if_no_loop(self):
)
tbl = client.table({"a": "integer", "b": "float", "c": "string"})

with raises(PerspectiveError):
with raises(PerspectivePythonError):
# loop not set - errors
tbl.update(data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from datetime import datetime
from functools import partial
from pytest import raises, mark
from perspective import Table, PerspectiveError, PerspectiveManager, create_sync_client
from perspective import Table, PerspectivePythonError, PerspectiveManager, create_sync_client

data = {"a": [1, 2, 3], "b": ["a", "b", "c"]}

Expand Down Expand Up @@ -197,7 +197,7 @@ def test_manager_clear_view_no_client_id(self):
manager.host_table("table1", table)
for message in messages:
manager._process(message, self.post)
with raises(PerspectiveError):
with raises(PerspectivePythonError):
manager.clear_views(None)

# locked manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

from pytest import raises
from perspective import Table, PerspectivePyError
from perspective import Table, PerspectiveError


class TestException(object):
def test_exception_from_core(self):
tbl = Table({"a": [1, 2, 3]})

with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
# creating view with unknown column should throw
tbl.view(group_by=["b"])

Expand All @@ -35,8 +35,8 @@ def test_exception_from_core_catch_generic(self):
def test_exception_from_core_correct_types(self):
tbl = Table({"a": [1, 2, 3]})

# `PerspectiveError` should be raised from the Python layer
with raises(PerspectivePyError) as ex:
# `PerspectivePythonError` should be raised from the Python layer
with raises(PerspectiveError) as ex:
tbl.view()
tbl.delete()

Expand All @@ -45,7 +45,7 @@ def test_exception_from_core_correct_types(self):
== "Abort(): Cannot delete table with views"
)

with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(group_by=["b"])

assert str(ex.value) == "Abort(): Invalid column 'b' found in View group_by.\n"
6 changes: 3 additions & 3 deletions rust/perspective-python/perspective/tests/table/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys
from datetime import date, datetime, timezone

from perspective.core.exception import PerspectiveError
from perspective.core.exception import PerspectivePythonError
from perspective import Table
import perspective
from pytest import mark, raises, skip
Expand Down Expand Up @@ -434,7 +434,7 @@ def test_table_index_float_with_none(self):

def test_table_index_bool_with_none(self):
# bools cannot be used as primary key columns
with raises(perspective.PerspectivePyError):
with raises(perspective.PerspectiveError):
Table({"a": [True, False, None, True], "b": [4, 3, 2, 1]}, index="a")

def test_table_index_date_with_none(self):
Expand Down Expand Up @@ -527,7 +527,7 @@ def test_table_get_num_views(self):
failed = False
try:
tbl.delete()
except PerspectiveError:
except PerspectivePythonError:
failed = True
assert failed
v3.delete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from datetime import date, datetime, timedelta
from dateutil import tz
from pytest import mark, raises
from perspective import Table, PerspectivePyError
from perspective import Table, PerspectiveError

LOCAL_DATETIMES = [
datetime(2019, 1, 11, 0, 10, 20),
Expand Down Expand Up @@ -212,7 +212,7 @@ def test_table_datetime_min_epoch(self, util):
def test_table_datetime_cant_convert_from_int(self):
data = pd.DataFrame({"a": [0]})
table = Table({"a": "datetime"})
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
table.update(data)
# assert str(ex.value) == "..."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import numpy as np
import pandas as pd
from perspective import PerspectiveError
from perspective import PerspectivePythonError
from perspective.table import Table
from pytest import raises, mark

Expand Down Expand Up @@ -497,7 +497,7 @@ def test_table_np_mixed(self):
}

# should not be able to parse mixed dicts of numpy array with list
with raises(PerspectiveError):
with raises(PerspectivePythonError):
Table(data)

def test_table_np_promote(self):
Expand Down
24 changes: 12 additions & 12 deletions rust/perspective-python/perspective/tests/table/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import random
import pandas as pd
import numpy as np
from perspective import PerspectivePyError, Table
from perspective import PerspectiveError, Table
from datetime import date, datetime
from pytest import approx, mark, raises

Expand Down Expand Up @@ -1558,7 +1558,7 @@ def test_view_delete(self):
data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
tbl = Table(data)
view = tbl.view()
with raises(PerspectivePyError):
with raises(PerspectiveError):
tbl.delete()
view.delete()
tbl.delete()
Expand Down Expand Up @@ -2113,15 +2113,15 @@ def test_view_expand_two_column_only(self):
def test_invalid_column_should_throw(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(columns=["x"])
assert str(ex.value) == "Abort(): Invalid column 'x' found in View columns.\n"

def test_invalid_column_should_throw_and_updates_should_work(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)

with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(columns=["x"])
assert str(ex.value) == "Abort(): Invalid column 'x' found in View columns.\n"

Expand All @@ -2137,7 +2137,7 @@ def test_invalid_column_aggregate_should_throw(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)

with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(columns=["x"], aggregates={"x": "sum"})

assert str(ex.value) == "Abort(): Invalid column 'x' found in View columns.\n"
Expand All @@ -2146,7 +2146,7 @@ def test_invalid_column_aggregate_should_throw_and_updates_should_work(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)

with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(columns=["x"], aggregates={"x": "sum"})

assert str(ex.value) == "Abort(): Invalid column 'x' found in View columns.\n"
Expand All @@ -2162,35 +2162,35 @@ def test_invalid_column_aggregate_should_throw_and_updates_should_work(self):
def test_invalid_group_by_should_throw(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(group_by=["x"])
assert str(ex.value) == "Abort(): Invalid column 'x' found in View group_by.\n"

def test_invalid_split_by_should_throw(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(split_by=["x"])
assert str(ex.value) == "Abort(): Invalid column 'x' found in View split_by.\n"

def test_invalid_filters_should_throw(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(filter=[["x", "==", "abc"]])
assert str(ex.value) == "Abort(): Filter column not in schema: x"

def test_invalid_sorts_should_throw(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(sort=[["x", "desc"]])
assert str(ex.value) == "Abort(): Invalid column 'x' found in View sorts.\n"

def test_should_throw_on_first_invalid(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(
group_by=["a"],
split_by=["c"],
Expand All @@ -2203,7 +2203,7 @@ def test_should_throw_on_first_invalid(self):
def test_invalid_columns_not_in_expression_should_throw(self):
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
tbl = Table(data)
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
tbl.view(columns=["abc", "x"], expressions={"abc": "1 + 2"})
assert str(ex.value) == "Abort(): Invalid column 'x' found in View columns.\n"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pytest import raises
from datetime import date, datetime
from time import mktime
from perspective import Table, PerspectivePyError
from perspective import Table, PerspectiveError
import pytest
from .test_view import compare_delta

Expand Down Expand Up @@ -516,7 +516,7 @@ def test_view_expression_create_no_alias(self):

def test_view_expression_should_not_overwrite_real(self):
table = Table({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]})
with raises(PerspectivePyError) as ex:
with raises(PerspectiveError) as ex:
table.view(expressions={"a": 'upper("a")'})

assert (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pytest import raises

from perspective.core import PerspectiveError
from perspective.core import PerspectivePythonError

# from perspective.core import Plugin
# import perspective.viewer.validate as validate
Expand All @@ -30,19 +30,19 @@
# assert validate.validate_plugin("X Bar") == "X Bar"

# def test_validate_plugin_invalid_string(self):
# with raises(PerspectiveError):
# with raises(PerspectivePythonError):
# validate.validate_plugin("invalid")

# def test_validate_plugin_invalid_string_hypergrid(self):
# with raises(PerspectiveError):
# with raises(PerspectivePythonError):
# validate.validate_plugin("hypergrid")

# def test_validate_filter_valid(self):
# filters = [["a", ">", 1], ["b", "==", "abc"]]
# assert validate.validate_filter(filters) == filters

# def test_validate_filter_invalid(self):
# with raises(PerspectiveError):
# with raises(PerspectivePythonError):
# filters = [["a", ">"], ["b", "invalid" "abc"]]
# validate.validate_filter(filters)

Expand All @@ -55,12 +55,12 @@
# assert validate.validate_filter(filters) == filters

# def test_validate_expressions(self):
# # with raises(PerspectiveError):
# # with raises(PerspectivePythonError):
# computed = {"expression1": " 'Hello'"}
# validate.validate_expressions(computed)

# def test_validate_expressions_invalid(self):
# with raises(PerspectiveError):
# with raises(PerspectivePythonError):
# assert validate.validate_expressions("test")

# def test_validate_version(self):
Expand Down
Loading
Loading