Skip to content

Commit

Permalink
Add back Table and View exports, make constructors throw like pyarrow…
Browse files Browse the repository at this point in the history
….Table

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
  • Loading branch information
timkpaine committed Nov 6, 2024
1 parent b9af3bd commit 2268aa3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@
"install_llvm": "node tools/perspective-scripts/install_llvm.mjs",
"install_pyodide": "node tools/perspective-scripts/install_pyodide.mjs",
"build,test": "npm run --silent build && npm run --silent test",
"build_js": "node tools/perspective-scripts/build_js.mjs",
"build_js": "node tools/perspective-scripts/build.mjs",
"build": "node tools/perspective-scripts/build.mjs",
"build_python": "node tools/perspective-scripts/build_python.mjs",
"build_python": "node tools/perspective-scripts/build.mjs",
"bench": "node tools/perspective-scripts/bench.mjs",
"_wheel_python": "node tools/perspective-scripts/_wheel_python.mjs",
"_requires_python": "node tools/perspective-scripts/_requires_python.mjs",
"setup": "node tools/perspective-scripts/setup.mjs",
"docs": "node tools/perspective-scripts/docs.mjs",
"test": "node tools/perspective-scripts/test.mjs",
Expand Down
4 changes: 4 additions & 0 deletions rust/perspective-python/perspective/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
PerspectiveError,
ProxySession,
PySyncServer as Server,
# NOTE: these are classes without constructors,
# so we import them just for type hinting
Table, # noqa: F401
View, # noqa: F401
)


Expand Down
12 changes: 12 additions & 0 deletions rust/perspective-python/perspective/tests/table/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@


class TestException(object):
def test_instantiation_exception_table(self):
from perspective import Table
with raises(TypeError) as ex:
Table()
assert "Do not call Table's constructor directly" in str(ex.value)

def test_instantiation_exception_view(self):
from perspective import View
with raises(TypeError) as ex:
View()
assert "Do not call View's constructor directly" in str(ex.value)

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

Expand Down
11 changes: 11 additions & 0 deletions rust/perspective-python/src/client/client_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use perspective_client::{assert_table_api, assert_view_api, Session};
#[cfg(doc)]
use perspective_client::{config::ViewConfigUpdate, Schema, TableInitOptions, UpdateOptions};
use pollster::FutureExt;
use pyo3::exceptions::PyTypeError;
use pyo3::marker::Ungil;
use pyo3::prelude::*;
use pyo3::types::*;
Expand Down Expand Up @@ -152,6 +153,11 @@ assert_table_api!(Table);

#[pymethods]
impl Table {
#[new]
fn new() -> PyResult<Self> {
Err(PyTypeError::new_err("Do not call Table's constructor directly, construct from a Client instance."))
}

#[doc = crate::inherit_docs!("table/get_index.md")]
pub fn get_index(&self) -> Option<String> {
self.0.get_index().block_on()
Expand Down Expand Up @@ -261,6 +267,11 @@ assert_view_api!(View);

#[pymethods]
impl View {
#[new]
fn new() -> PyResult<Self> {
Err(PyTypeError::new_err("Do not call View's constructor directly, construct from a Table instance."))
}

#[doc = crate::inherit_docs!("view/column_paths.md")]
pub fn column_paths(&self) -> PyResult<Vec<String>> {
self.0.column_paths().block_on()
Expand Down

0 comments on commit 2268aa3

Please sign in to comment.