Skip to content

Commit a87f3b9

Browse files
committed
Docs
1 parent 554c950 commit a87f3b9

File tree

6 files changed

+115
-13
lines changed

6 files changed

+115
-13
lines changed

distribution/lib/Standard/Table/0.0.0-dev/docs/api/Set_Mode.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@
44
- Add
55
- Add_Or_Update
66
- Update
7+
- type Set_Mode_Many
8+
- Add as:Standard.Base.Data.Text.Text=
9+
- Add_Or_Update as:Standard.Base.Data.Text.Text=
10+
- Update
11+
- as_value self -> Standard.Base.Any.Any
12+
- Standard.Table.Set_Mode.Set_Mode.from that:Standard.Table.Set_Mode.Set_Mode_Many -> Standard.Table.Set_Mode.Set_Mode
13+
- Standard.Table.Set_Mode.Set_Mode_Many.from that:Standard.Table.Set_Mode.Set_Mode -> Standard.Table.Set_Mode.Set_Mode_Many

distribution/lib/Standard/Table/0.0.0-dev/docs/api/Table.md

Lines changed: 11 additions & 10 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Enso Signatures 1.0
2+
## module Standard.Table.Table_Selector
3+
- type Table_Selector
4+
- By_Type by_type:Standard.Table.Value_Type.By_Type
5+
- Index index:Standard.Base.Data.Numbers.Integer
6+
- Name name:Standard.Base.Data.Text.Text
7+
- Regex pattern:Standard.Base.Data.Text.Regex.Regex
8+
- Vector selectors:(Standard.Base.Data.Vector.Vector Standard.Table.Table_Selector.Table_Selector)
9+
- act_if_any self table:Standard.Table.Table.Table error_on_missing_columns:Standard.Base.Data.Boolean.Boolean action:Standard.Base.Any.Any -> Standard.Base.Any.Any
10+
- resolve self table:Standard.Table.Table.Table error_on_missing_columns:Standard.Base.Data.Boolean.Boolean -> Standard.Base.Any.Any
11+
- Standard.Table.Table_Selector.Table_Selector.from that:Standard.Base.Data.Text.Text -> Standard.Table.Table_Selector.Table_Selector
12+
- Standard.Table.Table_Selector.Table_Selector.from that:Standard.Base.Data.Numbers.Integer -> Standard.Table.Table_Selector.Table_Selector
13+
- Standard.Table.Table_Selector.Table_Selector.from that:Standard.Base.Data.Text.Regex.Regex -> Standard.Table.Table_Selector.Table_Selector
14+
- Standard.Table.Table_Selector.Table_Selector.from that:Standard.Table.Value_Type.By_Type -> Standard.Table.Table_Selector.Table_Selector
15+
- Standard.Table.Table_Selector.Table_Selector.from that:Standard.Base.Function.Function -> Standard.Table.Table_Selector.Table_Selector
16+
- Standard.Table.Table_Selector.Table_Selector.from that:Standard.Base.Data.Vector.Vector -> Standard.Table.Table_Selector.Table_Selector

distribution/lib/Standard/Table/0.0.0-dev/src/Set_Mode.enso

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from Standard.Base import Text
2+
13
type Set_Mode
24
## Add a new column to the table.
35
If already present an `Existing_Column` error is returned.
@@ -9,3 +11,34 @@ type Set_Mode
911

1012
## Add the column to the table if not present, or update if present.
1113
Add_Or_Update
14+
15+
type Set_Mode_Many
16+
## Update the column in the table.
17+
If not present a `Missing_Column` error is returned.
18+
Update
19+
20+
## Add a new column to the table.
21+
If already present an `Existing_Column` error is returned.
22+
Add as:Text="New {{Column}}"
23+
24+
## Add the column to the table if not present, or update if present.
25+
Add_Or_Update as:Text="New {{Column}}"
26+
27+
## ---
28+
private: true
29+
---
30+
Get the `as` value associated with the Set_Mode_Many variant.
31+
as_value self = case self of
32+
Set_Mode_Many.Update -> "{{Column}}"
33+
Set_Mode_Many.Add as -> as
34+
Set_Mode_Many.Add_Or_Update as -> as
35+
36+
Set_Mode.from (that:Set_Mode_Many) = case that of
37+
Set_Mode_Many.Update -> Set_Mode.Update
38+
Set_Mode_Many.Add _ -> Set_Mode.Add
39+
Set_Mode_Many.Add_Or_Update _ -> Set_Mode.Add_Or_Update
40+
41+
Set_Mode_Many.from (that:Set_Mode) = case that of
42+
Set_Mode.Add -> Set_Mode_Many.Add
43+
Set_Mode.Update -> Set_Mode_Many.Update
44+
Set_Mode.Add_Or_Update -> Set_Mode_Many.Add_Or_Update

distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import project.Row.Row
5151
import project.Row_Limit.Row_Limit
5252
import project.Rows_To_Read.Rows_To_Read
5353
import project.Set_Mode.Set_Mode
54+
import project.Set_Mode.Set_Mode_Many
5455
import project.Simple_Expression.Simple_Expression
5556
import project.Sort_Column.Sort_Column
5657
import project.Table_Selector.Table_Selector
@@ -2618,6 +2619,46 @@ type Table
26182619
set self (value : Text | Expression | Column | Constant_Column | Simple_Expression = Missing_Argument.throw "value") as:Text="" set_mode:Set_Mode=..Add_Or_Update on_problems:Problem_Behavior=..Report_Warning -> Table & Any ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error =
26192620
self.implementation.set self.underlying value as set_mode on_problems
26202621

2622+
2623+
## ---
2624+
private: true
2625+
---
2626+
Adds or updates multiple columns on the table.
2627+
2628+
All calculation are performed based on the original table, so that the
2629+
order of setting columns does not matter.
2630+
2631+
## Arguments
2632+
- `columns`: The columns to set.
2633+
- `value`: The expression to create columns. Use `{{Column}}` as a
2634+
placeholder for the current column.
2635+
- `set_mode`: Specifies the expected behaviour in regards to existing
2636+
columns with the same name.
2637+
- `as`: If not in `Update` mode, the naming pattern for the new
2638+
columns. Use `{{Column}}` as a placeholder for the current column
2639+
name.
2640+
- `error_on_missing_columns`: If `True`, an error is raised if a
2641+
specified column is not found. If `False`, the missing column is
2642+
ignored.
2643+
- `on_problems`: Specifies how to handle problems with expression
2644+
evaluation.
2645+
2646+
## Returns
2647+
- Returns the updated Table along with the newly created or updated
2648+
columns.
2649+
@columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True)
2650+
set_many self (columns : Table_Selector = Missing_Argument.throw "columns") (value : Text = Missing_Argument.throw "value") set_mode:Set_Mode_Many=..Update error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning -> Table & Any ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error =
2651+
col_name = self.make_temp_column_name
2652+
as = set_mode.as_value
2653+
value_expr = Expression.Value (value.replace "{{Column}}" "["+col_name+"]")
2654+
columns.act_if_any self error_on_missing_columns selected->
2655+
new_columns = selected.map column_name->
2656+
as_name = as.replace "{{Column}}" column_name
2657+
column = self.at column_name
2658+
result = self.set column col_name . set value_expr as_name on_problems=on_problems
2659+
result.at as_name
2660+
new_columns.fold self current->new-> current.set new new.name set_mode
2661+
26212662
## ---
26222663
private: true
26232664
---

distribution/lib/Standard/Table/0.0.0-dev/src/Table_Selector.enso

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ type Table_Selector
2929
Table_Selector.Index i -> i
3030
Table_Selector.Regex r -> r
3131
Table_Selector.By_Type bt -> bt
32-
matched = table.select_columns flatten error_on_missing_columns=error_on_missing_columns on_problems=..Ignore . column_names
33-
if error_on_missing_columns then matched else
34-
matched.catch No_Output_Columns _->[]
32+
if flatten.length == 0 then [] else
33+
matched = table.select_columns flatten error_on_missing_columns=error_on_missing_columns on_problems=..Ignore . column_names
34+
if error_on_missing_columns then matched else
35+
matched.catch No_Output_Columns _->[]
3536
_ -> Table_Selector.Vector [self] . resolve table error_on_missing_columns
3637

3738
## ---
@@ -51,6 +52,9 @@ Table_Selector.from (that:Regex) = Table_Selector.Regex that
5152

5253
Table_Selector.from (that:By_Type) = Table_Selector.By_Type that
5354

55+
Table_Selector.from (that:Function) =
56+
Table_Selector.from (that:By_Type)
57+
5458
Table_Selector.from (that:Vector) =
5559
selectors = that.map v-> v.to Table_Selector
5660
Table_Selector.Vector selectors

0 commit comments

Comments
 (0)