From d938c96c5545a59be0d9336a79933401352e7fc6 Mon Sep 17 00:00:00 2001 From: James Dunkerley Date: Mon, 10 Jun 2024 08:52:32 +0100 Subject: [PATCH] Adding type annotations and enabling auto-scoping (#10173) - Renamed `Missing_Required_Argument` to `Missing_Argument`, and added `throw` method. - Add default widget to `Case_Sensitivity.Insensitive locale`. - Switch to auto scoping for `parse_type_selector`. - Add type annotation to various simple typed arguments in `Table` and `DB_Table`. - Altered `Filter_Condition` to have `Missing_Argument` for all non-defaulted arguments. - Added resolution of `Column_Ref` passed as auto-scoped to `Table_Ref`. - Altered `Simple_Calculation` to have `Missing_Argument` for all non-defaulted arguments. - Altered `Join_Condition` to have `Missing_Argument` for all non-defaulted arguments. - Altered `Sort_Column` to have `Missing_Argument` for all non-defaulted arguments. - Altered `Aggregate_Column` to have `Missing_Argument` for all non-defaulted arguments. **rename_columns:** ![image](https://github.com/enso-org/enso/assets/4699705/08aaba0f-687a-450c-9781-8eadc062bd50) **aggregate:** ![image](https://github.com/enso-org/enso/assets/4699705/c29e7944-1a1c-4020-9fe0-528d874b8049) **join:** ![image](https://github.com/enso-org/enso/assets/4699705/50038166-e56d-48c5-9eeb-bd46fa415e46) **set:** ![image](https://github.com/enso-org/enso/assets/4699705/bee2462a-dafb-4bd4-b102-ec73edb4fb93) --- .../0.0.0-dev/src/Data/Filter_Condition.enso | 69 ++++----- .../0.0.0-dev/src/Data/Index_Sub_Range.enso | 9 +- .../src/Data/Text/Case_Sensitivity.enso | 1 + .../Base/0.0.0-dev/src/Errors/Common.enso | 23 +-- .../Base/0.0.0-dev/src/Widget_Helpers.enso | 15 +- .../Database/0.0.0-dev/src/DB_Column.enso | 2 +- .../Database/0.0.0-dev/src/DB_Table.enso | 128 +++++++++-------- .../Table/0.0.0-dev/src/Aggregate_Column.enso | 3 +- .../Standard/Table/0.0.0-dev/src/Column.enso | 2 +- .../Table/0.0.0-dev/src/Data_Formatter.enso | 2 +- .../src/Internal/Aggregate_Column_Helper.enso | 2 +- .../0.0.0-dev/src/Internal/Java_Exports.enso | 10 +- .../0.0.0-dev/src/Internal/Join_Helpers.enso | 6 +- .../0.0.0-dev/src/Internal/Table_Helpers.enso | 9 +- .../0.0.0-dev/src/Internal/Table_Ref.enso | 14 +- .../src/Internal/Widget_Helpers.enso | 133 ++++++++---------- .../Table/0.0.0-dev/src/Join_Condition.enso | 10 +- .../0.0.0-dev/src/Simple_Expression.enso | 71 +++++----- .../Table/0.0.0-dev/src/Sort_Column.enso | 13 +- .../Standard/Table/0.0.0-dev/src/Table.enso | 105 +++++++------- .../callable/UnresolvedConstructor.java | 3 + test/Base_Tests/src/Data/Text_Spec.enso | 13 +- test/Base_Tests/src/Data/Vector_Spec.enso | 12 +- .../Missing_Required_Arguments_Spec.enso | 20 +-- test/Base_Tests/src/Widget_Helpers_Spec.enso | 2 +- .../Aggregate_Spec.enso | 24 ++++ .../Derived_Columns_Spec.enso | 4 + .../Common_Table_Operations/Filter_Spec.enso | 17 ++- .../Join/Join_Spec.enso | 9 ++ .../Order_By_Spec.enso | 17 +++ .../Take_Drop_Spec.enso | 25 +--- .../src/Formatting/Data_Formatter_Spec.enso | 3 +- .../src/Formatting/Parse_Values_Spec.enso | 5 +- 33 files changed, 398 insertions(+), 383 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso index 9618b086b780..d7b817f8f7dc 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso @@ -8,10 +8,12 @@ import project.Data.Text.Text import project.Data.Vector.Vector import project.Error.Error import project.Errors.Common.Incomparable_Values +import project.Errors.Common.Missing_Argument import project.Errors.Illegal_Argument.Illegal_Argument import project.Function.Function import project.Meta import project.Nothing.Nothing +import project.Panic.Panic from project.Data.Boolean import Boolean, False, True from project.Data.Filter_Condition.Filter_Condition import all from project.Data.Text.Extensions import all @@ -22,25 +24,25 @@ polyglot java import org.enso.base.Regex_Utils type Filter_Condition ## Is less than a value (or another column, in case of Table operations)? - Less than:Any action:Filter_Action=Filter_Action.Keep + Less than=(Missing_Argument.throw "than") action:Filter_Action=Filter_Action.Keep ## Is less than or equal to a value (or another column, in case of Table operations)? - Equal_Or_Less than:Any action:Filter_Action=Filter_Action.Keep + Equal_Or_Less than=(Missing_Argument.throw "than") action:Filter_Action=Filter_Action.Keep ## Is equal to a value (or another column, in case of Table operations)? - Equal to:Any action:Filter_Action=Filter_Action.Keep + Equal to=(Missing_Argument.throw "to") action:Filter_Action=Filter_Action.Keep ## Is greater than or equal to a value (or another column, in case of Table operations)? - Equal_Or_Greater than:Any action:Filter_Action=Filter_Action.Keep + Equal_Or_Greater than=(Missing_Argument.throw "than") action:Filter_Action=Filter_Action.Keep ## Is greater than a value (or another column, in case of Table operations)? - Greater than:Any action:Filter_Action=Filter_Action.Keep + Greater than=(Missing_Argument.throw "than") action:Filter_Action=Filter_Action.Keep ## Is not equal to a value (or another column, in case of Table operations)? - Not_Equal to:Any action:Filter_Action=Filter_Action.Keep + Not_Equal to=(Missing_Argument.throw "to") action:Filter_Action=Filter_Action.Keep ## Is between (inclusive) two values (or columns, in case of Table operations)? - Between lower:Any upper:Any action:Filter_Action=Filter_Action.Keep + Between lower=(Missing_Argument.throw "lower") upper=(Missing_Argument.throw "upper") action:Filter_Action=Filter_Action.Keep ## Is equal to another value, ignoring case (Text only)? @@ -55,7 +57,7 @@ type Filter_Condition This ensures that different ways of expressing the same character in the underlying binary representation are considered equal. @locale Locale.default_widget - Equal_Ignore_Case (to : Text | Any) (locale:Locale=Locale.default) action:Filter_Action=Filter_Action.Keep + Equal_Ignore_Case (to = (Missing_Argument.throw "to")) (locale:Locale=Locale.default) action:Filter_Action=Filter_Action.Keep ## Does the value start with a prefix (Text only)? @@ -63,7 +65,7 @@ type Filter_Condition It accepts a Text value to check if the value contains it. In case of Table operations, it can accept another column - then the corresponding values from the source column and the provided column are checked. - Starts_With (prefix : Text | Any) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep + Starts_With (prefix = (Missing_Argument.throw "prefix")) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep ## Does the value end with a suffix (Text only)? @@ -71,7 +73,7 @@ type Filter_Condition It accepts a Text value to check if the value contains it. In case of Table operations, it can accept another column - then the corresponding values from the source column and the provided column are checked. - Ends_With (suffix : Text | Any) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep + Ends_With (suffix = (Missing_Argument.throw "suffix")) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep ## Does the value contain the substring (Text only)? @@ -79,7 +81,7 @@ type Filter_Condition It accepts a Text value to check if the value contains it. In case of Table operations, it can accept another column - then the corresponding values from the source column and the provided column are checked. - Contains (substring : Text | Any) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep + Contains (substring = (Missing_Argument.throw "substring")) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) action:Filter_Action=Filter_Action.Keep ## Is equal to Nothing? Is_Nothing action:Filter_Action=Filter_Action.Keep @@ -127,7 +129,7 @@ type Filter_Condition Due to this limitation, Unicode normalization has been disabled for this function, so beware that some equivalent graphemes like 'ś' and 's\u0301' will not be matched. - Like (pattern : Text | Any) action:Filter_Action=Filter_Action.Keep + Like (pattern = (Missing_Argument.throw "pattern")) action:Filter_Action=Filter_Action.Keep ## Is the value contained in `values`? @@ -141,7 +143,16 @@ type Filter_Condition Using Columns can be particularly useful for Database operations, as uploading a temporary table and using its column for an `Is_In` check will likely be faster than using the vector directly. - Is_In values:Vector|Any action:Filter_Action=Filter_Action.Keep + Is_In values=[] action:Filter_Action=Filter_Action.Keep + + ## PRIVATE + Resolves a possibly auto-scoped value to a concrete value. + resolve_auto_scoped : Any -> Any + resolve_auto_scoped filter = + resolve filter:Filter_Condition = filter + case filter of + _ : Function -> Panic.catch Any (resolve filter) _->filter + _ -> filter ## ICON convert Converts a `Filter_Condition` condition into a predicate taking an @@ -295,43 +306,15 @@ unify_condition_or_predicate : Filter_Condition | (Any -> Boolean) -> (Any -> Bo unify_condition_or_predicate (condition_or_predicate : Filter_Condition | (Any -> Boolean)) = case condition_or_predicate of condition : Filter_Condition -> condition.to_predicate - predicate -> handle_constructor_missing_arguments predicate predicate + predicate -> predicate ## PRIVATE unify_condition_predicate_or_element condition = case condition of condition : Filter_Condition -> condition.to_predicate - predicate : Function -> handle_constructor_missing_arguments predicate predicate + predicate : Function -> predicate element -> (== element) -## PRIVATE - Checks if the given `function` is actually a `Filter_Condition` constructor - that is just missing arguments. If so, it will report a more friendly error. - Otherwise it will run the `continuation`. -handle_constructor_missing_arguments function ~continuation = - is_filter_condition_constructor = case Meta.meta function of - constructor : Meta.Constructor -> - constructor.declaring_type == Meta.meta Filter_Condition - ## Special case for multi-argument constructors with some but not all - arguments applied. - - For example, `Meta.meta (Filter_Condition.Between 10)` will return a `Meta.Primitive`. - We rely on its text representation being of the form `Filter_Condition.Between[Filter_Condition.enso:41-343]`. - _ : Meta.Primitive -> - text = function.to_text - prefix = "Filter_Condition." - if (text.starts_with prefix && text.contains "[Filter_Condition.enso:") . not then False else - ## The additional check for capital letter is needed, because otherwise, we get false positives: - `(Filter_Condition.Greater 1).to_predicate` evaluates to function whose text representation - may start with `Filter_Condition.handle_nothing`. Such functions are not constructors. - constructor_letter = text.get prefix.length "" - constructor_letter >= "A" && constructor_letter <= "Z" - - _ -> False - if is_filter_condition_constructor.not then continuation else - message = "Got a Filter_Condition constructor without all required arguments provided. Please provide the missing arguments." - Error.throw (Illegal_Argument.Error message) - ## PRIVATE Extends the provided predicate to handle `Nothing` values without error. The new predicate will return `False` for `Nothing`. diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Index_Sub_Range.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Index_Sub_Range.enso index 3c0025c23037..720b20437c9c 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Index_Sub_Range.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Index_Sub_Range.enso @@ -5,6 +5,7 @@ import project.Data.Text.Text import project.Data.Vector.Vector import project.Error.Error import project.Errors.Common.Index_Out_Of_Bounds +import project.Errors.Common.Missing_Argument import project.Errors.Common.Type_Error import project.Errors.Illegal_Argument.Illegal_Argument import project.Function.Function @@ -35,7 +36,7 @@ type Index_Sub_Range Last (count : Integer = 1) ## Select elements from the start while the predicate returns `True`. - While (predicate : (Any -> Boolean)) + While (predicate : (Any -> Boolean) = Missing_Argument.throw "predicate") ## Selects specific indexes (starting from 0) either as an `Integer` or a `Range`. @@ -47,13 +48,13 @@ type Index_Sub_Range Only ranges with positive step and positive indices are supported. Individual integer indices can be negative which allows for indexing from the end of the collection. - By_Index (indexes : (Integer | Range | Vector (Integer | Range))) + By_Index (indexes : (Integer | Range | Vector (Integer | Range)) = Missing_Argument.throw "indexes") ## Gets a random sample of entries, without repetitions. If `count` is greater than the length of the input, a random permutation of all elements from the input is selected. - Sample (count:Integer) (seed:Integer|Nothing=Nothing) + Sample (count : Integer = 1) (seed:Integer|Nothing=Nothing) ## Gets every Nth entry. @@ -61,7 +62,7 @@ type Index_Sub_Range - step: The step between consecutive entries that are included. - first: The first entry to include. If it is outside of bounds of the input, an error is raised. - Every (step:Integer) (first:Integer=0) + Every (step:Integer=1) (first:Integer=0) ## PRIVATE Convert to a display representation of this Index_Sub_Range. diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Case_Sensitivity.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Case_Sensitivity.enso index a1603f182f07..ebb30718b667 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Case_Sensitivity.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Case_Sensitivity.enso @@ -21,6 +21,7 @@ type Case_Sensitivity Arguments: - locale: The locale used for the comparison. + @locale Locale.default_widget Insensitive (locale : Locale = Locale.default) ## PRIVATE diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso index 5144fe9892b2..9eb6f0b84197 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso @@ -460,16 +460,23 @@ type Out_Of_Memory ## Indicates that an expression cannot be evaluated because somewhere within it, a function does not have all required arguments provided. -type Missing_Required_Argument +type Missing_Argument ## PRIVATE Indicates that an expression cannot be evaluated because somewhere within it, a function does not have all required arguments provided. - Error (argument_name : Text) (function_name : Text) (call_location : Source_Location | Nothing) + Error (argument_name : Text) (function_name : Text | Nothing = Nothing) (call_location : Source_Location | Nothing = Nothing) ## PRIVATE to_display_text : Text - to_display_text self = - "Missing required argument `" + self.argument_name + "` in function `" + self.function_name + "`." + to_display_text self = case self.function_name of + Nothing -> "Provide a value for the argument `" + self.argument_name + "`." + _ -> "Missing required argument `" + self.argument_name + "` in function `" + self.function_name + "`." + + ## PRIVATE + Throws an error saying that a required argument has not been provided. + throw : Text -> Nothing ! Missing_Argument + throw argument_name:Text = + Error.throw (Missing_Argument.Error argument_name) ## PRIVATE Throws an error saying that a required argument has not been provided. @@ -482,16 +489,16 @@ type Missing_Required_Argument > Example - my_function (arg1 = Missing_Required_Argument.ensure_present "arg1") (arg2 = 100) = arg1+arg2 - ensure_present : Text -> Nothing ! Missing_Required_Argument - ensure_present (argument_name : Text = Missing_Required_Argument.ensure_present "argument_name") = + my_function (arg1 = Missing_Argument.ensure_present "arg1") (arg2 = 100) = arg1+arg2 + ensure_present : Text -> Nothing ! Missing_Argument + ensure_present (argument_name : Text = Missing_Argument.ensure_present "argument_name") = stack_trace = Runtime.get_stack_trace function_frame = stack_trace . at 1 caller_frame = stack_trace . at 2 function_name = function_frame.name call_location = caller_frame.source_location - Error.throw (Missing_Required_Argument.Error argument_name function_name call_location) + Error.throw (Missing_Argument.Error argument_name function_name call_location) ## Warning when additional warnings occurred. type Additional_Warnings diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Widget_Helpers.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Widget_Helpers.enso index 2459912f34d2..2202447ad979 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Widget_Helpers.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Widget_Helpers.enso @@ -143,17 +143,6 @@ make_format_chooser include_number:Boolean=True include_date:Boolean=True includ Creates a Multiple_Choice Widget for selecting data cleanse operations. make_data_cleanse_vector_selector : Display -> Widget make_data_cleanse_vector_selector display:Display=Display.Always = - options = Vector.build builder-> - builder.append (Option "Leading_Whitespace" "Named_Pattern.Leading_Whitespace") - builder.append (Option "Trailing_Whitespace" "Named_Pattern.Trailing_Whitespace") - builder.append (Option "Duplicate_Whitespace" "Named_Pattern.Duplicate_Whitespace") - builder.append (Option "All_Whitespace" "Named_Pattern.All_Whitespace") - builder.append (Option "Leading_Numbers" "Named_Pattern.Leading_Numbers") - builder.append (Option "Trailing_Numbers" "Named_Pattern.Trailing_Numbers") - builder.append (Option "Non_ASCII" "Named_Pattern.Non_ASCII") - builder.append (Option "Tabs" "Named_Pattern.Tabs") - builder.append (Option "Letters" "Named_Pattern.Letters") - builder.append (Option "Numbers" "Named_Pattern.Numbers") - builder.append (Option "Punctuation" "Named_Pattern.Punctuation") - builder.append (Option "Symbols" "Named_Pattern.Symbols") + patterns = ['Leading_Whitespace', 'Trailing_Whitespace', 'Duplicate_Whitespace', 'All_Whitespace', 'Leading_Numbers', 'Trailing_Numbers', 'Non_ASCII', 'Tabs', 'Letters', 'Numbers', 'Punctuation', 'Symbols'] + options = patterns.map f-> Option f (".." + f) Multiple_Choice values=options display=display diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/DB_Column.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/DB_Column.enso index 1bc9a89f50a4..512376c87262 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/DB_Column.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/DB_Column.enso @@ -1732,7 +1732,7 @@ type DB_Column @type (Widget_Helpers.parse_type_selector include_auto=False) @format (make_format_chooser include_number=False) parse : Value_Type | Auto -> Text | Data_Formatter -> Problem_Behavior -> DB_Column - parse self type format:(Text | Data_Formatter)="" on_problems=Report_Warning = + parse self type:(Value_Type | Auto) format:(Text | Data_Formatter)="" on_problems=Report_Warning = if type == Auto then Error.throw (Unsupported_Database_Operation.Error "The `Auto` parse type is not supported by the Database backend. Either pick a specific type or materialize the table to memory using `.read`.") else if format != "" then Error.throw (Unsupported_Database_Operation.Error "Custom formatting is not supported by the Database backend. Please set the format to `''` to use the default settings, or if custom formatting is needed, materialize the table to memory using `.read` first.") else Value_Type.expect_text self <| diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/DB_Table.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/DB_Table.enso index 501da371514c..b885924ae692 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/DB_Table.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/DB_Table.enso @@ -104,7 +104,7 @@ type DB_Table - show_rows: the number of initial rows that should be displayed. - format_terminal: whether ANSI-terminal formatting should be used display : Integer -> Boolean -> Text - display self show_rows=10 format_terminal=False = + display self show_rows:Integer=10 format_terminal:Boolean=False = data_fragment_with_warning = self.read (..First_With_Warning show_rows) has_more_rows = data_fragment_with_warning.has_warnings warning_type=Not_All_Rows_Downloaded data_fragment_cleared = data_fragment_with_warning.remove_warnings Not_All_Rows_Downloaded @@ -168,7 +168,7 @@ type DB_Table @selector Widget_Helpers.make_column_name_selector @index (t-> Widget.Numeric_Input minimum=0 maximum=t.row_count-1) get_value : Text | Integer -> Integer -> Any -> Any - get_value self selector=0 index=0 ~if_missing=Nothing = + get_value self selector:Integer=0 index:Integer=0 ~if_missing=Nothing = col = self.get selector if_missing=Nothing if Nothing == col then if_missing else col.get index if_missing @@ -260,7 +260,7 @@ type DB_Table table.select_columns [..By_Type ..Integer] @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) select_columns : Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> Boolean -> Case_Sensitivity -> Boolean -> Problem_Behavior -> DB_Table ! No_Output_Columns | Missing_Input_Columns - select_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (reorder:Boolean=False) (case_sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=Report_Warning) = + select_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (reorder:Boolean=False) (case_sensitivity:Case_Sensitivity=..Default) (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=..Report_Warning) = new_columns = self.columns_helper.select_columns columns case_sensitivity reorder error_on_missing_columns on_problems self.updated_columns (new_columns.map _.as_internal) @@ -338,7 +338,7 @@ type DB_Table table.remove_columns [..By_Type ..Integer] @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) remove_columns : Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> Case_Sensitivity -> Boolean -> Problem_Behavior -> DB_Table ! No_Output_Columns | Missing_Input_Columns - remove_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (case_sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=Report_Warning) = + remove_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (case_sensitivity:Case_Sensitivity=..Default) (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=..Report_Warning) = new_columns = self.columns_helper.remove_columns columns case_sensitivity error_on_missing_columns=error_on_missing_columns on_problems=on_problems self.updated_columns (new_columns.map _.as_internal) @@ -383,7 +383,7 @@ type DB_Table table.select_blank_columns select_blank_columns : Blank_Selector -> Boolean -> DB_Table - select_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells) treat_nans_as_blank=False = + select_blank_columns self (when : Blank_Selector = ..All_Cells) treat_nans_as_blank:Boolean=False = new_columns = self.columns_helper.select_blank_columns_helper when treat_nans_as_blank self.updated_columns new_columns @@ -409,7 +409,7 @@ type DB_Table table.remove_blank_columns remove_blank_columns : Blank_Selector -> Boolean -> DB_Table - remove_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells) treat_nans_as_blank=False = + remove_blank_columns self (when : Blank_Selector = ..All_Cells) treat_nans_as_blank:Boolean=False = new_columns = self.columns_helper.select_blank_columns_helper when treat_nans_as_blank invert_selection=True self.updated_columns new_columns @@ -464,7 +464,7 @@ type DB_Table table.reorder_columns [0] position=Position.After_Other_Columns @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) reorder_columns : Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> Position -> Case_Sensitivity -> Boolean -> Problem_Behavior -> DB_Table ! Missing_Input_Columns - reorder_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (position:Position=Position.Before_Other_Columns) (case_sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=Report_Warning) = + reorder_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (position:Position=..Before_Other_Columns) (case_sensitivity:Case_Sensitivity=..Default) (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=..Report_Warning) = new_columns = self.columns_helper.reorder_columns columns position case_sensitivity error_on_missing_columns on_problems self.updated_columns (new_columns.map _.as_internal) @@ -493,7 +493,7 @@ type DB_Table table.reorder_columns Sort_Direction.Descending sort_columns : Sort_Direction -> Text_Ordering -> DB_Table - sort_columns self order=Sort_Direction.Ascending text_ordering=Text_Ordering.Default = + sort_columns self order:Sort_Direction=..Ascending text_ordering:Text_Ordering=..Default = new_columns = Table_Helpers.sort_columns internal_columns=self.internal_columns order text_ordering self.updated_columns new_columns @@ -564,7 +564,7 @@ type DB_Table table.rename_columns (Map.from_vector [["name=(.*)".to_regex, "key:$1"]]) @column_map Widget_Helpers.make_rename_name_vector_selector rename_columns : Map (Text | Integer | Regex) Text | Vector Text | Vector Vector -> Case_Sensitivity -> Boolean -> Problem_Behavior -> DB_Table ! Missing_Input_Columns | Ambiguous_Column_Rename | Too_Many_Column_Names_Provided | Invalid_Column_Names | Duplicate_Output_Column_Names - rename_columns self (column_map:(Table | Map | Vector)=["Column"]) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=Report_Warning) = case column_map of + rename_columns self (column_map:(Table | Map | Vector)=["Column"]) (case_sensitivity:Case_Sensitivity=..Default) (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=..Report_Warning) = case column_map of _ : Table -> resolved = Table_Helpers.read_name_map_from_table column_map self.rename_columns resolved case_sensitivity error_on_missing_columns on_problems @@ -593,7 +593,7 @@ type DB_Table table.use_first_row_as_names use_first_row_as_names : Problem_Behavior -> DB_Table - use_first_row_as_names self (on_problems=Report_Warning) = + use_first_row_as_names self (on_problems:Problem_Behavior=..Report_Warning) = _ = on_problems Error.throw (Unsupported_Database_Operation.Error "DB_Table.use_first_row_as_names is currently not implemented for the Database backend. You may download the table to memory using `.read` to use this feature.") @@ -665,28 +665,27 @@ type DB_Table @column (Widget_Helpers.make_column_name_selector add_expression=True) @filter Widget_Helpers.make_filter_condition_selector filter : (DB_Column | Text | Integer) -> (Filter_Condition | (Any -> Boolean)) -> Problem_Behavior -> DB_Table ! No_Such_Column | Index_Out_Of_Bounds | Invalid_Value_Type - filter self column (filter : Filter_Condition | (Any -> Boolean) = Filter_Condition.Equal True) on_problems=Report_Warning = case column of - _ : DB_Column -> - mask filter_column = case Helpers.check_integrity self filter_column of - False -> - Error.throw (Integrity_Error.Error "DB_Column "+filter_column.name) - True -> - new_filters = self.context.where_filters + [filter_column.expression] - new_ctx = self.context.set_where_filters new_filters - self.updated_context new_ctx - case filter of - _ : Filter_Condition -> - resolved = (self:Table_Ref).resolve_condition filter - mask (make_filter_column column resolved on_problems) - ## We check the `filter` predicate before reporting unsupported - operation, because it may just be a Filter_Condition with - missing arguments and then another error is more appropriate. - _ : Function -> Filter_Condition_Module.handle_constructor_missing_arguments filter <| - Error.throw (Unsupported_Database_Operation.Error "Filtering with a custom predicate is not supported in the database.") - _ : Expression -> self.filter (self.evaluate_expression column on_problems) filter on_problems - _ -> - table_at = self.at column - self.filter table_at filter on_problems + filter self column (filter : Filter_Condition | (Any -> Boolean) = Filter_Condition.Equal True) on_problems:Problem_Behavior=..Report_Warning = case column of + _ : DB_Column -> + mask filter_column = case Helpers.check_integrity self filter_column of + False -> + Error.throw (Integrity_Error.Error "DB_Column "+filter_column.name) + True -> + new_filters = self.context.where_filters + [filter_column.expression] + new_ctx = self.context.set_where_filters new_filters + self.updated_context new_ctx + + filter_condition = Filter_Condition.resolve_auto_scoped filter + case filter_condition of + _ : Filter_Condition -> + resolved = (self:Table_Ref).resolve_condition filter_condition + mask (make_filter_column column resolved on_problems) + _ : Function -> + Error.throw (Unsupported_Database_Operation.Error "Filtering with a custom predicate is not supported in the database.") + _ : Expression -> self.filter (self.evaluate_expression column on_problems) filter on_problems + _ -> + table_at = self.at column + self.filter table_at filter on_problems ## PRIVATE ALIAS filter rows @@ -723,7 +722,7 @@ type DB_Table people.filter_by_expression "[age] % 10 == 0" filter_by_expression : Text -> Problem_Behavior -> DB_Table ! No_Such_Column | Invalid_Value_Type | Expression_Error - filter_by_expression self expression:Text on_problems=Report_Warning = + filter_by_expression self expression:Text on_problems:Problem_Behavior=..Report_Warning = column = self.evaluate_expression (Expression.Value expression) on_problems result = self.filter column Filter_Condition.Is_True Warning.attach (Deprecated.Warning "Standard.Database.DB_Table.DB_Table" "filter_by_expression" "Deprecated: use `filter` with an `Expression` instead.") result @@ -757,7 +756,7 @@ type DB_Table table.take (While row-> row.to_vector.compute Statistic.Sum == 10) @range Index_Sub_Range.default_widget take : (Index_Sub_Range | Range | Integer) -> DB_Table - take self range=(First 1) = + take self range:(Index_Sub_Range | Range | Integer)=(..First 1) = Take_Drop_Helpers.take_drop_helper Take_Drop.Take self range ## ALIAS skip, remove @@ -789,7 +788,7 @@ type DB_Table table.drop (While row-> row.to_vector.compute Statistic.Sum == 10) @range Index_Sub_Range.default_widget drop : (Index_Sub_Range | Range | Integer) -> DB_Table - drop self range=(First 1) = + drop self range:(Index_Sub_Range | Range | Integer)=(..First 1) = Take_Drop_Helpers.take_drop_helper Take_Drop.Drop self range ## PRIVATE @@ -832,7 +831,7 @@ type DB_Table @group_by Widget_Helpers.make_column_name_multi_selector @order_by Widget_Helpers.make_order_by_selector add_row_number : Text -> Integer -> Integer -> Vector (Text | Integer | Regex) | Text | Integer | Regex -> Vector (Text | Sort_Column) | Text -> Problem_Behavior -> DB_Table - add_row_number self (name:Text="Row") (from:Integer=1) (step:Integer=1) (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (on_problems:Problem_Behavior=Problem_Behavior.Report_Warning) = + add_row_number self (name:Text="Row") (from:Integer=1) (step:Integer=1) (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (on_problems:Problem_Behavior=..Report_Warning) = problem_builder = Problem_Builder.new error_on_missing_columns=True grouping_columns = self.columns_helper.select_columns_helper group_by Case_Sensitivity.Default True problem_builder grouping_columns.each column-> @@ -903,7 +902,7 @@ type DB_Table t2 = t1.filter 'A' (Greater than=5) t2.read limit : Integer -> DB_Table - limit self max_rows = + limit self max_rows:Integer=1000 = new_ctx = self.context.set_limit max_rows self.updated_context new_ctx @@ -951,8 +950,8 @@ type DB_Table table.set double_inventory as="total_stock" table.set (expr "2 * [total_stock]") as="total_stock_expr" @value Simple_Expression.default_widget - set : DB_Column | Text | Expression | Array | Vector | Range | Date_Range | Constant_Column | Simple_Expression | Column_Operation -> Text -> Set_Mode -> Problem_Behavior -> DB_Table ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error - set self value (as : Text = "") (set_mode : Set_Mode = Set_Mode.Add_Or_Update) (on_problems : Problem_Behavior = Report_Warning) = + set : DB_Column | Text | Expression | Array | Vector | Range | Date_Range | Constant_Column | Simple_Expression -> Text -> Set_Mode -> Problem_Behavior -> DB_Table ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error + set self value:(DB_Column | Text | Expression | Array | Vector | Range | Date_Range | Constant_Column | Simple_Expression) (as : Text = "") (set_mode : Set_Mode = ..Add_Or_Update) (on_problems : Problem_Behavior = ..Report_Warning) = problem_builder = Problem_Builder.new unique = self.column_naming_helper.create_unique_name_strategy unique.mark_used self.column_names @@ -964,7 +963,6 @@ type DB_Table if Helpers.check_integrity self value then value else Error.throw (Integrity_Error.Error "Column "+value.name) _ : Constant_Column -> self.make_constant_column value - _ : Column_Operation -> (value:Simple_Expression).evaluate self (set_mode==Set_Mode.Update && as=="") on_problems _ : Simple_Expression -> value.evaluate self (set_mode==Set_Mode.Update && as=="") on_problems _ : Vector -> Error.throw (Unsupported_Database_Operation.Error "Cannot use `Vector` for `set` in the database.") _ : Array -> Error.throw (Unsupported_Database_Operation.Error "Cannot use `Array` for `set` in the database.") @@ -1018,7 +1016,7 @@ type DB_Table - If more than 10 rows encounter computation issues, an `Additional_Warnings`. evaluate_expression : Text | Expression -> Problem_Behavior -> DB_Column ! No_Such_Column | Invalid_Value_Type | Expression_Error - evaluate_expression self expression:(Text | Expression) on_problems:Problem_Behavior=Report_Warning = if expression.is_a Text then self.evaluate_expression (Expression.Value expression) on_problems else + evaluate_expression self expression:(Text | Expression) on_problems:Problem_Behavior=..Report_Warning = if expression.is_a Text then self.evaluate_expression (Expression.Value expression) on_problems else get_column name = self.at name new_column = Expression.evaluate expression get_column self.make_constant_column "Standard.Database.DB_Column" "DB_Column" DB_Column.var_args_functions problems = Warning.get_all new_column . map .value @@ -1252,7 +1250,7 @@ type DB_Table table.order_by [(Sort_Column.Select_By_Name "a.*".to_regex case_sensitivity=Case_Sensitivity.Insensitive)] @columns Widget_Helpers.make_order_by_selector order_by : Vector (Text | Sort_Column) | Text -> Text_Ordering -> Boolean -> Problem_Behavior -> DB_Table ! Incomparable_Values | No_Input_Columns_Selected | Missing_Input_Columns - order_by self (columns = ([(Sort_Column.Name (self.columns.at 0 . name))])) text_ordering=Text_Ordering.Default error_on_missing_columns=True on_problems=Problem_Behavior.Report_Warning = + order_by self (columns = ([(Sort_Column.Name (self.columns.at 0 . name))])) text_ordering:Text_Ordering=..Default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns types_to_always_throw=[No_Input_Columns_Selected] columns_for_ordering = Table_Helpers.prepare_order_by self.columns columns problem_builder problem_builder.attach_problems_before on_problems <| @@ -1334,7 +1332,7 @@ type DB_Table setting. @columns Widget_Helpers.make_column_name_multi_selector distinct : Vector (Integer | Text | Regex) | Text | Integer | Regex -> Case_Sensitivity -> Boolean -> Problem_Behavior -> DB_Table ! No_Output_Columns | Missing_Input_Columns | No_Input_Columns_Selected | Floating_Point_Equality - distinct self columns=self.column_names case_sensitivity=Case_Sensitivity.Default error_on_missing_columns=True on_problems=Report_Warning = + distinct self columns=self.column_names case_sensitivity:Case_Sensitivity=..Default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=Report_Warning = key_columns = self.columns_helper.select_columns columns Case_Sensitivity.Default reorder=True error_on_missing_columns=error_on_missing_columns on_problems=on_problems . catch No_Output_Columns _-> Error.throw No_Input_Columns_Selected problem_builder = Problem_Builder.new @@ -1418,7 +1416,7 @@ type DB_Table @join_kind Widget_Helpers.make_join_kind_selector @on Widget_Helpers.make_join_condition_selector join : DB_Table -> Join_Kind -> Join_Condition | Text | Vector (Join_Condition | Text) -> Text -> Problem_Behavior -> DB_Table - join self right (join_kind : Join_Kind = Join_Kind.Left_Outer) (on : Join_Condition | Text | Vector (Join_Condition | Text) = (default_join_condition self join_kind)) (right_prefix:Text="Right ") (on_problems:Problem_Behavior=Report_Warning) = + join self right (join_kind : Join_Kind = ..Left_Outer) (on : Join_Condition | Text | Vector (Join_Condition | Text) = (default_join_condition self join_kind)) (right_prefix:Text="Right ") (on_problems:Problem_Behavior=..Report_Warning) = self.join_or_cross_join right join_kind on right_prefix on_problems ## PRIVATE @@ -1523,7 +1521,7 @@ type DB_Table The ordering of rows in the resulting table is not specified. cross_join : DB_Table -> Integer | Nothing -> Text -> Problem_Behavior -> DB_Table - cross_join self right:DB_Table right_row_limit=100 right_prefix="Right " on_problems=Report_Warning = + cross_join self right:DB_Table right_row_limit=100 right_prefix:Text="Right " on_problems:Problem_Behavior=..Report_Warning = limit_problems = case right_row_limit.is_nothing.not && (right.row_count > right_row_limit) of True -> [Cross_Join_Row_Limit_Exceeded.Error right_row_limit right.row_count] @@ -1588,7 +1586,7 @@ type DB_Table that are not present in this table, an `Unexpected_Extra_Columns`. @key_columns Widget_Helpers.make_column_name_multi_selector merge : DB_Table -> (Vector (Integer | Text | Regex) | Text | Integer | Regex) -> Boolean -> Boolean -> Problem_Behavior -> DB_Table ! Missing_Input_Columns | Non_Unique_Key | Unmatched_Rows_In_Lookup - merge self lookup_table:DB_Table key_columns:(Vector (Integer | Text | Regex) | Text | Integer | Regex) add_new_columns:Boolean=False allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=Problem_Behavior.Report_Warning = + merge self lookup_table:DB_Table key_columns:(Vector (Integer | Text | Regex) | Text | Integer | Regex) add_new_columns:Boolean=False allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=..Report_Warning = Helpers.ensure_same_connection "table" [self, lookup_table] <| Lookup_Query_Helper.build_lookup_query self lookup_table key_columns add_new_columns allow_unmatched_rows on_problems @@ -1671,7 +1669,7 @@ type DB_Table @from_column Widget.Text_Input @to_column Widget.Text_Input replace : (DB_Table | Map) -> Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> (Text | Integer | Nothing) -> (Text | Integer | Nothing) -> Boolean -> Problem_Behavior -> DB_Table ! Missing_Input_Columns | Non_Unique_Key | Unmatched_Rows_In_Lookup - replace self lookup_table:(DB_Table | Map) columns:(Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type) from_column:(Text | Integer | Nothing)=Nothing to_column:(Text | Integer | Nothing)=Nothing allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=Problem_Behavior.Report_Warning = + replace self lookup_table:(DB_Table | Map) columns:(Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type) from_column:(Text | Integer | Nothing)=Nothing to_column:(Text | Integer | Nothing)=Nothing allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=..Report_Warning = Replace_Helpers.replace self lookup_table columns from_column to_column allow_unmatched_rows on_problems ## ALIAS join by row position @@ -1722,7 +1720,7 @@ type DB_Table `Undefined_Column_Order` problem and returning an empty table. @keep_unmatched (make_single_choice [["True", "Boolean.True"], ["False", "Boolean.False"], ["Report", Meta.get_qualified_type_name Report_Unmatched]]) zip : DB_Table -> Boolean | Report_Unmatched -> Text -> Problem_Behavior -> DB_Table - zip self right keep_unmatched=Report_Unmatched right_prefix="Right " on_problems=Report_Warning = + zip self right keep_unmatched=Report_Unmatched right_prefix:Text="Right " on_problems:Problem_Behavior=..Report_Warning = _ = [right, keep_unmatched, right_prefix, on_problems] Error.throw (Unsupported_Database_Operation.Error "DB_Table.zip is not implemented yet for the Database backends.") @@ -1805,7 +1803,7 @@ type DB_Table @tables (Widget.Vector_Editor item_editor=Widget.Code_Input item_default='_' display=Display.Always) @columns_to_keep Columns_To_Keep.default_widget union : (DB_Table | Vector DB_Table) -> Columns_To_Keep -> Match_Columns -> Problem_Behavior -> DB_Table - union self tables:(DB_Table | Vector) (columns_to_keep : Columns_To_Keep = ..In_Any_Warn_On_Missing) (match_columns : Match_Columns = Match_Columns.By_Name) (on_problems : Problem_Behavior = Report_Warning) = + union self tables:(DB_Table | Vector) (columns_to_keep : Columns_To_Keep = ..In_Any_Warn_On_Missing) (match_columns : Match_Columns = ..By_Name) (on_problems : Problem_Behavior = ..Report_Warning) = all_tables = case tables of v : Vector -> [self] + (v.map t-> DB_Table.from t) single_table -> [self, single_table] @@ -1958,7 +1956,7 @@ type DB_Table @group_by Widget_Helpers.make_column_name_multi_selector @columns Widget_Helpers.make_aggregate_column_vector_selector aggregate : Vector (Integer | Text | Regex | Aggregate_Column) | Text | Integer | Regex -> Vector Aggregate_Column -> Boolean -> Problem_Behavior -> DB_Table ! No_Output_Columns | Invalid_Aggregate_Column | Invalid_Column_Names | Duplicate_Output_Column_Names | Floating_Point_Equality | Invalid_Aggregation | Unquoted_Delimiter | Additional_Warnings - aggregate self group_by=[] columns=[] (error_on_missing_columns=False) (on_problems=Report_Warning) = + aggregate self group_by=[] columns=[] (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=..Report_Warning) = normalized_group_by = Vector.unify_vector_or_element group_by if normalized_group_by.is_empty && columns.is_empty then Error.throw (No_Output_Columns.Error "At least one column must be specified.") else validated = Aggregate_Column_Helper.prepare_aggregate_columns self.column_naming_helper normalized_group_by columns self error_on_missing_columns=error_on_missing_columns @@ -2066,7 +2064,7 @@ type DB_Table B | Country | Germany @key_columns Widget_Helpers.make_column_name_multi_selector transpose : Vector (Integer | Text | Regex) | Text | Integer | Regex -> Text -> Text -> Boolean -> Problem_Behavior -> DB_Table ! No_Output_Columns | Missing_Input_Columns | Duplicate_Output_Column_Names - transpose self key_columns=[] (attribute_column_name="Name") (value_column_name="Value") (error_on_missing_columns=True) (on_problems = Report_Warning) = + transpose self key_columns=[] (attribute_column_name:Text="Name") (value_column_name:Text="Value") (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=..Report_Warning) = ## Avoid unused arguments warning. We cannot rename arguments to `_`, because we need to keep the API consistent with the in-memory table. _ = [key_columns, attribute_column_name, value_column_name, error_on_missing_columns, on_problems] @@ -2130,7 +2128,7 @@ type DB_Table @names Widget_Helpers.make_column_name_selector @values Widget_Helpers.make_aggregate_column_selector cross_tab : Vector (Integer | Text | Regex | Aggregate_Column) | Text | Integer | Regex -> (Text | Integer) -> Aggregate_Column | Vector Aggregate_Column -> Problem_Behavior -> DB_Table ! Missing_Input_Columns | Invalid_Aggregate_Column | Floating_Point_Equality | Invalid_Aggregation | Unquoted_Delimiter | Additional_Warnings | Invalid_Column_Names - cross_tab self group_by=[] names=self.column_names.first values=Aggregate_Column.Count (on_problems=Report_Warning) = + cross_tab self group_by=[] names=self.column_names.first values=..Count (on_problems:Problem_Behavior=..Report_Warning) = ## Avoid unused arguments warning. We cannot rename arguments to `_`, because we need to keep the API consistent with the in-memory table. _ = [group_by, names, values, on_problems] @@ -2193,7 +2191,7 @@ type DB_Table @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True) @format (make_format_chooser include_number=False) parse : Vector (Text | Integer | Regex) | Text | Integer | Regex -> Value_Type | Auto -> Text | Data_Formatter -> Boolean -> Problem_Behavior -> DB_Table - parse self columns=(self.columns . filter (c-> c.value_type.is_text) . map .name) type format:(Text | Data_Formatter)='' error_on_missing_columns=True on_problems=Report_Warning = + parse self columns=(self.columns . filter (c-> c.value_type.is_text) . map .name) type:(Value_Type | Auto) format:(Text | Data_Formatter)='' error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = selected = self.columns_helper.select_columns columns Case_Sensitivity.Default reorder=False error_on_missing_columns=error_on_missing_columns on_problems=on_problems error_on_empty=False . map self.make_column selected.fold self table-> column_to_parse-> new_column = column_to_parse.parse type format on_problems @@ -2276,7 +2274,7 @@ type DB_Table @locale Locale.default_widget @format (make_format_chooser include_number=True) format : Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type -> Text | Date_Time_Formatter | DB_Column -> Locale -> Boolean -> Problem_Behavior -> DB_Table ! Date_Time_Format_Parse_Error | Illegal_Argument - format self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type) format:(Text | Date_Time_Formatter | DB_Column)="" locale=Locale.default error_on_missing_columns=True on_problems=Report_Warning = + format self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type) format:(Text | Date_Time_Formatter | DB_Column)="" locale:Locale=Locale.default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = _ = [columns, format, locale, error_on_missing_columns, on_problems] Error.throw (Unsupported_Database_Operation.Error "DB_Table.format is not implemented yet for the Database backends.") @@ -2301,7 +2299,7 @@ type DB_Table @delimiter make_delimiter_selector @column_count Columns_To_Add.default_widget split_to_columns : Text | Integer -> Text -> Columns_To_Add -> Problem_Behavior -> DB_Table - split_to_columns self column delimiter="," (column_count : Columns_To_Add = ..All_Columns) on_problems=Report_Warning = + split_to_columns self column delimiter="," (column_count : Columns_To_Add = ..All_Columns) on_problems:Problem_Behavior=..Report_Warning = _ = [column, delimiter, column_count.columns_to_split, on_problems] Error.throw (Unsupported_Database_Operation.Error "DB_Table.split_to_columns is not implemented yet for the Database backends.") @@ -2344,7 +2342,7 @@ type DB_Table be reported according to the `on_problems` behavior. @column Widget_Helpers.make_column_name_selector tokenize_to_columns : Text | Integer -> Text -> Case_Sensitivity -> Columns_To_Add -> Problem_Behavior -> DB_Table - tokenize_to_columns self column pattern="." case_sensitivity=Case_Sensitivity.Sensitive (column_count : Columns_To_Add = ..All_Columns) (on_problems : Problem_Behavior = Report_Warning) = + tokenize_to_columns self column pattern="." case_sensitivity:Case_Sensitivity=..Sensitive (column_count : Columns_To_Add = ..All_Columns) (on_problems : Problem_Behavior = ..Report_Warning) = _ = [column, pattern, case_sensitivity, column_count, on_problems] Error.throw (Unsupported_Database_Operation.Error "DB_Table.tokenize_to_columns is not implemented yet for the Database backends.") @@ -2366,7 +2364,7 @@ type DB_Table Equivalent to converting a tokenization output of [] to [Nothing]. @column Widget_Helpers.make_column_name_selector tokenize_to_rows : Text | Integer -> Text -> Case_Sensitivity -> Boolean -> DB_Table - tokenize_to_rows self column pattern="." case_sensitivity=Case_Sensitivity.Sensitive at_least_one_row=False = + tokenize_to_rows self column pattern="." case_sensitivity:Case_Sensitivity=..Sensitive at_least_one_row:Boolean=False = _ = [column, pattern, case_sensitivity, at_least_one_row] Error.throw (Unsupported_Database_Operation.Error "DB_Table.tokenize_to_rows is not implemented yet for the Database backends.") @@ -2399,7 +2397,7 @@ type DB_Table @column Widget_Helpers.make_column_name_selector @pattern Widget.Text_Input parse_to_columns : Text | Integer -> Text | Regex -> Case_Sensitivity -> Boolean -> Problem_Behavior -> DB_Table - parse_to_columns self column pattern="." case_sensitivity=Case_Sensitivity.Sensitive parse_values=True on_problems=Report_Error = + parse_to_columns self column pattern="." case_sensitivity:Case_Sensitivity=..Sensitive parse_values=True on_problems:Problem_Behavior=..Report_Error = _ = [column, pattern, case_sensitivity, parse_values, on_problems] Error.throw (Unsupported_Database_Operation.Error "DB_Table.parse_to_columns is not implemented yet for the Database backends.") @@ -2454,7 +2452,7 @@ type DB_Table # => Table.new [["aaa", [1, 1, 2, 2]], ["bbb", [30, 31, 40, 41]]] @column Widget_Helpers.make_column_name_selector expand_to_rows : Text | Integer -> Boolean -> DB_Table ! Type_Error | No_Such_Column | Index_Out_Of_Bounds - expand_to_rows self column at_least_one_row=False = + expand_to_rows self column at_least_one_row:Boolean=False = _ = [column, at_least_one_row] Error.throw (Unsupported_Database_Operation.Error "DB_Table.expand_to_rows is currently not implemented for the Database backend. You may download the table to memory using `.read` to use this feature.") @@ -2512,7 +2510,7 @@ type DB_Table actually be converted into `[2, Nothing]` when casting to Integer type. @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) cast : Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type -> Value_Type -> Boolean -> Problem_Behavior -> DB_Table ! Illegal_Argument | Inexact_Type_Coercion | Conversion_Failure - cast self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type)=[0] value_type error_on_missing_columns=True on_problems=Problem_Behavior.Report_Warning = + cast self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type)=[0] value_type:Value_Type error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = selected = self.columns_helper.select_columns columns Case_Sensitivity.Default reorder=False error_on_missing_columns=error_on_missing_columns on_problems=on_problems error_on_empty=False . map self.make_column selected.fold self table-> column_to_cast-> new_column = column_to_cast.cast value_type on_problems @@ -2526,7 +2524,7 @@ type DB_Table This operation is currently not available in the Database backend. @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) auto_value_types : Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type -> Boolean -> Boolean -> Problem_Behavior -> DB_Table - auto_value_types self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type)=self.column_names shrink_types=False error_on_missing_columns=True on_problems=Problem_Behavior.Report_Warning = + auto_value_types self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type)=self.column_names shrink_types:Boolean=False error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = _ = [columns, shrink_types, error_on_missing_columns, on_problems] Error.throw (Unsupported_Database_Operation.Error "DB_Table.auto_value_types is not supported in the Database backends.") @@ -2544,7 +2542,7 @@ type DB_Table ? Blank values Blank values are `Nothing`, `""` and depending on setting `Number.nan`. filter_blank_rows : Blank_Selector -> Boolean -> DB_Table - filter_blank_rows self (when:Blank_Selector = Blank_Selector.All_Cells) treat_nans_as_blank=False = + filter_blank_rows self (when:Blank_Selector=..All_Cells) treat_nans_as_blank:Boolean=False = Table_Helpers.filter_blank_rows self when treat_nans_as_blank ## ALIAS count @@ -2798,7 +2796,7 @@ type DB_Table @path (Widget.Text_Input display=Display.Always) @format Widget_Helpers.write_table_selector write : Writable_File -> File_Format -> Existing_File_Behavior -> Match_Columns -> Problem_Behavior -> Nothing ! Column_Count_Mismatch | Illegal_Argument | File_Error - write self path:Writable_File format=Auto_Detect on_existing_file=Existing_File_Behavior.Backup match_columns=Match_Columns.By_Name on_problems=Report_Warning = + write self path:Writable_File format=Auto_Detect on_existing_file:Existing_File_Behavior=..Backup match_columns:Match_Columns=..By_Name on_problems:Problem_Behavior=..Report_Warning = # TODO This should ideally be done in a streaming manner, or at least respect the row limits. self.read.write path format on_existing_file match_columns on_problems @@ -2895,7 +2893,7 @@ type DB_Table @term (Widget_Helpers.make_column_ref_by_name_selector add_regex=True add_text=True add_named_pattern=True) @new_text (Widget_Helpers.make_column_ref_by_name_selector add_text=True) text_replace : Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> Text | DB_Column | Column_Ref | Expression | Regex -> Text | DB_Column | Column_Ref | Expression -> Case_Sensitivity -> Boolean -> DB_Column - text_replace self columns:(Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type) (term : Text | DB_Column | Column_Ref | Expression | Regex = "") (new_text : Text | DB_Column | Column_Ref | Expression = "") case_sensitivity=Case_Sensitivity.Sensitive only_first=False = + text_replace self columns:(Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type) (term : Text | DB_Column | Column_Ref | Expression | Regex = "") (new_text : Text | DB_Column | Column_Ref | Expression = "") case_sensitivity:Case_Sensitivity=..Sensitive only_first:Boolean=False = table_ref = Table_Ref.from self resolved_term = table_ref.resolve term resolved_new_text = table_ref.resolve new_text @@ -2971,7 +2969,7 @@ type DB_Table @order_by Widget_Helpers.make_order_by_selector @of Widget_Helpers.make_column_name_selector running : Statistic -> (Text | Integer) -> Text -> Vector (Text | Integer | Regex) | Text | Integer | Regex -> Vector (Text | Sort_Column) | Text -> Problem_Behavior -> Table - running self (statistic:Statistic=Statistic.Count) (of:(Text | Integer)=0) (as:Text='') (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (on_problems:Problem_Behavior=Problem_Behavior.Report_Warning) = + running self (statistic:Statistic=..Count) (of:(Text | Integer)=0) (as:Text='') (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (on_problems:Problem_Behavior=..Report_Warning) = _ = [statistic, of, as, group_by, order_by, on_problems] Error.throw (Unsupported_Database_Operation.Error "DB_Table.running is currently not implemented for the Database backend. You may download the table to memory using `.read` to use this feature.") diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Aggregate_Column.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Aggregate_Column.enso index ca8a52ead7e3..2ca7d38ccb1a 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Aggregate_Column.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Aggregate_Column.enso @@ -1,4 +1,5 @@ from Standard.Base import all +import Standard.Base.Errors.Common.Missing_Argument import project.Sort_Column.Sort_Column @@ -10,7 +11,7 @@ type Aggregate_Column Arguments: - column: the column (either name, expression or index) to group by. - as: name of new column. - Group_By (column:Text|Integer|Any) (as:Text="") # Any needed because of 6866 + Group_By (column:Text|Integer|Any=(Missing_Argument.throw "column")) (as:Text="") # Any needed because of 6866 ## Creates a new column with the row count of each group. If no rows, evaluates to 0. diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso index 6d784fb9e09d..875089cf8c86 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso @@ -1799,7 +1799,7 @@ type Column @type Widget_Helpers.parse_type_selector @format (make_format_chooser include_number=False) parse : Value_Type | Auto -> Text | Data_Formatter -> Problem_Behavior -> Column - parse self type=Auto format:(Text | Data_Formatter)="" on_problems=Report_Warning = + parse self type:(Value_Type | Auto)=Auto format:(Text | Data_Formatter)="" on_problems=Report_Warning = Value_Type.expect_text self <| formatter = case format of _ : Text -> if format == "" then Data_Formatter.Value else Data_Formatter.Value.with_format type format diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso index 250c832bdeb0..fa0ac81030bd 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso @@ -78,7 +78,7 @@ type Data_Formatter If set to `Ignore`, the operation proceeds without errors or warnings. @type Widget_Helpers.parse_type_selector parse : Text -> (Value_Type | Auto) -> Problem_Behavior -> Any - parse self text type=Auto on_problems=Problem_Behavior.Report_Warning = + parse self text type:(Value_Type | Auto)=Auto on_problems=Problem_Behavior.Report_Warning = parser = self.make_value_type_parser type Java_Problems.with_problem_aggregator on_problems java_problem_aggregator-> related_column_name = Nothing diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso index 583422ef9cf6..6595f77207be 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso @@ -188,7 +188,7 @@ resolve_aggregate table problem_builder aggregate_column:Aggregate_Column = Value_Type.expect_text col <| internal_column - result = case aggregate_column of + result = case aggregate_column:Aggregate_Column of Group_By c as -> Group_By (resolve c) as Count as -> Count as Count_Distinct c as ignore_nothing -> if c == [] then Count as else diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Exports.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Exports.enso index 0d2ca255440e..7a71aec82e30 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Exports.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Exports.enso @@ -1,5 +1,5 @@ from Standard.Base import all -import Standard.Base.Errors.Common.Missing_Required_Argument +import Standard.Base.Errors.Common.Missing_Argument import project.Internal.Storage import project.Value_Type.Bits @@ -22,18 +22,18 @@ make_bool_builder = BoolBuilder.new ## PRIVATE make_double_builder : Integer -> ProblemAggregator -> NumericBuilder -make_double_builder initial_size java_problem_aggregator=(Missing_Required_Argument.ensure_present "java_problem_aggregator") = +make_double_builder initial_size java_problem_aggregator=(Missing_Argument.ensure_present "java_problem_aggregator") = NumericBuilder.createDoubleBuilder initial_size java_problem_aggregator ## PRIVATE make_long_builder : Integer -> Bits -> ProblemAggregator -> NumericBuilder -make_long_builder initial_size bits java_problem_aggregator=(Missing_Required_Argument.ensure_present "java_problem_aggregator") = +make_long_builder initial_size bits java_problem_aggregator=(Missing_Argument.ensure_present "java_problem_aggregator") = integer_type = Storage.from_value_type_strict (Value_Type.Integer bits) NumericBuilder.createLongBuilder initial_size integer_type java_problem_aggregator ## PRIVATE make_biginteger_builder : Integer -> ProblemAggregator -> BigIntegerBuilder -make_biginteger_builder initial_size java_problem_aggregator=(Missing_Required_Argument.ensure_present "java_problem_aggregator") = +make_biginteger_builder initial_size java_problem_aggregator=(Missing_Argument.ensure_present "java_problem_aggregator") = BigIntegerBuilder.new initial_size java_problem_aggregator ## PRIVATE @@ -56,7 +56,7 @@ make_date_builder initial_size = DateBuilder.new initial_size ## PRIVATE make_inferred_builder : Integer -> ProblemAggregator -> InferredBuilder -make_inferred_builder initial_size java_problem_aggregator=(Missing_Required_Argument.ensure_present "java_problem_aggregator") = +make_inferred_builder initial_size java_problem_aggregator=(Missing_Argument.ensure_present "java_problem_aggregator") = InferredBuilder.new initial_size java_problem_aggregator ## PRIVATE diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso index 99a8b4976160..1045e9f52957 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso @@ -43,10 +43,7 @@ type Join_Condition_Resolver is_nothing column = case column of Nothing -> True _ -> False - conditions_vector = case conditions of - _ : Vector -> conditions - single_condition : Join_Condition -> [single_condition] - single_condition : Text -> [single_condition] + conditions_vector = Vector.unify_vector_or_element conditions . map on_problems=No_Wrap condition-> (condition:Join_Condition) handle_equals left_selector right_selector = left = resolve_left left_selector right = resolve_right right_selector @@ -59,7 +56,6 @@ type Join_Condition_Resolver Join_Condition.Equals left_selector right_selector -> right_resovled = if right_selector == "" then left_selector else right_selector handle_equals left_selector right_resovled - column_name : Text -> handle_equals column_name column_name Join_Condition.Equals_Ignore_Case left_selector right_selector locale -> left = resolve_left left_selector right_resovled = if right_selector == "" then left_selector else right_selector diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso index bd3f5019fd2c..437e8a6ca2d7 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso @@ -486,9 +486,7 @@ prepare_order_by internal_columns column_selectors problem_builder = containing the original selector and the selected column. resolve_order_by : Vector -> Text | Sort_Column | Vector (Text | Sort_Column) -> Problem_Builder -> Vector Column_Transform_Element resolve_order_by internal_columns column_selectors problem_builder = - resolve_selector selector = case selector of - name : Text -> resolve_selector (Sort_Column.Name name) - ix : Integer -> resolve_selector (Sort_Column.Index ix) + resolve_selector selector:Sort_Column = case selector of Sort_Column.Name name direction -> resolve_selector (Sort_Column.Select_By_Name name direction Case_Sensitivity.Sensitive) Sort_Column.Index ix _ -> @@ -499,10 +497,7 @@ resolve_order_by internal_columns column_selectors problem_builder = matches = match_columns name case_sensitivity internal_columns if matches.is_empty then problem_builder.report_missing_input_columns [name] matches.map c-> Column_Transform_Element.Value c selector - selectors_vec = case column_selectors of - _ : Vector -> column_selectors - _ -> [column_selectors] - selectors_vec.flat_map resolve_selector + Vector.unify_vector_or_element column_selectors . flat_map resolve_selector ## PRIVATE A helper method gathering the common logic for constructing expressions that diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso index e3c3dda70775..41b33e1cb5e4 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso @@ -42,6 +42,9 @@ type Table_Ref Column_Ref.Name name -> self.at name Column_Ref.Index index -> self.at index Expression.Value _ -> self.evaluate_expression value + _ : Function -> + col_ref = Panic.catch Any (value:Column_Ref) _->Nothing + if col_ref.is_nothing then value else self.resolve col_ref _ -> value ## PRIVATE @@ -49,10 +52,13 @@ type Table_Ref a constant column. resolve_as_column : Any -> Any ! No_Such_Column | Index_Out_Of_Bounds resolve_as_column self value = case value of - Column_Ref.Name name -> self.at name - Column_Ref.Index index -> self.at index - Expression.Value _ -> self.evaluate_expression value - _ -> self.underlying.make_constant_column value + Column_Ref.Name name -> self.at name + Column_Ref.Index index -> self.at index + Expression.Value _ -> self.evaluate_expression value + _ : Function -> + col_ref = Panic.catch Any (value:Column_Ref) _->Nothing + if col_ref.is_nothing then self.underlying.make_constant_column value else self.resolve_as_column col_ref + _ -> self.underlying.make_constant_column value ## PRIVATE Transforms a condition, changing any Column_Ref instances into Column instances resolved in this table. diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Widget_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Widget_Helpers.enso index cbf2c03b6719..0e6b2b5356d9 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Widget_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Widget_Helpers.enso @@ -24,41 +24,40 @@ make_aggregate_column_selector table display=Display.Always = col_names_selector = make_column_name_selector table display=Display.Always add_expression=True column_widget = ["column", col_names_selector] - fqn = Meta.get_qualified_type_name Aggregate_Column - count = Option "Count" fqn+".Count" + count = Option "Count" "..Count" ## Currently can't support nested vector editors so using single picker col_list_selector = make_column_name_multi_selector table display=Display.Always - count_distinct = Option "Count Distinct" fqn+".Count_Distinct" [["columns", col_list_selector]] + count_distinct = Option "Count Distinct" "..Count_Distinct" [["columns", col_list_selector]] ## Currently can't support nested vector editors so using single order by picker order_by_selector = make_order_by_selector table Display.When_Modified name_only=True - first = Option "First" fqn+".First" [column_widget, ["order_by" , order_by_selector]] - last = Option "Last" fqn+".Last" [column_widget, ["order_by" , order_by_selector]] + first = Option "First" "..First" [column_widget, ["order_by" , order_by_selector]] + last = Option "Last" "..Last" [column_widget, ["order_by" , order_by_selector]] - count_not_nothing = Option "Count Not Nothing" fqn+".Count_Not_Nothing" [column_widget] - count_nothing = Option "Count Nothing" fqn+".Count_Nothing" [column_widget] + count_not_nothing = Option "Count Not Nothing" "..Count_Not_Nothing" [column_widget] + count_nothing = Option "Count Nothing" "..Count_Nothing" [column_widget] ## Should be a list of Text columns only - count_not_empty = Option "Count Not Empty" fqn+".Count_Not_Empty" [column_widget] - count_empty = Option "Count Empty" fqn+".Count_Empty" [column_widget] - concatenate = Option "Concatenate" fqn+".Concatenate" [column_widget] - shortest = Option "Shortest" fqn+".Shortest" [column_widget] - longest = Option "Longest" fqn+".Longest" [column_widget] + count_not_empty = Option "Count Not Empty" "..Count_Not_Empty" [column_widget] + count_empty = Option "Count Empty" "..Count_Empty" [column_widget] + concatenate = Option "Concatenate" "..Concatenate" [column_widget] + shortest = Option "Shortest" "..Shortest" [column_widget] + longest = Option "Longest" "..Longest" [column_widget] ## Should be a list of Numeric columns only - sum = Option "Sum" fqn+".Sum" [column_widget] - average = Option "Average" fqn+".Average" [column_widget] - median = Option "Median" fqn+".Median" [column_widget] - percentile = Option "Percentile" fqn+".Percentile" [column_widget] - mode = Option "Mode" fqn+".Mode" [column_widget] - standard_deviation = Option "Standard Deviation" fqn+".Standard_Deviation" [column_widget] + sum = Option "Sum" "..Sum" [column_widget] + average = Option "Average" "..Average" [column_widget] + median = Option "Median" "..Median" [column_widget] + percentile = Option "Percentile" "..Percentile" [column_widget] + mode = Option "Mode" "..Mode" [column_widget] + standard_deviation = Option "Standard Deviation" "..Standard_Deviation" [column_widget] # Should be a list of comparable columns only - maximum = Option "Maximum" fqn+".Maximum" [column_widget] - minimum = Option "Minimum" fqn+".Minimum" [column_widget] + maximum = Option "Maximum" "..Maximum" [column_widget] + minimum = Option "Minimum" "..Minimum" [column_widget] - Single_Choice display=display values=[count, sum, average, count_distinct, first, last, count_not_nothing, count_nothing, count_not_empty, count_empty, concatenate, shortest, longest, median, percentile, mode, standard_deviation, maximum, minimum] + Single_Choice display=display values=[count, sum, average, maximum, minimum, count_distinct, first, last, count_not_nothing, count_nothing, count_not_empty, count_empty, concatenate, shortest, longest, median, percentile, mode, standard_deviation] ## PRIVATE Make an Aggregate_Column list editor @@ -66,7 +65,7 @@ make_aggregate_column_vector_selector : Table -> Display -> Widget make_aggregate_column_vector_selector table display=Display.Always = item_editor = make_aggregate_column_selector table display=Display.Always # TODO this is a workaround for a dropdown issue - Vector_Editor item_editor=item_editor item_default="(Aggregate_Column.Count)" display=display + Vector_Editor item_editor=item_editor item_default="..Count" display=display ## PRIVATE Make a column name selector. @@ -95,27 +94,18 @@ make_column_name_multi_selector table display:Display=Display.Always add_regex:B ## PRIVATE Make a column reference by name selector. -make_column_ref_by_name_selector : Table -> Display -> Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Widget -make_column_ref_by_name_selector table display:Display=Display.Always add_text:Boolean=False add_regex:Boolean=False add_number:Boolean=False add_boolean:Boolean=False add_named_pattern:Boolean=False = +make_column_ref_by_name_selector : Table -> Display -> Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Widget +make_column_ref_by_name_selector table display:Display=..Always add_text:Boolean=False add_regex:Boolean=False add_number:Boolean=False add_boolean:Boolean=False add_named_pattern:Boolean=False = text = if add_text then [Option "" "''"] else [] regex = if add_regex then [Option "" "(regex '')"] else [] number = if add_number then [Option "" "0"] else [] boolean = if add_boolean then [Option "" "True"] else [] named_pattern = if add_named_pattern.not then [] else - Vector.build builder-> - builder.append (Option "" "Named_Pattern.Leading_Whitespace") - builder.append (Option "" "Named_Pattern.Trailing_Whitespace") - builder.append (Option "" "Named_Pattern.All_Whitespace") - builder.append (Option "" "Named_Pattern.Leading_Numbers") - builder.append (Option "" "Named_Pattern.Trailing_Numbers") - builder.append (Option "" "Named_Pattern.Non_ASCII") - builder.append (Option "" "Named_Pattern.Tabs") - builder.append (Option "" "Named_Pattern.Letters") - builder.append (Option "" "Named_Pattern.Numbers") - builder.append (Option "" "Named_Pattern.Punctuation") - builder.append (Option "" "Named_Pattern.Symbols") + patterns = ["Leading_Whitespace", "Trailing_Whitespace", "All_Whitespace", "Leading_Numbers", "Trailing_Numbers", "Non_ASCII", "Tabs", "Letters", "Numbers", "Punctuation", "Symbols"] + ## Can't use auto-scoping as Named_Patterns are materialised into Regex. + patterns.map p-> Option "<"+p+">" "Named_Pattern."+p expression = if table.is_nothing then [] else [Option "" "(expr '["+table.column_names.first+"]')"] - col_names = if table.is_nothing then [] else table.column_names.map (name -> Option name "(Column_Ref.Name "+name.pretty+")") + col_names = if table.is_nothing then [] else table.column_names.map (name -> Option name "(..Name "+name.pretty+")") values = text + regex + number + boolean + named_pattern + expression + col_names Single_Choice values=values display=display @@ -136,37 +126,35 @@ make_filter_condition_selector table display=Display.Always = with_text = make_column_ref_by_name_selector table add_text=True options = Vector.build builder-> - fqn = Meta.get_qualified_type_name Filter_Condition - builder.append (Option "Equals" fqn+".Equal" [["to", with_all_types]]) - builder.append (Option "Not Equals" fqn+".Not_Equal" [["to", with_all_types]]) - builder.append (Option "Less Than" fqn+".Less" [["than", with_number_text]]) - builder.append (Option "Less Than Or Equal" fqn+".Equal_Or_Less" [["than", with_number_text]]) - builder.append (Option "Greater Than" fqn+".Greater" [["than", with_number_text]]) - builder.append (Option "Greater Than Or Equal" fqn+".Equal_Or_Greater" [["than", with_number_text]]) - builder.append (Option "Between" fqn+".Between" [["lower", with_number_text], ["upper", with_number_text]]) - builder.append (Option "Equals Ignore Case" fqn+".Equal_Ignore_Case" [["to", with_text]]) - builder.append (Option "Starts With" fqn+".Starts_With" [["prefix", with_text]]) - builder.append (Option "Ends With" fqn+".Ends_With" [["suffix", with_text]]) - builder.append (Option "Contains" fqn+".Contains" [["substring", with_text]]) - builder.append (Option "Is Nothing" fqn+".Is_Nothing") - builder.append (Option "Is Not Nothing" fqn+".Not_Nothing") - builder.append (Option "Is Finite" fqn+".Is_Finite") - builder.append (Option "Is Infinite" fqn+".Is_Infinite") - builder.append (Option "Is NaN" fqn+".Is_Nan") - builder.append (Option "Is True" fqn+".Is_True") - builder.append (Option "Is False" fqn+".Is_False") - builder.append (Option "Is Empty" fqn+".Is_Empty") - builder.append (Option "Is Not Empty" fqn+".Not_Empty") - builder.append (Option "Like" fqn+".Like" [["pattern", with_text]]) - builder.append (Option "Is In" fqn+".Is_In") + builder.append (Option "Equals" "..Equal" [["to", with_all_types]]) + builder.append (Option "Not Equals" "..Not_Equal" [["to", with_all_types]]) + builder.append (Option "Less Than" "..Less" [["than", with_number_text]]) + builder.append (Option "Less Than Or Equal" "..Equal_Or_Less" [["than", with_number_text]]) + builder.append (Option "Greater Than" "..Greater" [["than", with_number_text]]) + builder.append (Option "Greater Than Or Equal" "..Equal_Or_Greater" [["than", with_number_text]]) + builder.append (Option "Between" "..Between" [["lower", with_number_text], ["upper", with_number_text]]) + builder.append (Option "Equals Ignore Case" "..Equal_Ignore_Case" [["to", with_text]]) + builder.append (Option "Starts With" "..Starts_With" [["prefix", with_text]]) + builder.append (Option "Ends With" "..Ends_With" [["suffix", with_text]]) + builder.append (Option "Contains" "..Contains" [["substring", with_text]]) + builder.append (Option "Is Nothing" "..Is_Nothing") + builder.append (Option "Is Not Nothing" "..Not_Nothing") + builder.append (Option "Is Finite" "..Is_Finite") + builder.append (Option "Is Infinite" "..Is_Infinite") + builder.append (Option "Is NaN" "..Is_Nan") + builder.append (Option "Is True" "..Is_True") + builder.append (Option "Is False" "..Is_False") + builder.append (Option "Is Empty" "..Is_Empty") + builder.append (Option "Is Not Empty" "..Not_Empty") + builder.append (Option "Like" "..Like" [["pattern", with_text]]) + builder.append (Option "Is In" "..Is_In") Single_Choice options display=display ## PRIVATE Make a join kind selector - Needed to override display. make_join_kind_selector : Display -> Widget make_join_kind_selector display=Display.Always = - fqn = Meta.get_qualified_type_name Join_Kind - options = ["Inner", "Left_Outer", "Right_Outer", "Full", "Left_Exclusive", "Right_Exclusive"].map n-> Option n fqn+"."+n + options = ["Inner", "Left_Outer", "Right_Outer", "Full", "Left_Exclusive", "Right_Exclusive"].map n-> Option n ".."+n Single_Choice display=display values=options ## PRIVATE @@ -178,27 +166,25 @@ make_join_condition_selector table display=Display.Always cache=Nothing = right_selector = if right.is_nothing then Text_Input else make_column_name_selector right display=Display.Always - fqn = Meta.get_qualified_type_name Join_Condition - equals = Option "Equals" fqn+".Equals" [["left", self_selector], ["right", right_selector]] - equals_ci = Option "Equals (Ignore Case)" fqn+".Equals_Ignore_Case" [["left", self_selector], ["right", right_selector]] - between = Option "Between" fqn+".Between" [["left", self_selector], ["right_lower", right_selector], ["right_upper", right_selector]] + equals = Option "Equals" "..Equals" [["left", self_selector], ["right", right_selector]] + equals_ci = Option "Equals (Ignore Case)" "..Equals_Ignore_Case" [["left", self_selector], ["right", right_selector]] + between = Option "Between" "..Between" [["left", self_selector], ["right_lower", right_selector], ["right_upper", right_selector]] names=[equals, equals_ci, between] item_editor = Single_Choice display=display values=names - Vector_Editor item_editor=item_editor item_default="(Join_Condition.Equals "+table.column_names.first.pretty+")" display=display + Vector_Editor item_editor=item_editor item_default="(..Equals "+table.column_names.first.pretty+")" display=display ## PRIVATE Make a column name selector. make_order_by_selector : Table -> Display -> Boolean -> Widget make_order_by_selector table display=Display.Always name_only:Boolean=False = - fqn = Meta.get_qualified_type_name Sort_Column - values = if name_only then table.column_names.map n-> Option n "(Sort_Column.Name "+n.pretty+")" else - name = Option "Name" fqn+".Name" [["name", make_column_name_selector table display=Display.Always]] - index = Option "Index" fqn+".Index" [["index", Numeric_Input display=Display.Always minimum=0 maximum=table.column_count-1]] + values = if name_only then table.column_names.map n-> Option n "(..Name "+n.pretty+")" else + name = Option "Name" "..Name" [["name", make_column_name_selector table display=Display.Always]] + index = Option "Index" "..Index" [["index", Numeric_Input display=Display.Always minimum=0 maximum=table.column_count-1]] [name, index] item_editor = Single_Choice display=Display.Always values=values - Vector_Editor item_editor=item_editor item_default="(Sort_Column.Name "+table.column_names.first.pretty+")" display=display + Vector_Editor item_editor=item_editor item_default="(..Name "+table.column_names.first.pretty+")" display=display ## PRIVATE Make a column rename name selector. @@ -220,8 +206,7 @@ parse_type_selector include_auto=True = prefix = if include_auto then ['Auto'] else [] names = prefix + valid_parse_targets - fqn = Meta.get_qualified_type_name Value_Type - choice = names.map n-> if n=='Auto' then (Meta.get_qualified_type_name Auto) else fqn+'.'+n + choice = names.map n-> if n=='Auto' then (Meta.get_qualified_type_name Auto) else '..'+n options = names.zip choice . map pair-> Option pair.first pair.second Single_Choice display=Display.Always values=options diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Join_Condition.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Join_Condition.enso index 80da948689fe..245bfb0a6fb7 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Join_Condition.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Join_Condition.enso @@ -1,4 +1,5 @@ from Standard.Base import all +import Standard.Base.Errors.Common.Missing_Argument type Join_Condition ## Correlates rows from the two tables if the `left` element is equal to the @@ -9,7 +10,7 @@ type Join_Condition Arguments: - left: A name or index of a column in the left table. - right: A name or index of a column in the right table. - Equals (left : Text | Integer) (right : Text | Integer = "") + Equals (left : Text | Integer = Missing_Argument.throw "left") (right : Text | Integer = "") ## Correlates rows from the two tables if the `left` element is equal to the `right` element, ignoring case. This is only supported for text columns. @@ -24,7 +25,7 @@ type Join_Condition - right: A name or index of a column in the right table. - locale: The locale to use for case insensitive comparisons. @locale Locale.default_widget - Equals_Ignore_Case (left : Text | Integer) (right : Text | Integer = "") (locale : Locale = Locale.default) + Equals_Ignore_Case (left : Text | Integer = Missing_Argument.throw "left") (right : Text | Integer = "") (locale : Locale = Locale.default) ## Correlates rows from the two tables if the `left` element fits between the `right_lower` and `right_upper` elements. The comparison is inclusive @@ -39,4 +40,7 @@ type Join_Condition the lower bound for the check. - right_upper: A name or index of a column in the right table, used as the upper bound for the check. - Between (left : Text | Integer) (right_lower : Text | Integer = "") (right_upper : Text | Integer = "") + Between (left : Text | Integer = Missing_Argument.throw "left") (right_lower : Text | Integer = "") (right_upper : Text | Integer = "") + +## PRIVATE +Join_Condition.from (that:Text) = Join_Condition.Equals that that diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Simple_Expression.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Simple_Expression.enso index a060478ee89e..171acb3dea9f 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Simple_Expression.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Simple_Expression.enso @@ -1,4 +1,5 @@ from Standard.Base import all +import Standard.Base.Errors.Common.Missing_Argument import Standard.Base.Errors.Deprecated.Deprecated import Standard.Base.Metadata.Display import Standard.Base.Metadata.Widget @@ -15,7 +16,7 @@ from project.Internal.Filter_Condition_Helpers import make_filter_column ## Defines a simple expression based off an input column and an operation to perform. type Simple_Expression ## A simple expression based off an input column and an operation to perform. - From (input : Column_Ref|Expression|Any = (Column_Ref.Index 0)) (operation : Simple_Calculation = Simple_Calculation.Copy) + From (input : Column_Ref|Expression|Any = (..Index 0)) (operation : Simple_Calculation = ..Copy) ## PRIVATE Interprets the `Simple_Expression` as operation on columns of a provided @@ -74,35 +75,33 @@ type Simple_Expression filter_cond = Widget_Helpers.make_filter_condition_selector table options = Vector.build builder-> - fqn = Meta.get_qualified_type_name Simple_Calculation - builder.append (Option "copy" fqn+".Copy") - builder.append (Option "add" fqn+".Add" [["rhs", with_number_text]]) - builder.append (Option "subtract" fqn+".Subtract" [["rhs", with_number]]) - builder.append (Option "multiply" fqn+".Multiply" [["rhs", with_number]]) - builder.append (Option "divide" fqn+".Divide" [["rhs", with_number]]) - builder.append (Option "mod" fqn+".Mod" [["rhs", with_number]]) - builder.append (Option "power" fqn+".Power" [["rhs", with_number]]) - builder.append (Option "round" fqn+".Round") - builder.append (Option "ceil" fqn+".Ceil") - builder.append (Option "floor" fqn+".Floor") - builder.append (Option "truncate" fqn+".Truncate") - builder.append (Option "min" fqn+".Min" [["rhs", with_number_text]]) - builder.append (Option "max" fqn+".Max" [["rhs", with_number_text]]) - builder.append (Option "date add" fqn+".Date_Add" [["length", with_number]]) - builder.append (Option "date part" fqn+".Date_Part") - builder.append (Option "date diff" fqn+".Date_Diff" [["end", col_names]]) - builder.append (Option "not" fqn+".Not") - builder.append (Option "and" fqn+".And" [["rhs", with_boolean]]) - builder.append (Option "or" fqn+".Or" [["rhs", with_boolean]]) - builder.append (Option "if" fqn+".If" [["condition", filter_cond], ["true_value", with_all_types], ["false_value", with_all_types]]) - builder.append (Option "trim" fqn+".Trim" [["what", with_text]]) - builder.append (Option "text_left" fqn+".Text_Left" [["length", with_number]]) - builder.append (Option "text_right" fqn+".Text_Right" [["length", with_number]]) - builder.append (Option "text_length" fqn+".Text_Length") - builder.append (Option "format" fqn+".Format" [["format", make_format_chooser include_number=True]]) - - fqn_column = Meta.get_qualified_type_name Simple_Expression - derived = Option "" fqn_column+".From" [["input", with_all_types], ["operation", Single_Choice options]] + builder.append (Option "copy" "..Copy") + builder.append (Option "add" "..Add" [["rhs", with_number_text]]) + builder.append (Option "subtract" "..Subtract" [["rhs", with_number]]) + builder.append (Option "multiply" "..Multiply" [["rhs", with_number]]) + builder.append (Option "divide" "..Divide" [["rhs", with_number]]) + builder.append (Option "mod" "..Mod" [["rhs", with_number]]) + builder.append (Option "power" "..Power" [["rhs", with_number]]) + builder.append (Option "round" "..Round") + builder.append (Option "ceil" "..Ceil") + builder.append (Option "floor" "..Floor") + builder.append (Option "truncate" "..Truncate") + builder.append (Option "min" "..Min" [["rhs", with_number_text]]) + builder.append (Option "max" "..Max" [["rhs", with_number_text]]) + builder.append (Option "date add" "..Date_Add" [["length", with_number]]) + builder.append (Option "date part" "..Date_Part") + builder.append (Option "date diff" "..Date_Diff" [["end", col_names]]) + builder.append (Option "not" "..Not") + builder.append (Option "and" "..And" [["rhs", with_boolean]]) + builder.append (Option "or" "..Or" [["rhs", with_boolean]]) + builder.append (Option "if" "..If" [["condition", filter_cond], ["true_value", with_all_types], ["false_value", with_all_types]]) + builder.append (Option "trim" "..Trim" [["what", with_text]]) + builder.append (Option "text_left" "..Text_Left" [["length", with_number]]) + builder.append (Option "text_right" "..Text_Right" [["length", with_number]]) + builder.append (Option "text_length" "..Text_Length") + builder.append (Option "format" "..Format" [["format", make_format_chooser include_number=True]]) + + derived = Option "" "..From" [["input", with_all_types], ["operation", Single_Choice options]] Single_Choice [text, number, boolean, expression, derived] display=display @@ -112,7 +111,7 @@ type Simple_Calculation Copy ## Add two values/columns. - Add (rhs : Column_Ref|Expression|Number|Text) + Add (rhs : Column_Ref|Expression|Number|Text = Missing_Argument.throw "rhs") ## Subtract two values/columns. Subtract (rhs : Column_Ref|Expression|Number = 0) @@ -144,10 +143,10 @@ type Simple_Calculation Truncate ## Returns the minimum value of two columns. - Min (rhs : Column_Ref|Expression|Any) + Min (rhs : Column_Ref|Expression|Any = Missing_Argument.throw "rhs") ## Returns the maximum value of two columns. - Max (rhs : Column_Ref|Expression|Any) + Max (rhs : Column_Ref|Expression|Any = Missing_Argument.throw "rhs") ## Adds a period to a date/time column. Date_Add (length : Column_Ref|Expression|Integer = 1) (period : Date_Period|Time_Period = Date_Period.Day) @@ -156,7 +155,7 @@ type Simple_Calculation Date_Part (period : Date_Period|Time_Period = Date_Period.Day) ## Returns the difference between two date/time columns. - Date_Diff (end : Column_Ref|Expression|Date_Time|Date|Time_Of_Day) (period:Date_Period|Time_Period = Date_Period.Day) + Date_Diff (end : Column_Ref|Expression|Date_Time|Date|Time_Of_Day = Missing_Argument.throw "end") (period:Date_Period|Time_Period = Date_Period.Day) ## Negate a boolean column. Not @@ -170,11 +169,11 @@ type Simple_Calculation ## If input meets a condition return true value, otherwise false value. The `true_value` and `false_value` can be either a constant or a column. - If (condition:Filter_Condition=(Filter_Condition.Equal True)) (true_value:Column_Ref|Expression|Any = True) (false_value:Column_Ref|Expression|Any = False) + If (condition:Filter_Condition=(..Equal True)) (true_value:Column_Ref|Expression|Any = True) (false_value:Column_Ref|Expression|Any = False) ## Removes the specified characters, by default any whitespace, from the start, the end, or both ends of the input. - Trim (where:Location = Location.Both) (what:Column_Ref|Expression|Text = "") + Trim (where:Location = ..Both) (what:Column_Ref|Expression|Text = "") ## Takes the first characters from the input column. Text_Left (length : Column_Ref|Expression|Integer = 1) diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Sort_Column.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Sort_Column.enso index 7d9078f02403..26b34055a3b9 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Sort_Column.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Sort_Column.enso @@ -1,14 +1,15 @@ from Standard.Base import all +import Standard.Base.Errors.Common.Missing_Argument type Sort_Column ## A column to sort by, selected by its name. For case insensitive column name matching, use the `Select_By_Name` selector. - Name name:Text direction:Sort_Direction=Sort_Direction.Ascending + Name (name:Text=(Missing_Argument.throw "name")) direction:Sort_Direction=..Ascending ## A column to sort by, selected by its index. - Index index:Integer=0 direction:Sort_Direction=Sort_Direction.Ascending + Index index:Integer=0 direction:Sort_Direction=..Ascending ## A selector allowing to match columns by their name. @@ -17,4 +18,10 @@ type Sort_Column matched columns will be placed in the ORDER BY clause at the position of this selector. Their relative order between each other will be the same as in the table. - Select_By_Name name:Text|Regex direction:Sort_Direction=Sort_Direction.Ascending case_sensitivity:Case_Sensitivity=Case_Sensitivity.Insensitive + Select_By_Name (name:Text|Regex=(Missing_Argument.throw "name")) direction:Sort_Direction=..Ascending case_sensitivity:Case_Sensitivity=..Insensitive + +## PRIVATE +Sort_Column.from (that:Text) = Sort_Column.Name that + +## PRIVATE +Sort_Column.from (that:Integer) = Sort_Column.Index that diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso index 7be7aea89f38..da0d590e0152 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso @@ -187,7 +187,7 @@ type Table example_display = Examples.inventory_table.display display : Integer -> Boolean -> Text - display self show_rows=10 format_terminal=False = + display self show_rows:Integer=10 format_terminal:Boolean=False = Display_Helpers.display_table self add_row_index=True max_rows_to_show=show_rows all_rows_count=self.row_count format_terminal=format_terminal ## PRIVATE @@ -300,7 +300,7 @@ type Table @selector Widget_Helpers.make_column_name_selector @index (t-> Widget.Numeric_Input minimum=0 maximum=t.row_count-1) get_value : Text | Integer -> Integer -> Any -> Any - get_value self selector=0 index=0 ~if_missing=Nothing = + get_value self selector:Integer=0 index:Integer=0 ~if_missing=Nothing = col = self.get selector if_missing=Nothing if Nothing == col then if_missing else col.get index if_missing @@ -393,7 +393,7 @@ type Table table.select_columns [..By_Type ..Integer] @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) select_columns : Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> Boolean -> Case_Sensitivity -> Boolean -> Problem_Behavior -> Table ! No_Output_Columns | Missing_Input_Columns - select_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (reorder:Boolean=False) (case_sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=Report_Warning) = + select_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (reorder:Boolean=False) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=..Report_Warning) = new_columns = self.columns_helper.select_columns columns case_sensitivity reorder error_on_missing_columns on_problems Table.new new_columns @@ -473,7 +473,7 @@ type Table table.remove_columns [..By_Type ..Integer] @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) remove_columns : Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> Case_Sensitivity -> Boolean -> Problem_Behavior -> Table ! No_Output_Columns | Missing_Input_Columns - remove_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (case_sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=Report_Warning) = + remove_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=..Report_Warning) = new_columns = self.columns_helper.remove_columns columns case_sensitivity error_on_missing_columns=error_on_missing_columns on_problems=on_problems Table.new new_columns @@ -518,7 +518,7 @@ type Table table.select_blank_columns select_blank_columns : Blank_Selector -> Boolean -> Table ! No_Output_Columns - select_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells) (treat_nans_as_blank : Boolean = False) = + select_blank_columns self (when : Blank_Selector = Blank_Selector.All_Cells) (treat_nans_as_blank : Boolean = False) = new_columns = self.columns_helper.select_blank_columns_helper when treat_nans_as_blank Table.new new_columns @@ -544,7 +544,7 @@ type Table table.remove_blank_columns remove_blank_columns : Blank_Selector -> Boolean -> Table ! No_Output_Columns - remove_blank_columns self (when:Blank_Selector = Blank_Selector.All_Cells) (treat_nans_as_blank : Boolean = False) = + remove_blank_columns self (when : Blank_Selector = Blank_Selector.All_Cells) (treat_nans_as_blank : Boolean = False) = new_columns = self.columns_helper.select_blank_columns_helper when treat_nans_as_blank invert_selection=True Table.new new_columns @@ -599,7 +599,7 @@ type Table table.reorder_columns [0] position=Position.After_Other_Columns @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) reorder_columns : Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> Position -> Case_Sensitivity -> Boolean -> Problem_Behavior -> Table ! Missing_Input_Columns - reorder_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (position:Position=Position.Before_Other_Columns) (case_sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=Report_Warning) = + reorder_columns self (columns : (Vector | Text | Integer | Regex | By_Type) = [self.columns.first.name]) (position:Position=..Before_Other_Columns) (case_sensitivity:Case_Sensitivity=..Default) (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=..Report_Warning) = new_columns = self.columns_helper.reorder_columns columns position case_sensitivity error_on_missing_columns on_problems Table.new new_columns @@ -628,7 +628,7 @@ type Table table.reorder_columns Sort_Direction.Descending sort_columns : Sort_Direction -> Text_Ordering -> Table - sort_columns self order=Sort_Direction.Ascending text_ordering=Text_Ordering.Default = + sort_columns self order:Sort_Direction=Sort_Direction.Ascending text_ordering:Text_Ordering=Text_Ordering.Default = new_columns = Table_Helpers.sort_columns self.columns order text_ordering Table.new new_columns @@ -700,7 +700,7 @@ type Table table.rename_columns (Map.from_vector [["name=(.*)".to_regex, "key:$1"]]) @column_map Widget_Helpers.make_rename_name_vector_selector rename_columns : Map (Text | Integer | Regex) Text | Vector Text | Vector Vector -> Case_Sensitivity -> Boolean -> Problem_Behavior -> Table ! Missing_Input_Columns | Ambiguous_Column_Rename | Too_Many_Column_Names_Provided | Invalid_Column_Names | Duplicate_Output_Column_Names - rename_columns self (column_map:(Table | Map | Vector)=["Column"]) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=Report_Warning) = case column_map of + rename_columns self (column_map:(Table | Map | Vector)=["Column"]) (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=..Report_Warning) = case column_map of _ : Table -> resolved = Table_Helpers.read_name_map_from_table column_map self.rename_columns resolved case_sensitivity error_on_missing_columns on_problems @@ -729,7 +729,7 @@ type Table table.use_first_row_as_names use_first_row_as_names : Problem_Behavior -> Table - use_first_row_as_names self (on_problems=Report_Warning) = + use_first_row_as_names self (on_problems:Problem_Behavior=..Report_Warning) = new_names = self.first_row.to_vector.map c-> if c.is_nothing then Nothing else c.to_text unique = self.column_naming_helper.create_unique_name_strategy @@ -808,7 +808,7 @@ type Table @group_by Widget_Helpers.make_column_name_multi_selector @columns Widget_Helpers.make_aggregate_column_vector_selector aggregate : Vector (Integer | Text | Regex | Aggregate_Column) | Text | Integer | Regex -> Vector Aggregate_Column -> Boolean -> Problem_Behavior -> Table ! No_Output_Columns | Invalid_Aggregate_Column | Invalid_Column_Names | Duplicate_Output_Column_Names | Floating_Point_Equality | Invalid_Aggregation | Unquoted_Delimiter | Additional_Warnings - aggregate self group_by=[] columns=[] (error_on_missing_columns=False) (on_problems=Report_Warning) = + aggregate self group_by=[] columns=[] (error_on_missing_columns:Boolean=False) (on_problems:Problem_Behavior=..Report_Warning) = normalized_group_by = Vector.unify_vector_or_element group_by if normalized_group_by.is_empty && columns.is_empty then Error.throw (No_Output_Columns.Error "At least one column must be specified.") else validated = Aggregate_Column_Helper.prepare_aggregate_columns self.column_naming_helper normalized_group_by columns self error_on_missing_columns=error_on_missing_columns @@ -888,7 +888,7 @@ type Table table.order_by [(Sort_Column.Select_By_Name "a.*".to_regex case_sensitivity=Case_Sensitivity.Insensitive)] @columns Widget_Helpers.make_order_by_selector order_by : Vector (Text | Sort_Column) | Text -> Text_Ordering -> Boolean -> Problem_Behavior -> Table ! Incomparable_Values | No_Input_Columns_Selected | Missing_Input_Columns - order_by self (columns = [self.columns.first.name]) text_ordering=Text_Ordering.Default error_on_missing_columns=True on_problems=Problem_Behavior.Report_Warning = + order_by self (columns = [self.columns.first.name]) text_ordering:Text_Ordering=..Default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns types_to_always_throw=[No_Input_Columns_Selected] columns_for_ordering = Table_Helpers.prepare_order_by self.columns columns problem_builder problem_builder.attach_problems_before on_problems <| @@ -948,7 +948,7 @@ type Table setting. @columns Widget_Helpers.make_column_name_multi_selector distinct : Vector (Integer | Text | Regex) | Text | Integer | Regex -> Case_Sensitivity -> Boolean -> Problem_Behavior -> Table ! No_Output_Columns | Missing_Input_Columns | No_Input_Columns_Selected | Floating_Point_Equality - distinct self (columns = self.column_names) case_sensitivity=Case_Sensitivity.Default error_on_missing_columns=True on_problems=Report_Warning = + distinct self (columns = self.column_names) case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = key_columns = self.columns_helper.select_columns columns Case_Sensitivity.Default reorder=True error_on_missing_columns=error_on_missing_columns on_problems=on_problems . catch No_Output_Columns _-> Error.throw No_Input_Columns_Selected java_columns = key_columns.map c->c.java_column @@ -1052,7 +1052,7 @@ type Table @type Widget_Helpers.parse_type_selector @format (make_format_chooser include_number=False) parse : Vector (Text | Integer | Regex) | Text | Integer | Regex -> Value_Type | Auto -> Text | Data_Formatter -> Boolean -> Problem_Behavior -> Table - parse self columns=(self.columns . filter (c-> c.value_type.is_text) . map .name) type=Auto format:(Text | Data_Formatter)='' error_on_missing_columns=True on_problems=Report_Warning = + parse self columns=(self.columns . filter (c-> c.value_type.is_text) . map .name) type:(Value_Type | Auto)=Auto format:(Text | Data_Formatter)='' error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = formatter = case format of _ : Text -> if format.is_empty then Data_Formatter.Value else Data_Formatter.Value.with_format type format _ : Data_Formatter -> format @@ -1157,7 +1157,7 @@ type Table @locale Locale.default_widget @format (make_format_chooser include_number=True) format : Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type -> Text | Date_Time_Formatter | Column -> Locale -> Boolean -> Problem_Behavior -> Table ! Date_Time_Format_Parse_Error | Illegal_Argument - format self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type) format:(Text | Date_Time_Formatter | Column)="" locale=Locale.default error_on_missing_columns=True on_problems=Report_Warning = + format self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type) format:(Text | Date_Time_Formatter | Column)="" locale:Locale=Locale.default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = select_problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns selected_columns = self.columns_helper.select_columns_helper columns Case_Sensitivity.Default True select_problem_builder select_problem_builder.attach_problems_before on_problems <| @@ -1231,7 +1231,7 @@ type Table actually be converted into `[2, Nothing]` when casting to Integer type. @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) cast : Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type -> Value_Type -> Boolean -> Problem_Behavior -> Table ! Illegal_Argument | Inexact_Type_Coercion | Conversion_Failure - cast self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type)=[0] value_type error_on_missing_columns=True on_problems=Problem_Behavior.Report_Warning = + cast self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type)=[0] value_type:Value_Type error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = selected = self.columns_helper.select_columns columns Case_Sensitivity.Default reorder=False error_on_missing_columns=error_on_missing_columns on_problems=on_problems error_on_empty=False selected.fold self table-> column_to_cast-> new_column = column_to_cast.cast value_type on_problems @@ -1278,7 +1278,7 @@ type Table unchanged. @columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True) auto_value_types : Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type -> Boolean -> Boolean -> Problem_Behavior -> Table - auto_value_types self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type)=self.column_names shrink_types=False error_on_missing_columns=True on_problems=Problem_Behavior.Report_Warning = + auto_value_types self columns:(Vector (Text | Integer | Regex | By_Type) | Text | Integer | Regex | By_Type)=self.column_names shrink_types:Boolean=False error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning = selected = self.columns_helper.select_columns columns Case_Sensitivity.Default reorder=False error_on_missing_columns=error_on_missing_columns on_problems=on_problems error_on_empty=False selected.fold self table-> column_to_cast-> new_column = column_to_cast.auto_value_type shrink_types @@ -1305,7 +1305,7 @@ type Table @delimiter make_delimiter_selector @column_count Columns_To_Add.default_widget split_to_columns : Text | Integer -> Text -> Columns_To_Add -> Problem_Behavior -> Table - split_to_columns self column delimiter="," (column_count : Columns_To_Add = ..All_Columns) on_problems=Report_Warning = + split_to_columns self column delimiter="," (column_count : Columns_To_Add = ..All_Columns) on_problems:Problem_Behavior=..Report_Warning = Split_Tokenize.split_to_columns self column delimiter column_count=column_count on_problems ## GROUP Standard.Base.Conversions @@ -1346,7 +1346,7 @@ type Table be reported according to the `on_problems` behavior. @column Widget_Helpers.make_column_name_selector tokenize_to_columns : Text | Integer -> Text -> Case_Sensitivity -> Columns_To_Add -> Problem_Behavior -> Table - tokenize_to_columns self column pattern="." case_sensitivity=Case_Sensitivity.Sensitive (column_count : Columns_To_Add = ..All_Columns) on_problems=Report_Warning = + tokenize_to_columns self column pattern="." case_sensitivity:Case_Sensitivity=Case_Sensitivity.Sensitive (column_count : Columns_To_Add = ..All_Columns) on_problems:Problem_Behavior=..Report_Warning = Split_Tokenize.tokenize_to_columns self column pattern case_sensitivity column_count on_problems ## GROUP Standard.Base.Conversions @@ -1367,7 +1367,7 @@ type Table Equivalent to converting a tokenization output of [] to [Nothing]. @column Widget_Helpers.make_column_name_selector tokenize_to_rows : Text | Integer -> Text -> Case_Sensitivity -> Boolean -> Table - tokenize_to_rows self column pattern="." case_sensitivity=Case_Sensitivity.Sensitive at_least_one_row=False = + tokenize_to_rows self column pattern="." case_sensitivity:Case_Sensitivity=Case_Sensitivity.Sensitive at_least_one_row:Boolean=False = Split_Tokenize.tokenize_to_rows self column pattern case_sensitivity at_least_one_row ## GROUP Standard.Base.Conversions @@ -1399,7 +1399,7 @@ type Table @column Widget_Helpers.make_column_name_selector @pattern Widget.Text_Input parse_to_columns : Text | Integer -> Text | Regex -> Case_Sensitivity -> Boolean -> Problem_Behavior -> Table - parse_to_columns self column pattern="." case_sensitivity=Case_Sensitivity.Sensitive parse_values=True on_problems=Report_Error = + parse_to_columns self column pattern="." case_sensitivity:Case_Sensitivity=Case_Sensitivity.Sensitive parse_values=True on_problems:Problem_Behavior=..Report_Error = Split_Tokenize.parse_to_columns self column pattern case_sensitivity parse_values on_problems ## GROUP Standard.Base.Calculations @@ -1452,7 +1452,7 @@ type Table # => Table.new [["aaa", [1, 1, 2, 2]], ["bbb", [30, 31, 40, 41]]] @column Widget_Helpers.make_column_name_selector expand_to_rows : Text | Integer -> Boolean -> Table ! Type_Error | No_Such_Column | Index_Out_Of_Bounds - expand_to_rows self column at_least_one_row=False = + expand_to_rows self column at_least_one_row:Boolean=False = Expand_Objects_Helpers.expand_to_rows self column at_least_one_row ## ALIAS filter rows, where @@ -1507,15 +1507,15 @@ type Table @column (Widget_Helpers.make_column_name_selector add_expression=True) @filter Widget_Helpers.make_filter_condition_selector filter : (Column | Expression | Text | Integer) -> (Filter_Condition | (Any -> Boolean)) -> Problem_Behavior -> Table ! No_Such_Column | Index_Out_Of_Bounds | Invalid_Value_Type - filter self column (filter : Filter_Condition | (Any -> Boolean) = Filter_Condition.Equal True) on_problems=Report_Warning = case column of + filter self column (filter : Filter_Condition | (Any -> Boolean) = Filter_Condition.Equal True) on_problems:Problem_Behavior=..Report_Warning = case column of _ : Column -> mask filter_column = Table.Value (self.java_table.filter filter_column.java_column) - case filter of + filter_condition = Filter_Condition.resolve_auto_scoped filter + case filter_condition of _ : Filter_Condition -> - resolved = (self:Table_Ref).resolve_condition filter + resolved = (self:Table_Ref).resolve_condition filter_condition mask (make_filter_column column resolved on_problems) - _ : Function -> Filter_Condition_Module.handle_constructor_missing_arguments filter <| - mask (column.map filter) + _ : Function -> mask (column.map filter_condition) _ : Expression -> self.filter (self.evaluate_expression column on_problems) filter on_problems _ -> table_at = self.at column @@ -1556,7 +1556,7 @@ type Table people.filter_by_expression "[age] % 10 == 0" filter_by_expression : Text -> Problem_Behavior -> Table ! No_Such_Column | Invalid_Value_Type | Expression_Error - filter_by_expression self expression on_problems=Report_Warning = + filter_by_expression self expression on_problems:Problem_Behavior=..Report_Warning = column = self.evaluate_expression (Expression.Value expression) on_problems result = self.filter column Filter_Condition.Is_True Warning.attach (Deprecated.Warning "Standard.Table.Table.Table" "filter_by_expression" "Deprecated: use `filter` with an `Expression` instead.") result @@ -1590,7 +1590,7 @@ type Table table.take (While row-> row.to_vector.compute Statistic.Sum == 10) @range Index_Sub_Range.default_widget take : (Index_Sub_Range | Range | Integer) -> Table - take self range=(First 1) = + take self range:(Index_Sub_Range | Range | Integer)=(..First 1) = Index_Sub_Range_Module.take_helper self.row_count (self.rows.at _) self.slice (slice_ranges self) range ## ALIAS skip, remove @@ -1622,7 +1622,7 @@ type Table table.drop (While row-> row.to_vector.compute Statistic.Sum == 10) @range Index_Sub_Range.default_widget drop : (Index_Sub_Range | Range | Integer) -> Table - drop self range=(First 1) = + drop self range:(Index_Sub_Range | Range | Integer)=(..First 1) = Index_Sub_Range_Module.drop_helper self.row_count (self.rows.at _) self.slice (slice_ranges self) range ## PRIVATE @@ -1665,7 +1665,7 @@ type Table @group_by Widget_Helpers.make_column_name_multi_selector @order_by Widget_Helpers.make_order_by_selector add_row_number : Text -> Integer -> Integer -> Vector (Text | Integer | Regex) | Text | Integer | Regex -> Vector (Text | Sort_Column) | Text -> Problem_Behavior -> Table - add_row_number self (name:Text="Row") (from:Integer=1) (step:Integer=1) (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (on_problems:Problem_Behavior=Problem_Behavior.Report_Warning) = + add_row_number self (name:Text="Row") (from:Integer=1) (step:Integer=1) (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (on_problems:Problem_Behavior=..Report_Warning) = Add_Row_Number.add_row_number self name from step group_by order_by on_problems ## ALIAS add column, expression, formula, new column, update column @@ -1713,7 +1713,7 @@ type Table table.set (expr "2 * [total_stock]") as="total_stock_expr" @value Simple_Expression.default_widget set : Text | Expression | Column | Constant_Column | Simple_Expression -> Text -> Set_Mode -> Problem_Behavior -> Table ! Existing_Column | Missing_Column | No_Such_Column | Expression_Error - set self value:(Text | Expression | Column | Constant_Column | Simple_Expression) (as : Text = "") (set_mode : Set_Mode = Set_Mode.Add_Or_Update) (on_problems : Problem_Behavior = Report_Warning) = + set self value:(Text | Expression | Column | Constant_Column | Simple_Expression) (as : Text = "") (set_mode : Set_Mode = ..Add_Or_Update) (on_problems : Problem_Behavior = ..Report_Warning) = problem_builder = Problem_Builder.new unique = self.column_naming_helper.create_unique_name_strategy unique.mark_used self.column_names @@ -1772,7 +1772,7 @@ type Table - If more than 10 rows encounter computation issues, an `Additional_Warnings`. evaluate_expression : Text | Expression -> Problem_Behavior -> Column ! No_Such_Column | Invalid_Value_Type | Expression_Error - evaluate_expression self expression:(Text | Expression) on_problems:Problem_Behavior=Report_Warning = if expression.is_a Text then self.evaluate_expression (Expression.Value expression) on_problems else + evaluate_expression self expression:(Text | Expression) on_problems:Problem_Behavior=..Report_Warning = if expression.is_a Text then self.evaluate_expression (Expression.Value expression) on_problems else get_column name = self.at name new_column = Expression.evaluate expression get_column self.make_constant_column "Standard.Table.Column" "Column" Column.var_args_functions problems = Warning.get_all new_column . map .value @@ -1959,7 +1959,7 @@ type Table @join_kind Widget_Helpers.make_join_kind_selector @on Widget_Helpers.make_join_condition_selector join : Table -> Join_Kind -> Vector (Join_Condition | Text) | Text -> Text -> Problem_Behavior -> Table - join self right:Table (join_kind : Join_Kind = Join_Kind.Left_Outer) on=[Join_Condition.Equals self.column_names.first] right_prefix="Right " on_problems=Report_Warning = Out_Of_Memory.handle_java_exception "join" <| + join self right:Table (join_kind : Join_Kind = ..Left_Outer) on=[Join_Condition.Equals self.column_names.first] right_prefix:Text="Right " on_problems:Problem_Behavior=..Report_Warning = Out_Of_Memory.handle_java_exception "join" <| columns_to_keep = case join_kind of Join_Kind.Left_Exclusive -> [True, False] Join_Kind.Right_Exclusive -> [False, True] @@ -2010,11 +2010,9 @@ type Table example, by sorting the table; in-memory tables will keep the memory layout order while for database tables the order may be unspecified). cross_join : Table -> Integer | Nothing -> Text -> Problem_Behavior -> Table - cross_join self right:Table right_row_limit=100 right_prefix="Right " on_problems=Report_Warning = Out_Of_Memory.handle_java_exception "cross_join" <| - limit_problems = case right_row_limit.is_nothing.not && (right.row_count > right_row_limit) of - True -> - [Cross_Join_Row_Limit_Exceeded.Error right_row_limit right.row_count] - False -> [] + cross_join self right:Table right_row_limit=100 right_prefix:Text="Right " on_problems:Problem_Behavior=..Report_Warning = Out_Of_Memory.handle_java_exception "cross_join" <| + limit_problems = if right_row_limit.is_nothing || (right.row_count < right_row_limit) then [] else + [Cross_Join_Row_Limit_Exceeded.Error right_row_limit right.row_count] on_problems.attach_problems_before limit_problems <| new_java_table = Java_Problems.with_problem_aggregator on_problems java_aggregator-> self.java_table.crossJoin right.java_table right_prefix java_aggregator @@ -2077,7 +2075,7 @@ type Table that are not present in this table, an `Unexpected_Extra_Columns`. @key_columns Widget_Helpers.make_column_name_multi_selector merge : Table -> (Vector (Integer | Text | Regex) | Text | Integer | Regex) -> Boolean -> Boolean -> Problem_Behavior -> Table ! Missing_Input_Columns | Non_Unique_Key | Unmatched_Rows_In_Lookup - merge self lookup_table:Table key_columns:(Vector (Integer | Text | Regex) | Text | Integer | Regex) add_new_columns:Boolean=False allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=Problem_Behavior.Report_Warning = + merge self lookup_table:Table key_columns:(Vector (Integer | Text | Regex) | Text | Integer | Regex) add_new_columns:Boolean=False allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=..Report_Warning = lookup_columns = Lookup_Helpers.prepare_columns_for_lookup self lookup_table key_columns add_new_columns allow_unmatched_rows on_problems java_descriptions = lookup_columns.map make_java_lookup_column_description on_problems=No_Wrap @@ -2189,7 +2187,7 @@ type Table @from_column Widget.Text_Input @to_column Widget.Text_Input replace : (Table | Map) -> (Text | Integer | Regex | By_Type | Vector (Text | Integer | Regex | By_Type)) -> (Text | Integer | Nothing) -> (Text | Integer | Nothing) -> Boolean -> Problem_Behavior -> Table ! Missing_Input_Columns | Non_Unique_Key | Unmatched_Rows_In_Lookup - replace self lookup_table:(Table | Map) columns:(Text | Integer | Regex | By_Type | Vector (Text | Integer | Regex | By_Type)) from_column:(Text | Integer | Nothing)=Nothing to_column:(Text | Integer | Nothing)=Nothing allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=Problem_Behavior.Report_Warning = + replace self lookup_table:(Table | Map) columns:(Text | Integer | Regex | By_Type | Vector (Text | Integer | Regex | By_Type)) from_column:(Text | Integer | Nothing)=Nothing to_column:(Text | Integer | Nothing)=Nothing allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=..Report_Warning = Replace_Helpers.replace self lookup_table columns from_column to_column allow_unmatched_rows on_problems ## ALIAS join by row position @@ -2244,7 +2242,7 @@ type Table The ordering of rows in the resulting table is not specified. @keep_unmatched (make_single_choice [["True", "Boolean.True"], ["False", "Boolean.False"], ["Report", Meta.get_qualified_type_name Report_Unmatched]]) zip : Table -> Boolean | Report_Unmatched -> Text -> Problem_Behavior -> Table - zip self right:Table keep_unmatched=Report_Unmatched right_prefix="Right " on_problems=Report_Warning = + zip self right:Table keep_unmatched=Report_Unmatched right_prefix:Text="Right " on_problems:Problem_Behavior=..Report_Warning = keep_unmatched_bool = case keep_unmatched of Report_Unmatched -> True b : Boolean -> b @@ -2338,7 +2336,7 @@ type Table @tables (Widget.Vector_Editor item_editor=Widget.Code_Input item_default='_' display=Display.Always) @columns_to_keep Columns_To_Keep.default_widget union : (Table | Vector Table) -> Columns_To_Keep -> Match_Columns -> Problem_Behavior -> Table - union self tables:(Table | Vector) (columns_to_keep : Columns_To_Keep = ..In_Any_Warn_On_Missing) (match_columns : Match_Columns = Match_Columns.By_Name) (on_problems : Problem_Behavior = Report_Warning) = + union self tables:(Table | Vector) (columns_to_keep : Columns_To_Keep = ..In_Any_Warn_On_Missing) (match_columns : Match_Columns = ..By_Name) (on_problems : Problem_Behavior = ..Report_Warning) = Table.from_union ([self] + Vector.unify_vector_or_element tables) columns_to_keep match_columns on_problems ## ALIAS drop_missing_rows, dropna @@ -2355,7 +2353,7 @@ type Table ? Blank values Blank values are `Nothing`, `""` and depending on setting `Number.nan`. filter_blank_rows : Blank_Selector -> Boolean -> Table - filter_blank_rows self when=Blank_Selector.Any_Cell treat_nans_as_blank=False = + filter_blank_rows self when:Blank_Selector=..Any_Cell treat_nans_as_blank:Boolean=False = Table_Helpers.filter_blank_rows self when treat_nans_as_blank ## ALIAS count @@ -2464,7 +2462,7 @@ type Table B | Country | Germany @key_columns Widget_Helpers.make_column_name_multi_selector transpose : Vector (Integer | Text | Regex) | Text | Integer | Regex -> Text -> Text -> Boolean -> Problem_Behavior -> Table ! No_Output_Columns | Missing_Input_Columns | Duplicate_Output_Column_Names - transpose self (key_columns = []) (attribute_column_name="Name") (value_column_name="Value") (error_on_missing_columns=True) (on_problems = Report_Warning) = + transpose self (key_columns = []) (attribute_column_name:Text="Name") (value_column_name:Text="Value") (error_on_missing_columns:Boolean=True) (on_problems:Problem_Behavior=..Report_Warning) = columns_helper = self.columns_helper unique = self.column_naming_helper.create_unique_name_strategy problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns @@ -2543,7 +2541,7 @@ type Table @names Widget_Helpers.make_column_name_selector @values Widget_Helpers.make_aggregate_column_selector cross_tab : Vector (Integer | Text | Regex | Aggregate_Column) | Text | Integer | Regex -> (Text | Integer) -> Aggregate_Column | Vector Aggregate_Column -> Problem_Behavior -> Table ! Missing_Input_Columns | Invalid_Aggregate_Column | Floating_Point_Equality | Invalid_Aggregation | Unquoted_Delimiter | Additional_Warnings | Invalid_Column_Names - cross_tab self group_by=[] names=self.column_names.first values=Aggregate_Column.Count (on_problems=Report_Warning) = Out_Of_Memory.handle_java_exception "cross_tab" <| + cross_tab self group_by=[] names=self.column_names.first values=..Count (on_problems:Problem_Behavior=..Report_Warning) = Out_Of_Memory.handle_java_exception "cross_tab" <| columns_helper = self.columns_helper problem_builder = Problem_Builder.new error_on_missing_columns=True @@ -2563,10 +2561,7 @@ type Table grouping = columns_helper.select_columns_helper (normalize_group_by group_by) Case_Sensitivity.Default True problem_builder ## Validate the values - values_vector = case values of - _ : Vector -> values - _ -> [values] - resolved_values = values_vector.map on_problems=No_Wrap (Aggregate_Column_Helper.resolve_aggregate self problem_builder) + resolved_values = Vector.unify_vector_or_element values . map on_problems=No_Wrap (Aggregate_Column_Helper.resolve_aggregate self problem_builder) is_group_by c = case c of Aggregate_Column.Group_By _ _ -> True _ -> False @@ -2695,7 +2690,7 @@ type Table @path (Widget.File_Browse existing_only=False display=Display.Always) @format Widget_Helpers.write_table_selector write : Writable_File -> File_Format -> Existing_File_Behavior -> Match_Columns -> Problem_Behavior -> File ! Column_Count_Mismatch | Illegal_Argument | File_Error - write self path:Writable_File format=Auto_Detect on_existing_file=Existing_File_Behavior.Backup match_columns=Match_Columns.By_Name on_problems=Report_Warning = + write self path:Writable_File format=Auto_Detect on_existing_file:Existing_File_Behavior=..Backup match_columns:Match_Columns=..By_Name on_problems:Problem_Behavior=..Report_Warning = File_Format.handle_format_missing_arguments format <| case format of _ : Auto_Detect -> base_format = format.get_writing_format path @@ -2760,7 +2755,7 @@ type Table @element_columns Widget_Helpers.make_column_name_vector_selector @attribute_columns Widget_Helpers.make_column_name_vector_selector @value_column Widget_Helpers.make_column_name_selector - to_xml self (element_columns : (Vector (Integer | Text | Regex) | Text | Integer | Regex) = self.column_names) (attribute_columns : (Vector (Integer | Text | Regex) | Text | Integer | Regex) = []) (value_column : Text | Integer | Nothing = Nothing) (root_name : Text = "Table") (row_name : Text = "Row") (on_problems : Problem_Behavior = Report_Warning) -> XML_Document = + to_xml self (element_columns : (Vector (Integer | Text | Regex) | Text | Integer | Regex) = self.column_names) (attribute_columns : (Vector (Integer | Text | Regex) | Text | Integer | Regex) = []) (value_column : Text | Integer | Nothing = Nothing) (root_name : Text = "Table") (row_name : Text = "Row") (on_problems : Problem_Behavior = ..Report_Warning) -> XML_Document = columns_helper = self.columns_helper problem_builder = Problem_Builder.new error_on_missing_columns=True resolved_element_columns = columns_helper.select_columns_helper element_columns Case_Sensitivity.Default False problem_builder @@ -2876,7 +2871,7 @@ type Table @term (Widget_Helpers.make_column_ref_by_name_selector add_regex=True add_text=True add_named_pattern=True) @new_text (Widget_Helpers.make_column_ref_by_name_selector add_text=True) text_replace : Vector (Integer | Text | Regex | By_Type) | Text | Integer | Regex | By_Type -> Text | Column | Column_Ref | Expression | Regex -> Text | Column | Column_Ref | Expression -> Case_Sensitivity -> Boolean -> Column - text_replace self columns (term : Text | Column | Column_Ref | Expression | Regex | By_Type = "") (new_text : Text | Column | Column_Ref | Expression = "") case_sensitivity=Case_Sensitivity.Sensitive only_first=False = + text_replace self columns (term : Text | Column | Column_Ref | Expression | Regex | By_Type = "") (new_text : Text | Column | Column_Ref | Expression = "") case_sensitivity:Case_Sensitivity=..Sensitive only_first:Boolean=False = table_ref = Table_Ref.from self resolved_term = table_ref.resolve term resolved_new_text = table_ref.resolve new_text @@ -2952,7 +2947,7 @@ type Table @order_by Widget_Helpers.make_order_by_selector @of Widget_Helpers.make_column_name_selector running : Statistic -> (Text | Integer) -> Text -> Vector (Text | Integer | Regex) | Text | Integer | Regex -> Vector (Text | Sort_Column) | Text -> Problem_Behavior -> Table - running self (statistic:Statistic=Statistic.Count) (of:(Text | Integer)=0) (as:Text='') (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (on_problems:Problem_Behavior=Problem_Behavior.Report_Warning) = + running self (statistic:Statistic=..Count) (of:(Text | Integer)=0) (as:Text='') (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (on_problems:Problem_Behavior=..Report_Warning) = Add_Running.add_running self statistic of as group_by order_by on_problems ## PRIVATE @@ -3036,7 +3031,7 @@ type Table @tables (Widget.Vector_Editor item_editor=Widget.Code_Input item_default='_' display=Display.Always) @columns_to_keep Columns_To_Keep.default_widget from_union : (Vector Table) -> Columns_To_Keep -> Match_Columns -> Problem_Behavior -> Table ! No_Output_Columns | Illegal_Argument - from_union (tables : Vector) (columns_to_keep : Columns_To_Keep = ..In_Any_Warn_On_Missing) (match_columns : Match_Columns = Match_Columns.By_Name) (on_problems : Problem_Behavior = Report_Warning) = + from_union (tables : Vector) (columns_to_keep : Columns_To_Keep = ..In_Any_Warn_On_Missing) (match_columns : Match_Columns = ..By_Name) (on_problems : Problem_Behavior = ..Report_Warning) = all_tables = (tables.map t-> Table.from t) if all_tables.is_empty then Error.throw (Illegal_Argument.Error "`Table.from_union` needs at least 1 input table.") else ## We keep separate problem builders, because if we are reporting `No_Output_Columns`, diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java index 78c8b15611fa..e643b64c7828 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java @@ -32,6 +32,7 @@ import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.runtime.data.atom.Atom; import org.enso.interpreter.runtime.data.atom.AtomConstructor; +import org.enso.interpreter.runtime.error.DataflowError; import org.enso.interpreter.runtime.error.PanicException; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; import org.enso.interpreter.runtime.state.State; @@ -258,6 +259,8 @@ private Object invokeConstructor( var r = callNode.call(helper); if (r instanceof Atom) { return r; + } else if (r instanceof DataflowError) { + return r; } else { var ctx = EnsoContext.get(this); var err = ctx.getBuiltins().error().makeTypeError(c.getType(), r, prototype.toString()); diff --git a/test/Base_Tests/src/Data/Text_Spec.enso b/test/Base_Tests/src/Data/Text_Spec.enso index 322064da8a13..5ec8261f7aff 100644 --- a/test/Base_Tests/src/Data/Text_Spec.enso +++ b/test/Base_Tests/src/Data/Text_Spec.enso @@ -5,6 +5,7 @@ import Standard.Base.Data.Text.Span.Span import Standard.Base.Data.Text.Span.Utf_16_Span import Standard.Base.Errors.Common.Index_Out_Of_Bounds import Standard.Base.Errors.Common.Incomparable_Values +import Standard.Base.Errors.Common.Missing_Argument import Standard.Base.Errors.Common.Type_Error import Standard.Base.Errors.Illegal_Argument.Illegal_Argument @@ -762,16 +763,8 @@ add_specs suite_builder = Test.expect_panic Type_Error <| "".drop "FOO" r1 = "".take (Index_Sub_Range.While) - r1.should_fail_with Illegal_Argument - r1.catch.to_display_text . should_contain "The constructor While is missing some arguments" - - r2 = "".drop (Text_Sub_Range.Before ...) - r2.should_fail_with Illegal_Argument - r2.catch.to_display_text . should_contain "The constructor Before is missing some arguments" - - r3 = "".take (Index_Sub_Range.First _) - r3.should_fail_with Illegal_Argument - r3.catch.to_display_text . should_contain "Got a Function instead of a range, is a constructor argument missing?" + r1.should_fail_with Missing_Argument + r1.catch.to_display_text . should_contain "Provide a value for the argument `predicate`." # Double-check that constructors of _unexpected_ types are still yielding a type error. Test.expect_panic Type_Error <| "".take (Case_Sensitivity.Insensitive ...) diff --git a/test/Base_Tests/src/Data/Vector_Spec.enso b/test/Base_Tests/src/Data/Vector_Spec.enso index adf050bcbd86..41a274fcfe26 100644 --- a/test/Base_Tests/src/Data/Vector_Spec.enso +++ b/test/Base_Tests/src/Data/Vector_Spec.enso @@ -1,5 +1,6 @@ from Standard.Base import all from Standard.Base.Data.Array_Proxy import Array_Proxy +import Standard.Base.Errors.Common.Missing_Argument import Standard.Base.Errors.Empty_Error.Empty_Error import Standard.Base.Data.Vector.Builder import Standard.Base.Data.Vector.Map_Error @@ -7,6 +8,7 @@ import Standard.Base.Data.Vector.No_Wrap import Standard.Base.Errors.Common.Additional_Warnings import Standard.Base.Errors.Common.Incomparable_Values import Standard.Base.Errors.Common.Index_Out_Of_Bounds +import Standard.Base.Errors.Common.Missing_Argument import Standard.Base.Errors.Common.Not_Found import Standard.Base.Errors.Common.Type_Error import Standard.Base.Errors.Common.Unsupported_Argument_Types @@ -359,10 +361,10 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> v = alter [0, 1, 2] r1 = v.filter Filter_Condition.Less - r1 . should_fail_with Illegal_Argument - r1.catch.to_display_text . should_contain "missing arguments" + r1 . should_fail_with Missing_Argument + r1.catch.to_display_text . should_contain "Provide a value for" - v.filter (Filter_Condition.Between 10) . should_fail_with Illegal_Argument + v.filter (Filter_Condition.Between 10) . should_fail_with Missing_Argument group_builder.specify "should filter elements with indices" <| (alter [0, 10, 2, 2] . filter_with_index (==)) . should_equal [0, 2] @@ -686,8 +688,8 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> Test.expect_panic Type_Error <| [].drop "FOO" r1 = [].take (Index_Sub_Range.While) - r1.should_fail_with Illegal_Argument - r1.catch.to_display_text . should_contain "The constructor While is missing some arguments" + r1.should_fail_with Missing_Argument + r1.catch.to_display_text . should_contain "Provide a value for the argument `predicate`." r2 = [].drop (Index_Sub_Range.Every ...) r2.should_fail_with Illegal_Argument diff --git a/test/Base_Tests/src/Runtime/Missing_Required_Arguments_Spec.enso b/test/Base_Tests/src/Runtime/Missing_Required_Arguments_Spec.enso index 44a22c18f1aa..873fe76ca88e 100644 --- a/test/Base_Tests/src/Runtime/Missing_Required_Arguments_Spec.enso +++ b/test/Base_Tests/src/Runtime/Missing_Required_Arguments_Spec.enso @@ -1,5 +1,5 @@ from Standard.Base import all -import Standard.Base.Errors.Common.Missing_Required_Argument +import Standard.Base.Errors.Common.Missing_Argument import Standard.Base.Errors.Common.Not_Invokable import Standard.Base.Runtime.Ref.Ref @@ -7,19 +7,19 @@ import Standard.Base.Runtime.Ref.Ref from Standard.Test import all -my_function (xyz : Integer = Missing_Required_Argument.ensure_present "xyz") (y : Integer = 100) = +my_function (xyz : Integer = Missing_Argument.ensure_present "xyz") (y : Integer = 100) = xyz + y -my_function_2 (x : Integer = Missing_Required_Argument.ensure_present "x") = +my_function_2 (x : Integer = Missing_Argument.ensure_present "x") = x * 10 type Foo - Ctor (x : Integer = Missing_Required_Argument.ensure_present "x") (y : Integer = 100) + Ctor (x : Integer = Missing_Argument.ensure_present "x") (y : Integer = 100) - member self (txt : Text = Missing_Required_Argument.ensure_present "txt") = + member self (txt : Text = Missing_Argument.ensure_present "txt") = "Foo(" + self.x.to_text + ", " + self.y.to_text + "): " + txt -add_specs suite_builder = suite_builder.group "Missing_Required_Argument" group_builder-> +add_specs suite_builder = suite_builder.group "Missing_Argument" group_builder-> group_builder.specify "should do nothing if the argument is provided" <| r1 = my_function 23 r1.should_equal 123 @@ -39,7 +39,7 @@ add_specs suite_builder = suite_builder.group "Missing_Required_Argument" group_ group_builder.specify "should raise an error if a required argument is not specified" <| r1 = my_function - r1.should_fail_with Missing_Required_Argument + r1.should_fail_with Missing_Argument r1.catch.argument_name . should_equal "xyz" r1.catch.function_name . should_equal "Missing_Required_Arguments_Spec.my_function" r1.catch.call_location.file.name . should_equal "Missing_Required_Arguments_Spec.enso" @@ -47,13 +47,13 @@ add_specs suite_builder = suite_builder.group "Missing_Required_Argument" group_ r1.catch.to_display_text . should_equal "Missing required argument `xyz` in function `Missing_Required_Arguments_Spec.my_function`." r2 = my_function_2 - r2.should_fail_with Missing_Required_Argument + r2.should_fail_with Missing_Argument r3 = Foo.Ctor - r3.should_fail_with Missing_Required_Argument + r3.should_fail_with Missing_Argument r4 = Foo.Ctor 44 . member - r4.should_fail_with Missing_Required_Argument + r4.should_fail_with Missing_Argument r4.catch.argument_name . should_equal "txt" r4.catch.function_name . should_equal "Foo.member" r4.catch.to_display_text . should_equal "Missing required argument `txt` in function `Foo.member`." diff --git a/test/Base_Tests/src/Widget_Helpers_Spec.enso b/test/Base_Tests/src/Widget_Helpers_Spec.enso index bfc5673117af..3429b5658b3e 100644 --- a/test/Base_Tests/src/Widget_Helpers_Spec.enso +++ b/test/Base_Tests/src/Widget_Helpers_Spec.enso @@ -20,4 +20,4 @@ add_specs suite_builder = group_builder.specify "make_data_cleanse_vector_selector" <| w = make_data_cleanse_vector_selector j = (Widgets.get_widget_json w) . to_text - j.should_contain "Option 'Leading_Whitespace' 'Named_Pattern.Leading_Whitespace' [] ''" + j.should_contain "Option 'Leading_Whitespace' '..Leading_Whitespace' [] ''" diff --git a/test/Table_Tests/src/Common_Table_Operations/Aggregate_Spec.enso b/test/Table_Tests/src/Common_Table_Operations/Aggregate_Spec.enso index a27b41bbbd01..2a1e3d8ac3e2 100644 --- a/test/Table_Tests/src/Common_Table_Operations/Aggregate_Spec.enso +++ b/test/Table_Tests/src/Common_Table_Operations/Aggregate_Spec.enso @@ -73,6 +73,15 @@ add_specs suite_builder setup = materialized.columns.at 0 . name . should_equal "Count" materialized.columns.at 0 . at 0 . should_equal 2500 + group_builder.specify "should be able to count (autoscoped)" <| + grouped = data.table.aggregate columns=[..Count] + materialized = materialize grouped + Problems.assume_no_problems materialized + grouped.row_count . should_equal 1 + materialized.column_count . should_equal 1 + materialized.columns.at 0 . name . should_equal "Count" + materialized.columns.at 0 . at 0 . should_equal 2500 + group_builder.specify "should be able to count missing values" <| grouped = data.table.aggregate columns=[Count_Nothing "Hexadecimal", Count_Not_Nothing "Hexadecimal", Count_Empty "TextWithNothing", Count_Not_Empty "TextWithNothing"] materialized = materialize grouped @@ -125,6 +134,21 @@ add_specs suite_builder setup = materialized.columns.at 3 . name . should_equal "Average ValueWithNothing" materialized.columns.at 3 . at 0 . should_equal 1.228650 epsilon=0.000001 + group_builder.specify "should be able to compute sum and average of values (autoscoped)" <| + grouped = data.table.aggregate columns=[..Sum "Value", ..Sum "ValueWithNothing", ..Average "Value", ..Average "ValueWithNothing"] + materialized = materialize grouped + Problems.assume_no_problems materialized + grouped.row_count . should_equal 1 + materialized.column_count . should_equal 4 + materialized.columns.at 0 . name . should_equal "Sum Value" + materialized.columns.at 0 . at 0 . should_equal -932.411550 epsilon=0.000001 + materialized.columns.at 1 . name . should_equal "Sum ValueWithNothing" + materialized.columns.at 1 . at 0 . should_equal 2757.09 epsilon=0.000001 + materialized.columns.at 2 . name . should_equal "Average Value" + materialized.columns.at 2 . at 0 . should_equal -0.372965 epsilon=0.000001 + materialized.columns.at 3 . name . should_equal "Average ValueWithNothing" + materialized.columns.at 3 . at 0 . should_equal 1.228650 epsilon=0.000001 + group_builder.specify "should be able to compute standard deviation of values" (pending = resolve_pending test_selection.std_dev) <| grouped = data.table.aggregate columns=[Standard_Deviation "Value", Standard_Deviation "ValueWithNothing", (Standard_Deviation "Value" population=True), (Standard_Deviation "ValueWithNothing" population=True)] materialized = materialize grouped diff --git a/test/Table_Tests/src/Common_Table_Operations/Derived_Columns_Spec.enso b/test/Table_Tests/src/Common_Table_Operations/Derived_Columns_Spec.enso index d2a5d1aacfc3..dfe54da224ea 100644 --- a/test/Table_Tests/src/Common_Table_Operations/Derived_Columns_Spec.enso +++ b/test/Table_Tests/src/Common_Table_Operations/Derived_Columns_Spec.enso @@ -39,7 +39,11 @@ add_specs suite_builder setup = group_builder.specify "arithmetics" <| t = table_builder [["A", [1, 2]], ["B", [10, 40]]] t.set (Simple_Expression.From (Column_Ref.Name "A") Simple_Calculation.Copy) "C" . at "C" . to_vector . should_equal [1, 2] + t.set (..From (..Name "A") ..Copy) "C" . at "C" . to_vector . should_equal [1, 2] + t.set (Simple_Expression.From (Column_Ref.Name "A") (Simple_Calculation.Add (Column_Ref.Name "B"))) "C" . at "C" . to_vector . should_equal [11, 42] + t.set (..From (..Name "A") (..Add (..Name "B"))) "C" . at "C" . to_vector . should_equal [11, 42] + t.set (Simple_Expression.From 100 (Simple_Calculation.Add (Column_Ref.Name "B"))) "C" . at "C" . to_vector . should_equal [110, 140] t.set (Simple_Expression.From (Column_Ref.Name "A") (Simple_Calculation.Add 100)) "C" . at "C" . to_vector . should_equal [101, 102] t.set (Simple_Expression.From 23 (Simple_Calculation.Add 100)) "C" . at "C" . to_vector . should_equal [123, 123] diff --git a/test/Table_Tests/src/Common_Table_Operations/Filter_Spec.enso b/test/Table_Tests/src/Common_Table_Operations/Filter_Spec.enso index b92da440f5f8..be5d61f608ec 100644 --- a/test/Table_Tests/src/Common_Table_Operations/Filter_Spec.enso +++ b/test/Table_Tests/src/Common_Table_Operations/Filter_Spec.enso @@ -1,6 +1,7 @@ from Standard.Base import all import Standard.Base.Errors.Common.Arithmetic_Error import Standard.Base.Errors.Common.Index_Out_Of_Bounds +import Standard.Base.Errors.Common.Missing_Argument import Standard.Base.Errors.Common.Type_Error import Standard.Base.Errors.Illegal_Argument.Illegal_Argument import Standard.Base.Errors.Illegal_State.Illegal_State @@ -50,17 +51,24 @@ add_specs suite_builder setup = group_builder.specify "by integer comparisons" <| t = table_builder [["ix", [1, 2, 3, 4, 5]], ["X", [100, 3, Nothing, 4, 12]], ["Y", [100, 4, 2, Nothing, 11]]] t.filter "X" (Filter_Condition.Less than=10) . at "X" . to_vector . should_equal [3, 4] + t.filter "X" (..Less than=10) . at "X" . to_vector . should_equal [3, 4] t.filter "X" (Filter_Condition.Less than=4) . at "X" . to_vector . should_equal [3] t.filter "X" (Filter_Condition.Less than=4 action=Filter_Action.Remove) . at "X" . to_vector . should_equal [100, Nothing, 4, 12] + t.filter "X" (..Less than=4 action=..Remove) . at "X" . to_vector . should_equal [100, Nothing, 4, 12] t.filter "X" (Filter_Condition.Equal_Or_Less than=4) . at "X" . to_vector . should_equal [3, 4] + t.filter "X" (..Equal_Or_Less than=4) . at "X" . to_vector . should_equal [3, 4] t.filter "X" (Filter_Condition.Equal_Or_Less than=4 action=Filter_Action.Remove) . at "X" . to_vector . should_equal [100, Nothing, 12] t.filter "X" (Filter_Condition.Greater than=4) . at "X" . to_vector . should_equal [100, 12] + t.filter "X" (..Greater than=4) . at "X" . to_vector . should_equal [100, 12] t.filter "X" (Filter_Condition.Greater than=4 action=Filter_Action.Remove) . at "X" . to_vector . should_equal [3, Nothing, 4] t.filter "X" (Filter_Condition.Equal_Or_Greater than=4) . at "X" . to_vector . should_equal [100, 4, 12] + t.filter "X" (..Equal_Or_Greater than=4) . at "X" . to_vector . should_equal [100, 4, 12] t.filter "X" (Filter_Condition.Equal_Or_Greater than=4 action=Filter_Action.Remove) . at "X" . to_vector . should_equal [3, Nothing] t.filter "X" (Filter_Condition.Between 4 100) . at "X" . to_vector . should_equal [100, 4, 12] + t.filter "X" (..Between 4 100) . at "X" . to_vector . should_equal [100, 4, 12] t.filter "X" (Filter_Condition.Between 4 100 action=Filter_Action.Remove) . at "X" . to_vector . should_equal [3, Nothing] t.filter "X" (Filter_Condition.Equal to=100) . at "X" . to_vector . should_equal [100] + t.filter "X" (..Equal to=100) . at "X" . to_vector . should_equal [100] t.filter "X" (Filter_Condition.Equal to=123) . at "X" . to_vector . should_equal [] t.filter "X" (Filter_Condition.Equal to=3 action=Filter_Action.Remove) . at "X" . to_vector . should_equal [100, Nothing, 4, 12] @@ -94,6 +102,7 @@ add_specs suite_builder setup = t.filter "Y" (Filter_Condition.Between (t.at "ix") 100 action=Filter_Action.Remove) . at "Y" . to_vector . should_equal [2, Nothing] t.filter "X" (Filter_Condition.Equal to=(Column_Ref.Name "Y")) . at "X" . to_vector . should_equal [100] + t.filter "X" (..Equal to=(..Name "Y")) . at "X" . to_vector . should_equal [100] t.filter "X" (Filter_Condition.Equal to=(expr "[Y]-1")) . at "X" . to_vector . should_equal [3] t.filter "X" (Filter_Condition.Less than=(Column_Ref.Name "Y")) . at "X" . to_vector . should_equal [3] t.filter "X" (Filter_Condition.Equal_Or_Less than=(Column_Ref.Name "Y")) . at "X" . to_vector . should_equal [100, 3] @@ -385,10 +394,10 @@ add_specs suite_builder setup = group_builder.specify "should nicely handle Filter_Condition with unapplied arguments" <| t = table_builder [["X", [10, 20, 13, 4, 5]]] - t.filter "X" (Filter_Condition.Equal) . should_fail_with Illegal_Argument - t.filter "X" (Filter_Condition.Starts_With) . should_fail_with Illegal_Argument - t.filter "X" (Filter_Condition.Between) . should_fail_with Illegal_Argument - t.filter "X" (Filter_Condition.Between 1) . should_fail_with Illegal_Argument + t.filter "X" (Filter_Condition.Equal) . should_fail_with Missing_Argument + t.filter "X" (Filter_Condition.Starts_With) . should_fail_with Missing_Argument + t.filter "X" (Filter_Condition.Between) . should_fail_with Missing_Argument + t.filter "X" (Filter_Condition.Between 1) . should_fail_with Missing_Argument group_builder.specify "should report issues: floating point equality" <| t = table_builder [["ix", [1, 2, 3, 4, 5]], ["X", [10.0, 2.0001, 2.0, 4.5, 2.0]]] diff --git a/test/Table_Tests/src/Common_Table_Operations/Join/Join_Spec.enso b/test/Table_Tests/src/Common_Table_Operations/Join/Join_Spec.enso index c172ca38cd90..8ea0c41ffb12 100644 --- a/test/Table_Tests/src/Common_Table_Operations/Join/Join_Spec.enso +++ b/test/Table_Tests/src/Common_Table_Operations/Join/Join_Spec.enso @@ -79,6 +79,15 @@ add_specs suite_builder setup = t4.at "Y" . to_vector . should_equal [5, 5, 6] t4.at "W" . to_vector . should_equal [4, 6, 5] + group_builder.specify "should allow Inner join (autoscoped)" <| + t3 = data.t1.join data.t2 join_kind=..Inner on=(..Equals 0 0) + expect_column_names ["X", "Y", "Z", "W"] t3 + t4 = t3 |> materialize |> _.order_by ["X", "W"] + t4.at "X" . to_vector . should_equal [2, 2, 3] + t4.at "Z" . to_vector . should_equal [2, 2, 3] + t4.at "Y" . to_vector . should_equal [5, 5, 6] + t4.at "W" . to_vector . should_equal [4, 6, 5] + group_builder.specify "should allow Full join" <| t3 = data.t1.join data.t2 join_kind=Join_Kind.Full on=(Join_Condition.Equals 0 0) |> materialize |> _.order_by ["X", "W"] expect_column_names ["X", "Y", "Z", "W"] t3 diff --git a/test/Table_Tests/src/Common_Table_Operations/Order_By_Spec.enso b/test/Table_Tests/src/Common_Table_Operations/Order_By_Spec.enso index ee7d3d00af5b..03d2e7a43394 100644 --- a/test/Table_Tests/src/Common_Table_Operations/Order_By_Spec.enso +++ b/test/Table_Tests/src/Common_Table_Operations/Order_By_Spec.enso @@ -95,6 +95,23 @@ add_specs suite_builder setup = t4.at "alpha" . to_vector . should_equal [3, 2, 1, 0] t4.at "gamma" . to_vector . should_equal [1, 2, 3, 4] + group_builder.specify "should work with single Sort_Column (autoscoped)" <| + t1 = data.table.order_by [..Name "alpha"] + t1.at "alpha" . to_vector . should_equal [0, 1, 2, 3] + t1.at "gamma" . to_vector . should_equal [4, 3, 2, 1] + + t2 = t1.order_by [..Name "alpha" ..Descending] + t2.at "alpha" . to_vector . should_equal [3, 2, 1, 0] + t2.at "gamma" . to_vector . should_equal [1, 2, 3, 4] + + t3 = data.table.order_by [..Index 0] + t3.at "alpha" . to_vector . should_equal [0, 1, 2, 3] + t3.at "gamma" . to_vector . should_equal [4, 3, 2, 1] + + t4 = t3.order_by [..Index 0 ..Descending] + t4.at "alpha" . to_vector . should_equal [3, 2, 1, 0] + t4.at "gamma" . to_vector . should_equal [1, 2, 3, 4] + group_builder.specify "should allow the selector to mix regex and case insensitive matching" <| t4 = data.table.order_by [Sort_Column.Select_By_Name "A.*".to_regex case_sensitivity=Case_Sensitivity.Insensitive] t4.at "alpha" . to_vector . should_equal [0, 1, 2, 3] diff --git a/test/Table_Tests/src/Common_Table_Operations/Take_Drop_Spec.enso b/test/Table_Tests/src/Common_Table_Operations/Take_Drop_Spec.enso index 47c664d17b22..efd574938c26 100644 --- a/test/Table_Tests/src/Common_Table_Operations/Take_Drop_Spec.enso +++ b/test/Table_Tests/src/Common_Table_Operations/Take_Drop_Spec.enso @@ -1,6 +1,7 @@ from Standard.Base import all from Standard.Base.Data.Index_Sub_Range.Index_Sub_Range import While, Sample, Every import Standard.Base.Errors.Common.Index_Out_Of_Bounds +import Standard.Base.Errors.Common.Missing_Argument import Standard.Base.Errors.Common.Type_Error import Standard.Base.Errors.Illegal_Argument.Illegal_Argument @@ -232,16 +233,8 @@ add_specs suite_builder setup = Test.expect_panic Type_Error <| t.drop "FOO" r1 = t.take (Index_Sub_Range.While) - r1.should_fail_with Illegal_Argument - r1.catch.to_display_text . should_contain "The constructor While is missing some arguments" - - r2 = t.drop (Index_Sub_Range.Every ...) - r2.should_fail_with Illegal_Argument - r2.catch.to_display_text . should_contain "The constructor Every is missing some arguments" - - r3 = t.take (Index_Sub_Range.First _) - r3.should_fail_with Illegal_Argument - r3.catch.to_display_text . should_contain "Got a Function instead of a range, is a constructor argument missing?" + r1.should_fail_with Missing_Argument + r1.catch.to_display_text . should_contain "Provide a value for the argument `predicate`." group_builder.specify "unordered table" <| unordered_table = @@ -436,16 +429,8 @@ add_specs suite_builder setup = Test.expect_panic Type_Error <| c.drop "FOO" r1 = c.take (Index_Sub_Range.While) - r1.should_fail_with Illegal_Argument - r1.catch.to_display_text . should_contain "The constructor While is missing some arguments" - - r2 = c.drop (Index_Sub_Range.Every ...) - r2.should_fail_with Illegal_Argument - r2.catch.to_display_text . should_contain "The constructor Every is missing some arguments" - - r3 = c.take (Index_Sub_Range.First _) - r3.should_fail_with Illegal_Argument - r3.catch.to_display_text . should_contain "Got a Function instead of a range, is a constructor argument missing?" + r1.should_fail_with Missing_Argument + r1.catch.to_display_text . should_contain "Provide a value for the argument `predicate`." group_builder.specify "unordered table" <| unordered_table = diff --git a/test/Table_Tests/src/Formatting/Data_Formatter_Spec.enso b/test/Table_Tests/src/Formatting/Data_Formatter_Spec.enso index 897370d3d30c..330131bac009 100644 --- a/test/Table_Tests/src/Formatting/Data_Formatter_Spec.enso +++ b/test/Table_Tests/src/Formatting/Data_Formatter_Spec.enso @@ -1,4 +1,5 @@ from Standard.Base import all +import Standard.Base.Errors.Common.Type_Error import Standard.Base.Errors.Illegal_Argument.Illegal_Argument import Standard.Base.Errors.Illegal_State.Illegal_State from Standard.Base.Data.Time.Errors import Date_Time_Format_Parse_Error, Suspicious_Date_Time_Format @@ -214,7 +215,7 @@ add_specs suite_builder = group_builder.specify "should not allow unexpected types" <| formatter = Data_Formatter.Value - formatter.parse "Text" type=List . should_fail_with Illegal_Argument + Test.expect_panic Type_Error (formatter.parse "Text" type=List) suite_builder.group "DataFormatter.format" group_builder-> group_builder.specify "should handle Nothing" <| diff --git a/test/Table_Tests/src/Formatting/Parse_Values_Spec.enso b/test/Table_Tests/src/Formatting/Parse_Values_Spec.enso index b6da33f06b84..4b1121032a5d 100644 --- a/test/Table_Tests/src/Formatting/Parse_Values_Spec.enso +++ b/test/Table_Tests/src/Formatting/Parse_Values_Spec.enso @@ -1,4 +1,5 @@ from Standard.Base import all +import Standard.Base.Errors.Common.Type_Error import Standard.Base.Errors.Illegal_Argument.Illegal_Argument import Standard.Base.Data.Time.Errors.Date_Time_Format_Parse_Error @@ -362,7 +363,7 @@ add_specs suite_builder = group_builder.specify "should error if invalid target type is provided" <| t1 = Table.new [["A", ["1", "2", "3"]]] - t1.parse type=Nothing . should_fail_with Illegal_Argument + Test.expect_panic Type_Error (t1.parse type=Nothing) group_builder.specify "should error if the input column is not text" <| t1 = Table.new [["A", [1, 2, 3]], ["B", ["4", "5", "6"]], ["C", [7, 8, 9]], ["D", ["10", "11", "12"]]] @@ -627,7 +628,7 @@ add_specs suite_builder = group_builder.specify "should error if invalid target type is provided" <| c1 = Column.from_vector "A" ["1", "2", "3"] - c1.parse type=Nothing . should_fail_with Illegal_Argument + Test.expect_panic Type_Error (c1.parse type=Nothing) group_builder.specify "should return unchanged if all are Nothing or no rows" <| c1 = Column.from_vector "A" [Nothing, Nothing, Nothing] Value_Type.Char