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

Better Error Trapping in map #8307

Merged
merged 121 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
2485d3e
tests
GregoryTravis Nov 8, 2023
0cb3675
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 9, 2023
dd0fdde
wip
GregoryTravis Nov 9, 2023
ae1fd56
wip
GregoryTravis Nov 9, 2023
3cb9b4a
additional warnings
GregoryTravis Nov 9, 2023
506a13b
wip
GregoryTravis Nov 9, 2023
f4427df
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 10, 2023
b5d4325
wip
GregoryTravis Nov 10, 2023
be40d60
cleanup
GregoryTravis Nov 10, 2023
8205cac
nested wrapping
GregoryTravis Nov 10, 2023
87c246b
multiple nestings
GregoryTravis Nov 10, 2023
40ff235
wraps_error uses looks_for, test for should_fail_with
GregoryTravis Nov 10, 2023
a66384a
wip
GregoryTravis Nov 10, 2023
d1f7013
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 13, 2023
a4d9bbd
stack trace line fix
GregoryTravis Nov 13, 2023
9e3f0f0
use catch_primitive internally
GregoryTravis Nov 13, 2023
074ee0b
fix warning mapping, dtf spec
GregoryTravis Nov 13, 2023
7a3800c
just one wrapper checker, vector spec
GregoryTravis Nov 13, 2023
7516a6b
missing ctor, back to non-primitive catch
GregoryTravis Nov 13, 2023
f8f0b2f
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 14, 2023
b15c7a6
back to c_p
GregoryTravis Nov 14, 2023
059559b
put old map back
GregoryTravis Nov 14, 2023
8409be6
wip
GregoryTravis Nov 14, 2023
85e3e2d
unnest tests
GregoryTravis Nov 14, 2023
b0e811a
Array.map on_problems
GregoryTravis Nov 14, 2023
c30d171
wip
GregoryTravis Nov 14, 2023
178ccd4
Revert "wip"
GregoryTravis Nov 14, 2023
fd3062c
better test names
GregoryTravis Nov 14, 2023
f31bc15
warning logging
GregoryTravis Nov 15, 2023
74fa5f7
wip
GregoryTravis Nov 15, 2023
2444c35
wip
GregoryTravis Nov 15, 2023
139d8c4
move logic into ALH
GregoryTravis Nov 15, 2023
bfb318f
doc
GregoryTravis Nov 15, 2023
ec76880
constant
GregoryTravis Nov 15, 2023
a3dda25
My_Error.Error
GregoryTravis Nov 15, 2023
9af7498
nested
GregoryTravis Nov 15, 2023
434691f
doc
GregoryTravis Nov 15, 2023
1b06a95
map_primtiive in warning mapper
GregoryTravis Nov 15, 2023
933efca
composition
GregoryTravis Nov 15, 2023
5b305f5
ref spec
GregoryTravis Nov 15, 2023
f429ef8
Remove warnings prior to matching on the value
hubertp Nov 16, 2023
0a98e93
fix 1
GregoryTravis Nov 16, 2023
2488fd5
do not auto unwrap in test error checkers
GregoryTravis Nov 16, 2023
04a6202
nested error matcher
GregoryTravis Nov 16, 2023
688af38
in problems too
GregoryTravis Nov 16, 2023
6f9f8b7
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 16, 2023
ee003b5
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 20, 2023
af8a91d
dtf
GregoryTravis Nov 20, 2023
7b6d847
v
GregoryTravis Nov 20, 2023
14cdb97
statistics
GregoryTravis Nov 20, 2023
59f0acd
wip
GregoryTravis Nov 20, 2023
cba775e
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 21, 2023
2d0de7b
Table_Spec, map_with_index_primitive
GregoryTravis Nov 21, 2023
0ed97d9
Column_Operations_Spec
GregoryTravis Nov 21, 2023
0aa34e5
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 22, 2023
1e65438
disable warning wrapping and Report_Warning
GregoryTravis Nov 22, 2023
8ed4172
unimpl test
GregoryTravis Nov 22, 2023
34bff67
Warnings_Spec
GregoryTravis Nov 22, 2023
1cc67eb
DCS
GregoryTravis Nov 22, 2023
c9dc711
ACG JP
GregoryTravis Nov 22, 2023
174d235
zip_primitive
GregoryTravis Nov 22, 2023
bb128aa
join_helpers
GregoryTravis Nov 22, 2023
f4151a7
Lookup_Helpers
GregoryTravis Nov 22, 2023
ae500a7
Table
GregoryTravis Nov 22, 2023
4433b0f
Data_Formatter
GregoryTravis Nov 22, 2023
b6edd18
Value_Type_Helpers
GregoryTravis Nov 22, 2023
71335f2
revert check types changes
GregoryTravis Nov 22, 2023
a1457c8
table_helpers
GregoryTravis Nov 22, 2023
8e5a454
table tests
GregoryTravis Nov 22, 2023
cd9ec3b
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 27, 2023
3150f48
remove st
GregoryTravis Nov 27, 2023
25b2383
do not remove warnings from value
GregoryTravis Nov 27, 2023
fc8aa74
vec docs, tests for zip, mwi, flat_map
GregoryTravis Nov 27, 2023
e7efedc
docs, fixes
GregoryTravis Nov 27, 2023
a7e9b28
remove nested_error_matcher
GregoryTravis Nov 27, 2023
e0f6184
cleanup
GregoryTravis Nov 27, 2023
b13ab25
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 28, 2023
ce37250
benchmark
GregoryTravis Nov 28, 2023
1e05944
one error
GregoryTravis Nov 28, 2023
bd04928
alter
GregoryTravis Nov 28, 2023
749ae37
add bench to main
GregoryTravis Nov 28, 2023
45cf473
review
GregoryTravis Nov 28, 2023
4b0fb52
review
GregoryTravis Nov 28, 2023
8268fb1
review
GregoryTravis Nov 28, 2023
b950357
tail call
GregoryTravis Nov 28, 2023
46b254f
changelog
GregoryTravis Nov 28, 2023
dff1ec4
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 29, 2023
28e8ffd
tail call was not a tail call
GregoryTravis Nov 29, 2023
046a7a3
ws
GregoryTravis Nov 29, 2023
016042d
bad import
GregoryTravis Nov 29, 2023
edd5949
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 29, 2023
da7dcd9
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 30, 2023
9a67d60
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Nov 30, 2023
53c9fea
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Dec 4, 2023
8119536
Merge branch 'develop' into wip/gmt/8110-map-error
hubertp Dec 4, 2023
8331f02
Added missing import
hubertp Dec 4, 2023
d61f8f8
Merge branch 'wip/gmt/8110-map-error' of github.com:enso-org/enso int…
GregoryTravis Dec 4, 2023
14bc3ff
Update distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso
GregoryTravis Dec 4, 2023
ca82ea6
review, ref example
GregoryTravis Dec 4, 2023
5f75722
lazy benchmark data
GregoryTravis Dec 4, 2023
f3ef56b
extra paren
GregoryTravis Dec 4, 2023
78d7439
check outside of catch
GregoryTravis Dec 4, 2023
fd02ec4
review
GregoryTravis Dec 4, 2023
54578bd
vector too
GregoryTravis Dec 4, 2023
4da6a51
actually lazy
GregoryTravis Dec 4, 2023
634d1ce
disambiguate Map_Error
GregoryTravis Dec 4, 2023
d7804fa
finish rename
GregoryTravis Dec 4, 2023
2754ef3
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Dec 5, 2023
f619e44
move to extensions
GregoryTravis Dec 6, 2023
5c28d9e
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Dec 7, 2023
97dc84c
combine Additional_Warnings error
GregoryTravis Dec 7, 2023
6760cd0
rename to map_no_wrap
GregoryTravis Dec 7, 2023
0e7312e
do not catch and rethrow
GregoryTravis Dec 7, 2023
8e3e079
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Dec 8, 2023
17c2eff
review
GregoryTravis Dec 8, 2023
561636c
wip
GregoryTravis Dec 8, 2023
6ec4cd6
remove _primitives entirely
GregoryTravis Dec 8, 2023
cad76a5
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Dec 11, 2023
1465cf2
remove unused should_fail_with function options
GregoryTravis Dec 11, 2023
c354de6
Merge branch 'develop' into wip/gmt/8110-map-error
GregoryTravis Dec 12, 2023
ff469ff
remove expected_warning as function in Problems
GregoryTravis Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@
- [Added `Table.format` for the in-memory backend.][8150]
- [Implemented truncate `Date_Time` for database backend (Postgres only).][8235]
- [Initial Enso Cloud APIs.][8006]
- [Errors thrown inside `map` are wrapped in `Map_Error`.][8307]

[debug-shortcuts]:
https://github.com/enso-org/enso/blob/develop/app/gui/docs/product/shortcuts.md#debug
Expand Down Expand Up @@ -848,6 +849,7 @@
[8105]: https://github.com/enso-org/enso/pull/8105
[8150]: https://github.com/enso-org/enso/pull/8150
[8235]: https://github.com/enso-org/enso/pull/8235
[8307]: https://github.com/enso-org/enso/pull/8307
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How comes that a PR like this doesn't have any overview at all?

obrazek

No reference to any issue!? No summary? No explanation why chosen path is the right one?


#### Enso Compiler

Expand Down
111 changes: 103 additions & 8 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import project.Data.Range.Range
import project.Data.Sort_Direction.Sort_Direction
import project.Data.Text.Text
import project.Data.Vector.Empty_Error
import project.Data.Vector.No_Wrap
import project.Data.Vector.Vector
import project.Error.Error
import project.Errors.Common.Incomparable_Values
Expand Down Expand Up @@ -331,27 +332,73 @@ type Array
Arguments:
- function: A function that takes an element in the array and returns
some transformation of that element.
- on_problems: Specifies how to handle any problems that arise in
`function`.

? Problem Handling

The result of Errors thrown when executing the function depend on
`on_problems`:
- Report_Error: The first error is thrown, and is wrapped in
`Map_Error`.
- No_Wrap: The first error is thrown, and is not wrapped in
`Map_Error`.
- Report_Warning: The result for that element is `Nothing`,
the error is attached as a warning. Currently unimplemented.
- Ignore: The result is `Nothing`, and the error is
ignored.

Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.

> Example
Add 1 to each element of the array.

[1, 2, 3].to_array . map +1
map : (Any -> Any) -> Vector Any
map self function = Vector.map self function
map : (Any -> Any) -> Problem_Behavior | No_Wrap -> Vector Any
map self function on_problems=Problem_Behavior.Report_Error = Vector.map self function on_problems

## Applies a function to each element of the array, returning the `Vector`
that contains all results concatenated.

Arguments:
- function: A function that takes an element in the array, transforms
it, and returns a `Vector`.
- on_problems: Specifies how to handle any problems that arise in
`function`.

? Problem Handling

The result of Errors thrown when executing the function depend on
`on_problems`:
- Report_Error: The first error is thrown, and is wrapped in
`Map_Error`.
- No_Wrap: The first error is thrown, and is not wrapped in
`Map_Error`.
- Report_Warning: The result for that element is `Nothing`,
the error is attached as a warning. Currently unimplemented.
- Ignore: The result is `Nothing`, and the error is
ignored.

Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.

> Example
Replace each number `n` in the array with itself repeated n times.

[0, 1, 2].to_array . flat_map (n -> Vector.fill n n)
flat_map : (Any -> Vector Any) -> Vector Any
flat_map self function = Vector.flat_map self function
flat_map : (Any -> Vector Any) -> Problem_Behavior | No_Wrap -> Vector Any
flat_map self function on_problems=Problem_Behavior.Report_Error = Vector.flat_map self function on_problems

## GROUP Selections
ICON preparation
Expand Down Expand Up @@ -516,16 +563,39 @@ type Array
Arguments:
- function: A function that takes an index and an item and calculates a
new value for at that index.
- on_problems: Specifies how to handle any problems that arise in
`function`.

The function is called with both the element index as well as the
element itself.

? Problem Handling

The result of Errors thrown when executing the function depend on
`on_problems`:
- Report_Error: The first error is thrown, and is wrapped in
`Map_Error`.
- No_Wrap: The first error is thrown, and is not wrapped in
`Map_Error`.
- Report_Warning: The result for that element is `Nothing`,
the error is attached as a warning. Currently unimplemented.
- Ignore: The result is `Nothing`, and the error is
ignored.

Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.

> Example
Sum numbers with their indices in an array.

[1, 2, 3].to_array.map_with_index (+)
map_with_index : (Integer -> Any -> Any) -> Vector Any
map_with_index self function = Vector.map_with_index self function
map_with_index : (Integer -> Any -> Any) -> Problem_Behavior | No_Wrap -> Vector Any
map_with_index self function on_problems=Problem_Behavior.Report_Error = Vector.map_with_index self function on_problems

## PRIVATE
Creates a new array with the skipping elements until `start` and then
Expand Down Expand Up @@ -699,10 +769,33 @@ type Array
- that: The array to zip with `self`.
- function: The function used to combine pairwise elements of `self` and
`that`.
- on_problems: Specifies how to handle any problems that arise in
`function`.

The result of this function is a `Vector` of length being the shorter of
`self` and `that`, containing results of calling `function`.

? Problem Handling

The result of Errors thrown when executing the function depend on
`on_problems`:
- Report_Error: The first error is thrown, and is wrapped in
`Map_Error`.
- No_Wrap: The first error is thrown, and is not wrapped in
`Map_Error`.
- Report_Warning: The result for that element is `Nothing`,
the error is attached as a warning. Currently unimplemented.
- Ignore: The result is `Nothing`, and the error is
ignored.

Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.

> Example
Calculate the pairwise sum of two arrays.

Expand All @@ -713,8 +806,10 @@ type Array
of both elements.

[1, 2, 3].to_array.zip [4, 5, 6].to_array == [[1, 4].to_array, [2, 5].to_array, [3, 6].to_array].to_array
zip : Vector Any -> (Any -> Any -> Any) -> Vector Any
zip self that:Vector function=[_,_] = Vector.zip self that function
zip : Vector Any -> (Any -> Any -> Any) -> Problem_Behavior | No_Wrap -> Vector Any
zip self that function=[_,_] on_problems=Problem_Behavior.Report_Error =
len = self.length.min that.length
Array_Like_Helpers.vector_from_function len (i-> function (self.at i) (that.at i)) on_problems

## Returns the array as a `Vector`.
to_vector : Vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import project.Data.Numbers.Integer
import project.Data.Numbers.Number
import project.Data.Ordering.Comparable
import project.Data.Ordering.Ordering
import project.Data.Vector.No_Wrap
import project.Data.Vector.Vector
import project.Error.Error
import project.Errors.Common.Incomparable_Values
Expand Down Expand Up @@ -153,7 +154,7 @@ type Statistic
- statistics: Set of statistics to calculate.
compute_bulk : Vector -> Vector Statistic -> Vector Any
compute_bulk data statistics=[Statistic.Count, Statistic.Sum] =
moment_order = statistics.map .order
moment_order = statistics.map on_problems=No_Wrap.Value .order
has_min_max = statistics.any (s-> s == Statistic.Minimum || s == Statistic.Maximum)
max_moment_order = moment_order.filter (v-> v != Nothing) . fold 0 .max
counter = data.fold (Accumulator.new has_min_max max_moment_order) current-> value-> compute_fold current value
Expand All @@ -164,7 +165,7 @@ type Statistic
Error.throw (Illegal_Argument.Error ("Can only compute " + stat.to_text + " on numerical data sets."))

if max_moment_order > 0 && counter.moments.is_nothing then report_error statistics else
statistics.map statistic-> case statistic of
statistics.map on_problems=No_Wrap.Value statistic-> case statistic of
Statistic.Covariance series -> check_if_empty counter.count <| calculate_correlation_statistics data series . covariance
Statistic.Pearson series -> check_if_empty counter.count <| calculate_correlation_statistics data series . pearsonCorrelation
Statistic.R_Squared series -> check_if_empty counter.count <| calculate_correlation_statistics data series . rSquared
Expand Down Expand Up @@ -197,7 +198,7 @@ type Statistic
_ -> False

if statistics.any is_unsupported then Error.throw (Illegal_Argument.Error ("Unsupported Statistics ( " + (statistics.filter is_unsupported . to_text) ") for running calculations.")) else
moment_order = statistics.map .order
moment_order = statistics.map on_problems=No_Wrap.Value .order
has_min_max = statistics.any (s-> s == Statistic.Minimum || s == Statistic.Maximum)
max_moment_order = moment_order.filter (v-> v != Nothing) . fold 0 .max

Expand All @@ -208,7 +209,7 @@ type Statistic
data.fold counter current->value->
result = compute_fold current value

row = Panic.throw_wrapped_if_error <| statistics.map s-> case s of
row = Panic.throw_wrapped_if_error <| statistics.map on_problems=No_Wrap.Value s-> case s of
Statistic.Maximum -> if result.count == 0 then Nothing else result.maximum
Statistic.Minimum -> if result.count == 0 then Nothing else result.minimum
_ -> result.compute s
Expand Down
Loading