-
Notifications
You must be signed in to change notification settings - Fork 326
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
Add round, ceil, floor, truncate to the In-Database Column type #6988
Changes from 8 commits
bbc5cff
e6bed7b
347b46e
c78560d
2fa1846
8291ce3
b16d9ee
be81b60
3b486b9
9fe0841
f649b73
2f68d35
7f7324b
9c4e0ff
abaab2a
e20161a
f42285e
d802271
f05f9e3
ccda6aa
4ff6fa7
5b41821
93f4403
c60d354
a25e3d5
5283255
4aed89c
50b78eb
fbecfd8
593982b
3ff04b5
05fc15e
3fe8280
31874a8
9256930
03f3e05
78aa29f
92b4d49
8d19564
91d58b2
ea10375
b7b6d3e
e8dbf9f
218f2e2
570756d
afd21ac
b0c771e
bbd7033
e891c44
511a627
9769faf
41bd417
4d0627b
0ad7ef4
0a350c2
d6fe5ce
395a3b6
10fa61c
086fb18
c6fed25
6351dce
c27b52d
314546d
7fcb5c7
3bac313
05620e4
307f9f0
021a2f4
6ed5154
519f329
c6d7974
934f974
35fe5b1
076172a
3a9b1d7
819e75f
bfce3b7
e13e178
9d3f548
4895366
6342238
c22364e
7b16564
2ca4084
bc6f8fa
9905ac3
74f00d3
40d2376
9ff2ef6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.enso.table.data.column.operation.map; | ||
|
||
import java.util.BitSet; | ||
import org.enso.table.data.column.storage.numeric.DoubleStorage; | ||
import org.enso.table.data.column.storage.numeric.LongStorage; | ||
|
||
public abstract class DoubleLongMapOpWithSpecialNumericHandling | ||
extends UnaryMapOperationWithProblemBuilder<Double, DoubleStorage> { | ||
public DoubleLongMapOpWithSpecialNumericHandling(String name) { | ||
super(name); | ||
} | ||
|
||
protected abstract long doOperation(double a); | ||
|
||
@Override | ||
public LongStorage run( | ||
DoubleStorage storage, Object arg, MapOperationProblemBuilder problemBuilder) { | ||
long[] out = new long[storage.size()]; | ||
BitSet isMissing = new BitSet(); | ||
|
||
for (int i = 0; i < storage.size(); i++) { | ||
if (!storage.isNa(i)) { | ||
double item = storage.getItem(i); | ||
boolean special = Double.isNaN(item) || Double.isInfinite(item); | ||
if (!special) { | ||
out[i] = doOperation(item); | ||
} else { | ||
String msg = "Value is " + item; | ||
problemBuilder.reportArithmeticError(msg, i); | ||
isMissing.set(i); | ||
} | ||
} else { | ||
isMissing.set(i); | ||
} | ||
} | ||
return new LongStorage(out, storage.size(), isMissing); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.enso.table.data.column.operation.map; | ||
|
||
import org.enso.table.data.column.storage.Storage; | ||
|
||
/** | ||
* A map-like operation that ignores its second argument | ||
* | ||
* @param <I> the supported storage type | ||
*/ | ||
public abstract class UnaryMapOperationWithProblemBuilder<T, I extends Storage<T>> | ||
extends MapOperation<T, I> { | ||
public UnaryMapOperationWithProblemBuilder(String name) { | ||
super(name); | ||
} | ||
|
||
protected abstract Storage<?> run( | ||
I storage, Object arg, MapOperationProblemBuilder problemBuilder); | ||
|
||
@Override | ||
public Storage<?> runMap(I storage, Object arg, MapOperationProblemBuilder problemBuilder) { | ||
return run(storage, arg, problemBuilder); | ||
} | ||
|
||
@Override | ||
public Storage<?> runZip(I storage, Storage<?> arg, MapOperationProblemBuilder problemBuilder) { | ||
return run(storage, arg, problemBuilder); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,14 +512,6 @@ spec setup = | |
table = table_builder [["x", [0, 3, -3, 1, -2]]] | ||
table.at "x" . round 16 . should_fail_with Illegal_Argument | ||
|
||
Test.specify "Can handle NaN/Infinity" <| | ||
nan_result = if setup.test_selection.is_nan_and_nothing_distinct then Number.nan else Nothing | ||
ops = [.round, .truncate, .ceil, .floor] | ||
ops.each op-> | ||
do_op Number.nan op . should_equal nan_result | ||
do_op Number.positive_infinity op . should_equal Number.positive_infinity | ||
do_op Number.negative_infinity op . should_equal Number.negative_infinity | ||
|
||
if setup.test_selection.supports_decimal_type then | ||
Test.specify "should return decimals when rounding decimals" <| | ||
i1 = 9223372036854775807 - 1 | ||
|
@@ -647,69 +639,55 @@ spec setup = | |
do_round -3.50001 . should_equal -4 | ||
do_round -3.99999 . should_equal -4 | ||
|
||
Test.specify "Returns the correct type" <| | ||
do_round 231.2 1 . should_be_a Decimal | ||
do_round 231.2 0 . should_be_a Decimal | ||
do_round 231.2 . should_be_a Decimal | ||
do_round 231.2 -1 . should_be_a Decimal | ||
|
||
Test.specify "Can round correctly near the precision limit" <| | ||
do_round 1.22222222225 10 . should_equal 1.2222222223 | ||
do_round 1.222222222225 11 . should_equal 1.22222222223 | ||
do_round 1.2222222222225 12 . should_equal 1.222222222223 | ||
do_round 1.22222222222225 13 . should_equal 1.2222222222223 | ||
do_round 1.222222222222225 14 . should_equal 1.22222222222223 | ||
do_round 1.2222222222222225 15 . should_equal 1.222222222222223 | ||
|
||
do_round -1.22222222225 10 . should_equal -1.2222222223 | ||
do_round -1.222222222225 11 . should_equal -1.22222222223 | ||
do_round -1.2222222222225 12 . should_equal -1.222222222223 | ||
do_round -1.22222222222225 13 . should_equal -1.2222222222223 | ||
do_round -1.222222222222225 14 . should_equal -1.22222222222223 | ||
do_round -1.2222222222222225 15 . should_equal -1.222222222222223 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because SQLite fails this test. I could add this one line to the backend-specific test, with different values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it fail it? Should we be concerned? (if not a big deal, I'm ok with removing it) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to backend-specific tests. |
||
|
||
do_round 1.22222222235 10 . should_equal 1.2222222224 | ||
do_round 1.222222222235 11 . should_equal 1.22222222224 | ||
do_round 1.2222222222235 12 . should_equal 1.222222222224 | ||
do_round 1.22222222222235 13 . should_equal 1.2222222222224 | ||
do_round 1.222222222222235 14 . should_equal 1.22222222222224 | ||
do_round 1.2222222222222235 15 . should_equal 1.222222222222224 | ||
|
||
do_round -1.22222222235 10 . should_equal -1.2222222224 | ||
do_round -1.222222222235 11 . should_equal -1.22222222224 | ||
do_round -1.2222222222235 12 . should_equal -1.222222222224 | ||
do_round -1.22222222222235 13 . should_equal -1.2222222222224 | ||
do_round -1.222222222222235 14 . should_equal -1.22222222222224 | ||
do_round -1.2222222222222235 15 . should_equal -1.222222222222224 | ||
|
||
Test.specify "Can round correctly near the precision limit, using banker's rounding" <| | ||
do_round 1.22222222225 10 use_bankers=True . should_equal 1.2222222222 | ||
do_round 1.222222222225 11 use_bankers=True . should_equal 1.22222222222 | ||
do_round 1.2222222222225 12 use_bankers=True . should_equal 1.222222222222 | ||
do_round 1.22222222222225 13 use_bankers=True . should_equal 1.2222222222222 | ||
do_round 1.222222222222225 14 use_bankers=True . should_equal 1.22222222222222 | ||
do_round 1.2222222222222225 15 use_bankers=True . should_equal 1.222222222222222 | ||
|
||
do_round -1.22222222225 10 use_bankers=True . should_equal -1.2222222222 | ||
do_round -1.222222222225 11 use_bankers=True . should_equal -1.22222222222 | ||
do_round -1.2222222222225 12 use_bankers=True . should_equal -1.222222222222 | ||
do_round -1.22222222222225 13 use_bankers=True . should_equal -1.2222222222222 | ||
do_round -1.222222222222225 14 use_bankers=True . should_equal -1.22222222222222 | ||
do_round -1.2222222222222225 15 use_bankers=True . should_equal -1.222222222222222 | ||
|
||
do_round 1.22222222235 10 use_bankers=True . should_equal 1.2222222224 | ||
do_round 1.222222222235 11 use_bankers=True . should_equal 1.22222222224 | ||
do_round 1.2222222222235 12 use_bankers=True . should_equal 1.222222222224 | ||
do_round 1.22222222222235 13 use_bankers=True . should_equal 1.2222222222224 | ||
do_round 1.222222222222235 14 use_bankers=True . should_equal 1.22222222222224 | ||
do_round 1.2222222222222235 15 use_bankers=True . should_equal 1.222222222222224 | ||
|
||
do_round -1.22222222235 10 use_bankers=True . should_equal -1.2222222224 | ||
do_round -1.222222222235 11 use_bankers=True . should_equal -1.22222222224 | ||
do_round -1.2222222222235 12 use_bankers=True . should_equal -1.222222222224 | ||
do_round -1.22222222222235 13 use_bankers=True . should_equal -1.2222222222224 | ||
do_round -1.222222222222235 14 use_bankers=True . should_equal -1.22222222222224 | ||
do_round -1.2222222222222235 15 use_bankers=True . should_equal -1.222222222222224 | ||
|
||
Test.specify "Decimal places out of range" <| | ||
do_round 3.1 16 . should_fail_with Illegal_Argument | ||
|
@@ -812,12 +790,6 @@ spec setup = | |
do_round -12250 -2 use_bankers=True . should_equal -12200 | ||
do_round -12251 -2 use_bankers=True . should_equal -12300 | ||
|
||
Test.specify "Returns the correct type" <| | ||
do_round 231 1 . should_be_a Decimal | ||
do_round 231 0 . should_be_a Decimal | ||
do_round 231 . should_be_a Decimal | ||
do_round 231 -1 . should_be_a Decimal | ||
|
||
Test.group prefix+"Text Column Operations" <| | ||
t3 = table_builder [["s1", ["foobar", "bar", "baz", "BAB", Nothing]], ["s2", ["foo", "ar", "a", "b", Nothing]]] | ||
s1 = t3.at "s1" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message needs to be more user friendly.
or sth like that