From 104158d6d11ad7091fefc0babf78ff67af2bd783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Tue, 16 Mar 2021 19:10:05 +0100 Subject: [PATCH] Update vis, fix edge case with builders and slice --- .../Visualization/Table/Visualization.enso | 22 +++++++++++++------ .../data/column/storage/DoubleStorage.java | 2 +- .../data/column/storage/LongStorage.java | 2 +- .../data/column/storage/ObjectStorage.java | 2 +- test/Table_Tests/src/Table_Spec.enso | 1 + 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/distribution/std-lib/Standard/src/Visualization/Table/Visualization.enso b/distribution/std-lib/Standard/src/Visualization/Table/Visualization.enso index 4d17de4e1b929..8cf7c1e910bf8 100644 --- a/distribution/std-lib/Standard/src/Visualization/Table/Visualization.enso +++ b/distribution/std-lib/Standard/src/Visualization/Table/Visualization.enso @@ -8,17 +8,25 @@ import Standard.Database.Data.Column as Database_Column # TODO add an initial offset to fully support lazy visualizations ## PRIVATE prepare_visualization x max_rows = case x of - Dataframe_Table.Table _ -> here.make_json x - Dataframe_Column.Column _ -> here.make_json x.to_table + Dataframe_Table.Table _ -> + dataframe = x.take_start max_rows + all_rows_count = x.row_count + here.make_json dataframe all_rows_count + Dataframe_Column.Column _ -> + here.prepare_visualization x.to_table max_rows Database_Table.Table _ _ _ _ -> - here.make_json <| x.to_dataframe max_rows + dataframe = x.to_dataframe max_rows + all_rows_count = x.row_count + here.make_json dataframe all_rows_count Database_Column.Column _ _ _ _ _ -> - here.make_json <| x.to_table.to_dataframe max_rows + here.prepare_visualization x.to_table max_rows _ -> x . to_json . to_text ## PRIVATE make_json dataframe all_rows_count = - header = ["header", dataframe.columns.map .name] - data = ["data", dataframe.columns.map .to_vector . map (x -> x.take_start 2000) ] - pairs = [header,data] + columns = dataframe.columns + header = ["header", columns.map .name] + data = ["data", columns.map .to_vector] + all_rows = ["all_rows_count", all_rows_count] + pairs = [header, data, all_rows] Json.from_pairs pairs . to_text diff --git a/std-bits/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java b/std-bits/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java index 7e5fbade8964f..9d67d3da8635f 100644 --- a/std-bits/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java +++ b/std-bits/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java @@ -259,7 +259,7 @@ public Storage run(DoubleStorage storage) { @Override public DoubleStorage slice(int offset, int limit) { - int newSize = Math.min(data.length - offset, limit); + int newSize = Math.min(size - offset, limit); long[] newData = new long[newSize]; System.arraycopy(data, offset, newData, 0, newSize); BitSet newMask = isMissing.get(offset, offset + limit); diff --git a/std-bits/src/main/java/org/enso/table/data/column/storage/LongStorage.java b/std-bits/src/main/java/org/enso/table/data/column/storage/LongStorage.java index 0f86c432dad37..e82ac862e75a3 100644 --- a/std-bits/src/main/java/org/enso/table/data/column/storage/LongStorage.java +++ b/std-bits/src/main/java/org/enso/table/data/column/storage/LongStorage.java @@ -373,7 +373,7 @@ public Storage run(LongStorage storage) { @Override public LongStorage slice(int offset, int limit) { - int newSize = Math.min(data.length - offset, limit); + int newSize = Math.min(size - offset, limit); long[] newData = new long[newSize]; System.arraycopy(data, offset, newData, 0, newSize); BitSet newMask = isMissing.get(offset, offset + limit); diff --git a/std-bits/src/main/java/org/enso/table/data/column/storage/ObjectStorage.java b/std-bits/src/main/java/org/enso/table/data/column/storage/ObjectStorage.java index 3c21e4aef7c3e..17ea310a79fab 100644 --- a/std-bits/src/main/java/org/enso/table/data/column/storage/ObjectStorage.java +++ b/std-bits/src/main/java/org/enso/table/data/column/storage/ObjectStorage.java @@ -149,7 +149,7 @@ protected Storage run(ObjectStorage storage) { @Override public ObjectStorage slice(int offset, int limit) { - int newSize = Math.min(data.length - offset, limit); + int newSize = Math.min(size - offset, limit); Object[] newData = new Object[newSize]; System.arraycopy(data, offset, newData, 0, newSize); return new ObjectStorage(newData, newSize); diff --git a/test/Table_Tests/src/Table_Spec.enso b/test/Table_Tests/src/Table_Spec.enso index d2c9b88c45f24..5a6ad66e26ca1 100644 --- a/test/Table_Tests/src/Table_Spec.enso +++ b/test/Table_Tests/src/Table_Spec.enso @@ -511,6 +511,7 @@ spec = t_1 = Table.new [i_1, c_1, c_2, c_3] . set_index 'ix' t_1.take_start 10 . at 'col' . to_vector . should_equal (t_1.at 'col' . to_vector) + t_1.at 'col' . take_start 10 . to_vector . should_equal (t_1.at 'col' . to_vector) t_2 = t_1.take_start 2 t_2.index.to_vector . should_equal (t_1.index.to_vector . take_start 2)