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 manager internal API, speed up string filters in UI, add manager API tests #1077

Merged
merged 8 commits into from
Jun 24, 2020
15 changes: 10 additions & 5 deletions packages/perspective-viewer/src/js/viewer/dom_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export class DomElement extends PerspectiveElement {
row.setAttribute("filter", filter);

if (type === "string") {
const view = this._table.view({row_pivots: [name], aggregates: {}});
// Get all unique values for the column
const view = this._table.view({row_pivots: [name], columns: []});
view.to_json().then(json => {
row.choices(this._autocomplete_choices(json));
});
Expand Down Expand Up @@ -517,9 +518,13 @@ export class DomElement extends PerspectiveElement {
}

_autocomplete_choices(json) {
return json
.slice(1, json.length)
.map(x => x.__ROW_PATH__)
.filter(x => (Array.isArray(x) ? x.filter(v => !!v).length > 0 : !!x));
const choices = [];
for (let i = 1; i < json.length; i++) {
const row_path = json[i].__ROW_PATH__;
if (Array.isArray(row_path) && row_path.length > 0 && row_path[0]) {
choices.push(row_path[0]);
}
}
return choices;
}
}
5 changes: 3 additions & 2 deletions packages/perspective-viewer/test/js/unit/dom_element.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ describe(DomElement, () => {
dom_element = new DomElement();
json_choices = [
{__ROW_PATH__: [], foo: 2},
{__ROW_PATH__: [undefined], foo: 25},
{__ROW_PATH__: [null], foo: 25},
{__ROW_PATH__: ["somestring"], foo: 3},
{__ROW_PATH__: ["otherstring"], foo: 3}
];
});

test("the first value and null values are filtered out", () => {
expect(dom_element._autocomplete_choices(json_choices)).toEqual([["somestring"], ["otherstring"]]);
test("the first value, null values, and undefined values are filtered out", () => {
expect(dom_element._autocomplete_choices(json_choices)).toEqual(["somestring", "otherstring"]);
});
});
});
2 changes: 1 addition & 1 deletion python/perspective/perspective/core/data/np.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def make_null_mask(array):

if not is_object_or_string_dtype:
if is_datetime_dtype:
invalid = invalid or np.isnat(item)
invalid = invalid or str(item) == "NaT"
else:
invalid = invalid or np.isnan(item)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ PYBIND11_MODULE(libbinding, m)
m.def("get_computation_input_types", &get_computation_input_types);
m.def("get_computed_functions", &get_computed_functions);
m.def("make_computations", &make_computations);
m.def("scalar_to_py", &scalar_to_py);
}

#endif
Loading