Skip to content

Commit

Permalink
Add docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Jun 13, 2022
1 parent 3b9b39d commit 477b5da
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
2 changes: 2 additions & 0 deletions python/perspective/docs/perspective.core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Additionally, ``perspective.core`` defines several enums that provide easy acces

For usage of ``PerspectiveWidget`` and ``PerspectiveTornadoHandler``, see the User Guide in the sidebar.

.. autofunction:: perspective.set_threadpool_size

.. automodule:: perspective.core
:members:
:show-inheritance:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
################################################################################
#
# Copyright (c) 2019, the Perspective Authors.
#
# This file is part of the Perspective library, distributed under the terms of
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

################################################################################
#
# Copyright (c) 2019, the Perspective Authors.
#
# This file is part of the Perspective library, distributed under the terms of
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import pandas as pd
from perspective import Table, set_threadpool_size

set_threadpool_size(1)


class TestThreadPoolOne:
def test_threadpool_one_does_not_block_view(self):
t = Table(
{"id": int, "symbol": str, "valid": bool, "value": int, "value2": int},
index="id",
)
t.update(
[
{"id": 1, "symbol": "A", "valid": False, "value": 5, "value2": 15},
{"id": 2, "symbol": "A", "valid": True, "value": 10, "value2": 20},
]
)

v = t.view(
columns=["symbol", "value", "value3"],
expressions=["""//value3\n"value" + "value2\""""],
)

v_agg = t.view(
columns=["symbol", "value", "value3"],
expressions=["""//value3\n"value" + "value2\""""],
group_by=["symbol"],
aggregates={"symbol": "first", "value": "sum", "value2": "sum"},
)

df_flat = v.to_df()
pd.util.testing.assert_frame_equal(
df_flat,
pd.DataFrame.from_records(
[("A", 5, 20.0), ("A", 10, 30.0)],
index=[0, 1],
columns=["symbol", "value", "value3"],
),
)

df_agg = v_agg.to_df()
pd.util.testing.assert_frame_equal(
df_agg,
pd.DataFrame.from_records(
[(list([]), "A", 15, 50.0), (list(["A"]), "A", 15, 50.0)],
index=[0, 1],
columns=["__ROW_PATH__", "symbol", "value", "value3"],
),
)
28 changes: 20 additions & 8 deletions scripts/test_python.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ const pytest_client_mode = (IS_DOCKER) => {
}
};

/**
* Run pytest for single-threaded tests
*/
const pytest_single_threaded = (IS_DOCKER) => {
if (IS_DOCKER) {
return bash`${docker(IMAGE)} bash -c "cd \
python/perspective && TZ=UTC PYTHONMALLOC=debug ${PYTHON} -m pytest \
${VERBOSE ? "-vv --full-trace" : ""} --noconftest
perspective/tests/single_threaded"`;
} else {
return bash`cd ${python_path} && PYTHONMALLOC=debug ${PYTHON} -m pytest \
${VERBOSE ? "-vv --full-trace" : ""} --noconftest
--disable-pytest-warnings
perspective/tests/single_threaded`;
}
};

/**
* Run `pytest` for the `perspective-python` library.
*/
Expand All @@ -78,12 +95,14 @@ const pytest = (IS_DOCKER) => {
python/perspective && TZ=UTC PYTHONMALLOC=debug ${PYTHON} -m pytest \
${VERBOSE ? "-vv --full-trace" : ""} perspective \
--ignore=perspective/tests/client_mode \
--ignore=perspective/tests/single_threaded \
--disable-pytest-warnings
--cov=perspective"`;
} else {
return bash`cd ${python_path} && PYTHONMALLOC=debug ${PYTHON} -m pytest \
${VERBOSE ? "-vv --full-trace" : ""} perspective \
--ignore=perspective/tests/client_mode \
--ignore=perspective/tests/single_threaded \
--disable-pytest-warnings
${COVERAGE ? "--cov=perspective" : ""}`;
}
Expand All @@ -97,16 +116,9 @@ try {
PYTHON = "python";
}

// Check that the `PYTHON` command is valid, else default to `python`.
try {
execute_throw`${PYTHON} --version`;
} catch (e) {
console.warn(`\`${PYTHON}\` not found - using \`python\` instead.`);
PYTHON = "python";
}

try {
execute(pytest_client_mode(IS_DOCKER));
execute(pytest_single_threaded(IS_DOCKER));
execute(pytest(IS_DOCKER));
} catch (e) {
console.log(e.message);
Expand Down

0 comments on commit 477b5da

Please sign in to comment.