mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 08:21:49 +03:00
Some fixed form the Anagrams experiment. (#5592)
- Fixes the display of Date, Time_Of_Day and Date_Time so doesn't wrap. - Adjust serialization of large integer values for JS and display within table. - Workaround for issue with using `.lines` in the Table (new bug filed). - Disabled warning on no specified `separator` on `Concatenate`. Does not include fix for aggregation on integer values outside of `long` range.
This commit is contained in:
parent
4f90946d1e
commit
1c821e22cf
@ -183,10 +183,13 @@ class TableVisualization extends Visualization {
|
||||
let to_render = content
|
||||
if (content instanceof Object) {
|
||||
const type = content.type
|
||||
if (type === 'Date') {
|
||||
if (type === 'BigInt') {
|
||||
to_render = BigInt(content.value)
|
||||
} else if (type === 'Date') {
|
||||
to_render = new Date(content.year, content.month - 1, content.day)
|
||||
.toISOString()
|
||||
.substring(0, 10)
|
||||
to_render = '<span style="white-space: nowrap;">' + to_render + '</span>'
|
||||
} else if (type === 'Time_Of_Day') {
|
||||
const js_date = new Date(
|
||||
0,
|
||||
@ -200,6 +203,7 @@ class TableVisualization extends Visualization {
|
||||
to_render =
|
||||
js_date.toTimeString().substring(0, 8) +
|
||||
(js_date.getMilliseconds() === 0 ? '' : '.' + js_date.getMilliseconds())
|
||||
to_render = '<span style="white-space: nowrap;">' + to_render + '</span>'
|
||||
} else if (type === 'Date_Time') {
|
||||
const js_date = new Date(
|
||||
content.year,
|
||||
@ -213,6 +217,7 @@ class TableVisualization extends Visualization {
|
||||
to_render =
|
||||
js_date.toISOString().substring(0, 19).replace('T', ' ') +
|
||||
(js_date.getMilliseconds() === 0 ? '' : '.' + js_date.getMilliseconds())
|
||||
to_render = '<span style="white-space: nowrap;">' + to_render + '</span>'
|
||||
}
|
||||
}
|
||||
result += '<td class="plaintext">' + to_render + '</td>'
|
||||
|
@ -158,7 +158,7 @@ fetch uri method=HTTP_Method.Get headers=[] parse=True =
|
||||
request = Request.new method uri parsed_headers
|
||||
response = HTTP.new.request request
|
||||
|
||||
if response.code.is_success.not then Error.throw (Request_Error.Error "Status Code" ("Request failed with status code: " + response.code + ". " + response.body.to_text)) else
|
||||
if response.code.is_success.not then Error.throw (Request_Error.Error "Status Code" ("Request failed with status code: " + response.code.to_text + ". " + response.body.to_text)) else
|
||||
response_headers = response.headers
|
||||
content_type = response_headers.find if_missing=Nothing h-> "Content-Type".equals_ignore_case h.name
|
||||
if (parse == False) || (content_type == Nothing) then response else
|
||||
|
@ -45,6 +45,11 @@ Number.to_js_object self = case self of
|
||||
Number -> JS_Object.from_pairs [["type", "Number"]]
|
||||
Integer -> JS_Object.from_pairs [["type", "Integer"]]
|
||||
Decimal -> JS_Object.from_pairs [["type", "Decimal"]]
|
||||
_ : Integer ->
|
||||
## JS Safe Integer range -(2^53 - 1) to (2^53 - 1)
|
||||
js_max_integer = 9007199254740991
|
||||
if self >= -js_max_integer && self < js_max_integer then self else
|
||||
JS_Object.from_pairs [["type", "BigInt"], ["value", self.to_text]]
|
||||
_ -> self
|
||||
|
||||
## Converts the given value to a JSON serializable object.
|
||||
|
@ -160,6 +160,7 @@ public final class ParseStdLibTest extends TestCase {
|
||||
// Files containing type expressions not supported by old parser.
|
||||
"Data/Index_Sub_Range.enso",
|
||||
"Data/Json.enso",
|
||||
"Data/Json/Extensions.enso",
|
||||
"Data/List.enso",
|
||||
"Data/Pair.enso",
|
||||
"Data/Range.enso",
|
||||
|
@ -33,7 +33,7 @@ public class Concatenate extends Aggregator {
|
||||
if (value == null || value instanceof String) {
|
||||
String textValue = toQuotedString(value, quote, separator);
|
||||
|
||||
if (quote.equals("") && textValue.contains(separator)) {
|
||||
if (!separator.equals("") && quote.equals("") && textValue.contains(separator)) {
|
||||
this.addProblem(new UnquotedDelimiter(this.getName(), row, "Unquoted delimiter."));
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import org.enso.table.data.mask.SliceRange;
|
||||
import org.enso.table.error.UnexpectedColumnTypeException;
|
||||
import org.graalvm.polyglot.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
@ -104,8 +105,10 @@ public class Column {
|
||||
*/
|
||||
public static Column fromItems(String name, List<Value> items) {
|
||||
InferredBuilder builder = new InferredBuilder(items.size());
|
||||
for (Value item : items) {
|
||||
Object converted = Polyglot_Utils.convertPolyglotValue(item);
|
||||
// ToDo: This a workaround for an issue with polyglot layer. #5590 is related.
|
||||
// to revert replace with: for (Value item : items) {
|
||||
for (Object item : items) {
|
||||
Object converted = item instanceof Value v ? Polyglot_Utils.convertPolyglotValue(v) : item;
|
||||
builder.appendNoGrow(converted);
|
||||
}
|
||||
var storage = builder.seal();
|
||||
@ -120,12 +123,28 @@ public class Column {
|
||||
* @return a column with given name and items
|
||||
*/
|
||||
public static Column fromRepeatedItems(String name, List<Value> items, int repeat) {
|
||||
if (repeat < 1) {
|
||||
throw new IllegalArgumentException("Repeat count must be positive.");
|
||||
}
|
||||
|
||||
if (repeat == 1) {
|
||||
return fromItems(name, items);
|
||||
}
|
||||
|
||||
var totalSize = items.size() * repeat;
|
||||
|
||||
var values = new ArrayList<Object>(items.size());
|
||||
// ToDo: This a workaround for an issue with polyglot layer. #5590 is related.
|
||||
// to revert replace with: for (Value item : items) {
|
||||
for (Object item : items) {
|
||||
Object converted = item instanceof Value v ? Polyglot_Utils.convertPolyglotValue(v) : item;
|
||||
values.add(converted);
|
||||
}
|
||||
|
||||
var builder = new InferredBuilder(totalSize);
|
||||
for (int i = 0; i < totalSize; i++) {
|
||||
var item = items.get(i % items.size());
|
||||
var converted = Polyglot_Utils.convertPolyglotValue(item);
|
||||
builder.appendNoGrow(converted);
|
||||
var item = values.get(i % items.size());
|
||||
builder.appendNoGrow(item);
|
||||
}
|
||||
return new Column(name, builder.seal());
|
||||
}
|
||||
|
@ -1378,6 +1378,14 @@ spec setup =
|
||||
tester = expect_column_names ["Concatenate Text"]
|
||||
Problems.test_problem_handling action problems tester
|
||||
|
||||
Test.specify "should not fail if trying concatenate unquoted delimiters with no separator" <|
|
||||
column = Concatenate "Text" separator=""
|
||||
t = table_builder [["Text", ["A", "BC", "def"]]]
|
||||
result = t.aggregate [column] on_problems=Report_Error
|
||||
Problems.assume_no_problems result
|
||||
result.column_names . should_equal ["Concatenate Text"]
|
||||
result.at "Concatenate Text" . to_vector . should_equal ["ABCdef"]
|
||||
|
||||
Test.specify "should warn if can't compare value for Min or Max" <|
|
||||
[Problem_Behavior.Report_Error, Problem_Behavior.Report_Warning, Problem_Behavior.Ignore].each pb-> Test.with_clue "Problem_Behavior="+pb.to_text+" " <|
|
||||
err = table.aggregate [Maximum "Mixed"] on_problems=pb
|
||||
|
@ -105,7 +105,7 @@ spec =
|
||||
|
||||
pending_python_missing = if Polyglot.is_language_installed "python" . not then
|
||||
"Can't run Python tests, Python is not installed."
|
||||
Test.specify "should also work with polyglot values coming from Python" pending=pending_python_missing <|
|
||||
Test.specify "should work with polyglot values coming from Python" pending=pending_python_missing <|
|
||||
enso_dates = ["enso_dates", [Date.new 2022 8 27, Date.new 1999 1 1]]
|
||||
py_dates = ["py_dates", [py_make_date 2022 8 27, py_make_date 1999 1 1]]
|
||||
py_objects = ["py_objects", [py_make_object "a" "b", py_make_object "foo" "bar"]]
|
||||
@ -115,7 +115,7 @@ spec =
|
||||
|
||||
(table.at "enso_dates" == table.at "py_dates").to_vector . should_equal [True, True]
|
||||
|
||||
Test.specify "should also work with polyglot values coming from JS" <|
|
||||
Test.specify "should work with polyglot values coming from JS" <|
|
||||
enso_dates = ["enso_dates", [Date.new 2022 8 27, Date.new 1999 1 1]]
|
||||
js_dates = ["js_dates", [js_make_date 2022 8 27, js_make_date 1999 1 1]]
|
||||
js_objects = ["js_objects", [js_make_object "a" "b", js_make_object "foo" "bar"]]
|
||||
@ -130,6 +130,13 @@ spec =
|
||||
(js_converted_dates == table.at "enso_dates").to_vector . should_equal [True, True]
|
||||
(enso_date_times == table.at "js_dates").to_vector . should_equal [True, True]
|
||||
|
||||
Test.specify "should work with a Text value split into lines" <|
|
||||
## This tests verifies an issue with passing through a `List<String>` to the table.
|
||||
words = 'The\nquick\nbrown\nfox\njumps\nover\nthe\nlazy\ndog'.lines
|
||||
table = Table.new [["words", words]]
|
||||
table.at "words" . storage_type . should_equal Storage.Text
|
||||
table.at "words" . to_vector . should_equal words
|
||||
|
||||
Test.specify "should handle Unicode normalization when accessing table columns" <|
|
||||
col1 = ['s\u0301ciana', [1, 2, 3]]
|
||||
col2 = ['café', [4, 5, 6]]
|
||||
|
Loading…
Reference in New Issue
Block a user