mirror of
https://github.com/enso-org/enso.git
synced 2024-12-22 18:38:11 +03:00
Some tweaks following Steve's testings (#10042)
- Add ranged number widget to `at` and `get`. - Add defaults to `at` and `get` picking the first item. - PRIVATE on various Excel_Workbook methods. It still works like a connection but not shown in CB.
This commit is contained in:
parent
921870f12b
commit
d8059fd22c
@ -24,6 +24,7 @@ import project.Panic.Panic
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Index_Sub_Range import Index_Sub_Range
|
||||
from project.Data.Range.Extensions import all
|
||||
from project.Metadata import Display, Widget
|
||||
|
||||
## The type of primitive mutable arrays.
|
||||
@Builtin_Type
|
||||
@ -46,8 +47,9 @@ type Array
|
||||
Get the last element of an array.
|
||||
|
||||
[1, 2, 3].to_array.at -1 == 3
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
at : Integer -> Any ! Index_Out_Of_Bounds
|
||||
at self index = Array_Like_Helpers.at self index
|
||||
at self index:Integer=0 = Array_Like_Helpers.at self index
|
||||
|
||||
## GROUP Metadata
|
||||
ICON metadata
|
||||
@ -733,8 +735,9 @@ type Array
|
||||
also allowed be negative, then the elements are indexed from the back
|
||||
of the array, i.e. -1 will correspond to the last element.
|
||||
- if_missing: The value to return if the index is out of bounds.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
get : Integer -> Any -> Any
|
||||
get self index ~if_missing=Nothing =
|
||||
get self index:Integer=0 ~if_missing=Nothing =
|
||||
Array_Like_Helpers.get self index if_missing
|
||||
|
||||
## GROUP Logical
|
||||
|
@ -40,4 +40,4 @@ type Array_Proxy
|
||||
methods.
|
||||
from_proxy_object : Any -> Array
|
||||
from_proxy_object proxy =
|
||||
Array_Like_Helpers.new_array_proxy_builtin proxy.length proxy.at
|
||||
Array_Like_Helpers.new_array_proxy_builtin proxy.length (i-> proxy.at i)
|
||||
|
@ -16,6 +16,7 @@ import project.Panic.Panic
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Filter_Condition import unify_condition_or_predicate, unify_condition_predicate_or_element
|
||||
from project.Data.List.List import Cons, Nil
|
||||
from project.Metadata import Display, Widget
|
||||
|
||||
## The basic cons-list type.
|
||||
|
||||
@ -76,8 +77,9 @@ type List
|
||||
import Standard.Examples
|
||||
|
||||
example_length = Examples.list.length
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
at : Integer -> Any ! Index_Out_Of_Bounds
|
||||
at self index =
|
||||
at self index:Integer=0 =
|
||||
self.get index (Error.throw (Index_Out_Of_Bounds.Error index self.length))
|
||||
|
||||
## ICON parse3
|
||||
@ -93,8 +95,9 @@ type List
|
||||
also allowed be negative, then the elements are indexed from the back
|
||||
of the final item, i.e. -1 will correspond to the last element.
|
||||
- if_missing: The value to return if the index is out of bounds.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
get : Integer -> Any -> Any
|
||||
get self index ~if_missing=Nothing = case index >= 0 of
|
||||
get self index:Integer=0 ~if_missing=Nothing = case index >= 0 of
|
||||
True ->
|
||||
loop current index = case current of
|
||||
Nil -> if_missing
|
||||
|
@ -10,6 +10,7 @@ import project.Function.Function
|
||||
import project.Nothing.Nothing
|
||||
import project.Panic.Panic
|
||||
from project.Data.Text.Extensions import all
|
||||
from project.Metadata import Display, Widget
|
||||
|
||||
## A pair of elements.
|
||||
type Pair
|
||||
@ -70,8 +71,9 @@ type Pair
|
||||
- index: The location in the pair to get the element from. The index is
|
||||
also allowed be negative, then the elements are indexed from the back
|
||||
of the pair, i.e. -1 will correspond to the last element.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
at : Integer -> Any
|
||||
at self index =
|
||||
at self index:Integer=0 =
|
||||
self.get index (Error.throw (Index_Out_Of_Bounds.Error index 2))
|
||||
|
||||
## ICON parse3
|
||||
@ -83,8 +85,9 @@ type Pair
|
||||
also allowed be negative, then the elements are indexed from the back
|
||||
of the pair, i.e. -1 will correspond to the last element.
|
||||
- if_missing: The value to return if the index is out of bounds.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
get : Integer -> Any -> Any
|
||||
get self index ~if_missing=Nothing =
|
||||
get self index:Integer=0 ~if_missing=Nothing =
|
||||
case index of
|
||||
0 -> self.first
|
||||
1 -> self.second
|
||||
|
@ -15,6 +15,7 @@ import project.Nothing.Nothing
|
||||
import project.Panic.Panic
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Filter_Condition import unify_condition_or_predicate
|
||||
from project.Metadata import Display, Widget
|
||||
|
||||
## Represents a right-exclusive range of integer values.
|
||||
type Range
|
||||
@ -120,8 +121,9 @@ type Range
|
||||
Get the last element of a range with step.
|
||||
|
||||
0.up_to 10 . with_step 2 . get -1 == 8
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
at : Integer -> Any ! Index_Out_Of_Bounds
|
||||
at self index =
|
||||
at self index:Integer=0 =
|
||||
self.get index (Error.throw (Index_Out_Of_Bounds.Error index self.length))
|
||||
|
||||
## ICON parse3
|
||||
@ -133,8 +135,9 @@ type Range
|
||||
also allowed be negative, then the elements are indexed from the back,
|
||||
i.e. -1 will correspond to the last element.
|
||||
- if_missing: The value to return if the index is out of bounds.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
get : Integer -> Any -> Any
|
||||
get self index ~if_missing=Nothing =
|
||||
get self index:Integer=0 ~if_missing=Nothing =
|
||||
len = self.length
|
||||
used_index = if index < 0 then len + index else index
|
||||
if used_index >= 0 && used_index < len then self.start + used_index * self.step else
|
||||
@ -532,10 +535,9 @@ type Range
|
||||
1.up_to 6 . to_vector
|
||||
to_vector : Vector Integer
|
||||
to_vector self =
|
||||
proxy = Array_Proxy.new self.length self.at
|
||||
proxy = Array_Proxy.new self.length (self.at _)
|
||||
Vector.from_polyglot_array proxy
|
||||
|
||||
|
||||
## ICON preparation
|
||||
Combines all the elements of a non-empty range using a binary operation.
|
||||
If the range is empty, returns `if_empty`.
|
||||
|
@ -127,9 +127,9 @@ Text.each self function =
|
||||
Get the individual characters in the text "건반(Korean)".
|
||||
|
||||
"건반(Korean)".at 1 == "반"
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length display=Display.Always)
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
Text.at : Integer -> Text ! Index_Out_Of_Bounds
|
||||
Text.at self index =
|
||||
Text.at self index:Integer=0 =
|
||||
self.get index (Error.throw (Index_Out_Of_Bounds.Error index self.length))
|
||||
|
||||
## ALIAS get character
|
||||
@ -154,9 +154,9 @@ Text.at self index =
|
||||
Get the individual characters in the text "건반(Korean)".
|
||||
|
||||
"건반(Korean)".get 1 == "반"
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length display=Display.Always)
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
Text.get : Integer -> Any -> Any
|
||||
Text.get self index ~if_missing=Nothing =
|
||||
Text.get self index:Integer=0 ~if_missing=Nothing =
|
||||
new_index = if index < 0 then index + self.length else index
|
||||
if new_index < 0 then if_missing else
|
||||
iterator = BreakIterator.getCharacterInstance
|
||||
|
@ -15,6 +15,7 @@ import project.Nothing.Nothing
|
||||
import project.Panic.Panic
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Range.Extensions import all
|
||||
from project.Metadata import Display, Widget
|
||||
|
||||
type Match
|
||||
## PRIVATE
|
||||
@ -299,8 +300,9 @@ type Match
|
||||
Arguments:
|
||||
- id: The integer index or name of that group.
|
||||
- if_missing: The value to return if the index is out of bounds.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.pattern.group_count display=Display.Always)
|
||||
get : Integer -> Any -> Text | Any
|
||||
get self index ~if_missing=Nothing =
|
||||
get self index:Integer=0 ~if_missing=Nothing =
|
||||
self.text index . catch No_Such_Group (_-> if_missing)
|
||||
|
||||
## GROUP Selections
|
||||
@ -312,6 +314,7 @@ type Match
|
||||
Arguments:
|
||||
- id: The integer index or name of that group.
|
||||
- if_missing: The value to return if the index is out of bounds.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.pattern.group_count display=Display.Always)
|
||||
at : Integer -> Text ! Index_Out_Of_Bounds
|
||||
at self index =
|
||||
at self index:Integer=0 =
|
||||
self.get index if_missing=(Error.throw (Index_Out_Of_Bounds.Error index self.pattern.group_count))
|
||||
|
@ -18,6 +18,7 @@ import project.Nothing.Nothing
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Filter_Condition import unify_condition_or_predicate, unify_condition_predicate_or_element
|
||||
from project.Data.Range.Extensions import all
|
||||
from project.Metadata import Display, Widget
|
||||
from project.Runtime import assert
|
||||
|
||||
polyglot java import org.enso.base.Time_Utils
|
||||
@ -161,8 +162,9 @@ type Date_Range
|
||||
Get the last element of a range with step.
|
||||
|
||||
(Date.new 2023 04 05) . up_to (Date.new 2023 10 07) . with_step Date_Period.Month . get -1 == (Date.new 2023 10 05)
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
at : Integer -> Any ! Index_Out_Of_Bounds
|
||||
at self index =
|
||||
at self index:Integer=0 =
|
||||
self.get index (Error.throw (Index_Out_Of_Bounds.Error index self.length))
|
||||
|
||||
## ICON parse3
|
||||
@ -174,8 +176,9 @@ type Date_Range
|
||||
also allowed be negative, then the elements are indexed from the back,
|
||||
i.e. -1 will correspond to the last element.
|
||||
- if_missing: The value to return if the index is out of bounds.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
get : Integer -> Any -> Any
|
||||
get self index ~if_missing=Nothing =
|
||||
get self index:Integer=0 ~if_missing=Nothing =
|
||||
len = self.length
|
||||
effective_index = if index < 0 then len + index else index
|
||||
if effective_index >= 0 && effective_index < len then self.internal_at effective_index else
|
||||
@ -214,7 +217,7 @@ type Date_Range
|
||||
(Date.new 2021 05 07).up_to (Date.new 2021 05 10) . to_vector
|
||||
to_vector : Vector Date
|
||||
to_vector self =
|
||||
proxy = Array_Proxy.new self.length self.at
|
||||
proxy = Array_Proxy.new self.length (self.at _)
|
||||
Vector.from_polyglot_array proxy
|
||||
|
||||
## GROUP Logical
|
||||
|
@ -30,6 +30,7 @@ from project.Data.Filter_Condition import unify_condition_or_predicate, unify_co
|
||||
from project.Data.Index_Sub_Range import Index_Sub_Range
|
||||
from project.Data.Ordering import all
|
||||
from project.Data.Range.Extensions import all
|
||||
from project.Metadata import Display, Widget
|
||||
from project.Runtime import assert
|
||||
|
||||
polyglot java import java.lang.IndexOutOfBoundsException
|
||||
@ -294,8 +295,9 @@ type Vector a
|
||||
Get the last element of a vector.
|
||||
|
||||
[1, 2, 3].at -1 == 3
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
at : Integer -> Any ! Index_Out_Of_Bounds
|
||||
at self index = Array_Like_Helpers.at self index
|
||||
at self index:Integer=0 = Array_Like_Helpers.at self index
|
||||
|
||||
## ICON parse3
|
||||
Gets an element from the vector at a specified index (0-based).
|
||||
@ -306,8 +308,9 @@ type Vector a
|
||||
also allowed be negative, then the elements are indexed from the back
|
||||
of the vector, i.e. -1 will correspond to the last element.
|
||||
- if_missing: The value to return if the index is out of bounds.
|
||||
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.length-1 display=Display.Always)
|
||||
get : Integer -> Any -> Any
|
||||
get self index ~if_missing=Nothing =
|
||||
get self index:Integer=0 ~if_missing=Nothing =
|
||||
Array_Like_Helpers.get self index if_missing
|
||||
|
||||
## ICON dataframe_map_column
|
||||
@ -1440,7 +1443,7 @@ type Builder
|
||||
also allowed be negative, then the elements are indexed from the back
|
||||
of the vector, i.e. -1 will correspond to the last element.
|
||||
at : Integer -> Any ! Index_Out_Of_Bounds
|
||||
at self index =
|
||||
at self index:Integer =
|
||||
actual_index = if index < 0 then self.length + index else index
|
||||
Panic.catch IndexOutOfBoundsException (self.elements_java_builder.get actual_index) _->
|
||||
Error.throw (Index_Out_Of_Bounds.Error index self.length)
|
||||
|
@ -246,7 +246,7 @@ transpose vec_of_vecs =
|
||||
Vector.from_polyglot_array proxy
|
||||
|
||||
map vector function on_problems =
|
||||
vector_from_function vector.length (function << vector.at) on_problems
|
||||
vector_from_function vector.length (i-> function (vector.at i)) on_problems
|
||||
|
||||
map_with_index vector function on_problems =
|
||||
vector_from_function vector.length (i-> function i (vector.at i)) on_problems
|
||||
|
@ -53,6 +53,6 @@ type Nothing
|
||||
- key: The key to get.
|
||||
- if_missing: The value to return if the key is not found.
|
||||
get : Text | Integer -> Any -> Nothing
|
||||
get self key ~if_missing=Nothing =
|
||||
get self (key:(Text | Integer)=0) ~if_missing=Nothing =
|
||||
_ = key
|
||||
if_missing
|
||||
|
@ -56,7 +56,7 @@ type File_By_Line
|
||||
Arguments:
|
||||
- line: The line to read (0 indexed).
|
||||
get : Integer -> Text
|
||||
get self line:Integer = if self.limit_lines.is_nothing.not && line>self.limit_lines then Error.throw (Index_Out_Of_Bounds.Error line self.limit_lines) else
|
||||
get self line:Integer=0 = if self.limit_lines.is_nothing.not && line>self.limit_lines then Error.throw (Index_Out_Of_Bounds.Error line self.limit_lines) else
|
||||
read_line self line
|
||||
|
||||
## GROUP Selections
|
||||
@ -207,7 +207,7 @@ type File_By_Line
|
||||
Exports the row_map
|
||||
row_positions : Vector Integer
|
||||
row_positions self = Vector.from_polyglot_array <|
|
||||
Array_Proxy.new self.row_map.getSize (i-> self.row_map.get i)
|
||||
Array_Proxy.new self.row_map.getSize (self.row_map.get _)
|
||||
|
||||
## PRIVATE
|
||||
Gets the Java_File for the backing file.
|
||||
|
@ -137,7 +137,7 @@ type DB_Column
|
||||
|
||||
example_at = Examples.integer_column.at 0
|
||||
at : Integer -> (Any | Nothing) ! Index_Out_Of_Bounds
|
||||
at self (index : Integer) =
|
||||
at self index:Integer=0 =
|
||||
self.get index (Error.throw (Index_Out_Of_Bounds.Error index self.length))
|
||||
|
||||
## GROUP Standard.Base.Selections
|
||||
@ -155,7 +155,7 @@ type DB_Column
|
||||
|
||||
example_at = Examples.integer_column.get 0 -1
|
||||
get : Integer -> Any -> Any | Nothing
|
||||
get self (index : Integer) (~default=Nothing) =
|
||||
get self index:Integer=0 (~default=Nothing) =
|
||||
self.read (..First index+1) . get index default
|
||||
|
||||
## GROUP Standard.Base.Metadata
|
||||
|
@ -136,7 +136,7 @@ type DB_Table
|
||||
- selector: The name or index of the column to get.
|
||||
@selector Widget_Helpers.make_column_name_selector
|
||||
at : Text | Integer -> DB_Column ! No_Such_Column | Index_Out_Of_Bounds
|
||||
at self selector=0 = case selector of
|
||||
at self (selector:(Integer | Text)=0) = case selector of
|
||||
_ : Integer -> self.make_column (self.internal_columns.at selector)
|
||||
_ -> self.get selector (Error.throw (No_Such_Column.Error selector))
|
||||
|
||||
@ -148,11 +148,10 @@ type DB_Table
|
||||
- if_missing: The value to use if the selector isn't present.
|
||||
@selector Widget_Helpers.make_column_name_selector
|
||||
get : Text | Integer -> Any -> DB_Column | Any
|
||||
get self selector=0 ~if_missing=Nothing =
|
||||
get self (selector:(Integer | Text)=0) ~if_missing=Nothing =
|
||||
internal_column = case selector of
|
||||
_ : Integer -> self.internal_columns.get selector if_missing=Nothing
|
||||
_ : Text -> self.internal_columns.find (p -> p.name == selector) if_missing=Nothing
|
||||
_ -> Error.throw (Illegal_Argument.Error "expected 'selector' to be either a Text or an Integer, but got "+(Meta.get_simple_type_name selector)+".")
|
||||
if internal_column.is_nothing then if_missing else self.make_column internal_column
|
||||
|
||||
## ALIAS cell value, get cell
|
||||
|
@ -2140,7 +2140,7 @@ type Column
|
||||
example_at = Examples.integer_column.at 0
|
||||
@index (self-> Numeric_Input minimum=0 maximum=self.length-1)
|
||||
at : Integer -> (Any | Nothing) ! Index_Out_Of_Bounds
|
||||
at self (index : Integer) =
|
||||
at self index:Integer=0 =
|
||||
self.get index (Error.throw (Index_Out_Of_Bounds.Error index self.length))
|
||||
|
||||
## GROUP Standard.Base.Selections
|
||||
@ -2159,7 +2159,7 @@ type Column
|
||||
example_at = Examples.integer_column.get 0 -1
|
||||
@index (self-> Numeric_Input minimum=0 maximum=self.length-1)
|
||||
get : Integer -> Any -> Any | Nothing
|
||||
get self (index : Integer) (~default=Nothing) =
|
||||
get self index:Integer=0 (~default=Nothing) =
|
||||
valid_index = (index >= 0) && (index < self.length)
|
||||
if valid_index.not then default else
|
||||
storage = self.java_column.getStorage
|
||||
@ -2321,7 +2321,7 @@ type Column
|
||||
@range Index_Sub_Range.default_widget
|
||||
take : (Index_Sub_Range | Range | Integer) -> Column
|
||||
take self range=(First 1) =
|
||||
Index_Sub_Range_Module.take_helper self.length self.at self.slice (slice_ranges self) range
|
||||
Index_Sub_Range_Module.take_helper self.length (self.at _) self.slice (slice_ranges self) range
|
||||
|
||||
## ALIAS skip, remove
|
||||
GROUP Standard.Base.Selections
|
||||
@ -2334,7 +2334,7 @@ type Column
|
||||
@range Index_Sub_Range.default_widget
|
||||
drop : (Index_Sub_Range | Range | Integer) -> Column
|
||||
drop self range=(First 1) =
|
||||
Index_Sub_Range_Module.drop_helper self.length self.at self.slice (slice_ranges self) range
|
||||
Index_Sub_Range_Module.drop_helper self.length (self.at _) self.slice (slice_ranges self) range
|
||||
|
||||
## PRIVATE
|
||||
Returns a column with a continuous sub-range of rows taken.
|
||||
|
@ -17,7 +17,7 @@ type Convertible_To_Columns
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Columns.from (that:JS_Object) =
|
||||
Convertible_To_Columns.Value that.field_names that.get
|
||||
Convertible_To_Columns.Value that.field_names (that.get _)
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Columns.from (that:Map) =
|
||||
@ -38,7 +38,7 @@ Convertible_To_Columns.from (that:Column) =
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Columns.from (that:Row) =
|
||||
Convertible_To_Columns.Value that.column_names that.get
|
||||
Convertible_To_Columns.Value that.column_names (that.get _)
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Columns.from (that:Vector) =
|
||||
|
@ -33,35 +33,35 @@ Convertible_To_Rows.from that:Table =
|
||||
Convertible_To_Rows.from rows
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:Column = Convertible_To_Rows.Value that.length that.get
|
||||
Convertible_To_Rows.from that:Column = Convertible_To_Rows.Value that.length (that.get _)
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:Vector = Convertible_To_Rows.Value that.length that.get
|
||||
Convertible_To_Rows.from that:Vector = Convertible_To_Rows.Value that.length (that.get _)
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:Array = Convertible_To_Rows.Value that.length that.get
|
||||
Convertible_To_Rows.from that:Array = Convertible_To_Rows.Value that.length (that.get _)
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:List = Convertible_To_Rows.from that.to_vector
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:Range = Convertible_To_Rows.Value that.length that.get
|
||||
Convertible_To_Rows.from that:Range = Convertible_To_Rows.Value that.length (that.get _)
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:Pair = Convertible_To_Rows.Value that.length that.get
|
||||
Convertible_To_Rows.from that:Pair = Convertible_To_Rows.Value that.length (that.get _)
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:Date_Range = Convertible_To_Rows.Value that.length that.get
|
||||
Convertible_To_Rows.from that:Date_Range = Convertible_To_Rows.Value that.length (that.get _)
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:Map =
|
||||
vals = that.to_vector.map p-> Key_Value.Pair p.first p.second
|
||||
Convertible_To_Rows.Value vals.length vals.get ["Key", "Value"]
|
||||
Convertible_To_Rows.Value vals.length (vals.get _) ["Key", "Value"]
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from that:JS_Object =
|
||||
vals = that.map_with_key k->v-> Key_Value.Pair k v
|
||||
Convertible_To_Rows.Value vals.length vals.get ["Key", "Value"]
|
||||
Convertible_To_Rows.Value vals.length (vals.get _) ["Key", "Value"]
|
||||
|
||||
## PRIVATE
|
||||
Convertible_To_Rows.from (that:Any) =
|
||||
|
@ -5,7 +5,7 @@ import Standard.Base.System.File.Generic.Writable_File.Writable_File
|
||||
import Standard.Base.System.File_Format_Metadata.File_Format_Metadata
|
||||
import Standard.Base.System.Input_Stream.Input_Stream
|
||||
from Standard.Base.Metadata.Choice import Option
|
||||
from Standard.Base.Metadata.Widget import Numeric_Input, Text_Input
|
||||
from Standard.Base.Metadata.Widget import Text_Input
|
||||
from Standard.Base.System.File_Format import parse_boolean_with_infer
|
||||
|
||||
import project.Excel.Excel_Range.Excel_Range
|
||||
|
@ -1,4 +1,5 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Deprecated.Deprecated
|
||||
import Standard.Base.Errors.File_Error.File_Error
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
@ -73,13 +74,15 @@ type Excel_Workbook
|
||||
Creates an Excel_Workbook connection.
|
||||
Value (excel_connection_resource_ref : Ref (Managed_Resource ReadOnlyExcelConnection)) (file:(File|Temporary_File|Nothing)) xls_format:Boolean
|
||||
|
||||
## ICON metadata
|
||||
## PRIVATE
|
||||
ICON metadata
|
||||
Returns the list of databases (or catalogs) for the connection.
|
||||
databases : Nothing
|
||||
databases self = Nothing
|
||||
|
||||
## ICON metadata
|
||||
Returns the name of the current database (or catalog).
|
||||
## PRIVATE
|
||||
ICON metadata
|
||||
Returns the name of the current file.
|
||||
database : Text
|
||||
database self = case self.file of
|
||||
regular_file : File -> regular_file.path
|
||||
@ -87,31 +90,34 @@ type Excel_Workbook
|
||||
just an implementation detail - it is coming form a stream so there is no logical file it is associated with.
|
||||
_ -> ""
|
||||
|
||||
## ICON data_input
|
||||
Returns a new Connection with the specified database set as default.
|
||||
## PRIVATE
|
||||
ICON data_input
|
||||
Returns a new Workbook with the specified file.
|
||||
|
||||
Arguments:
|
||||
- database: The name of the database to connect to.
|
||||
@database (Single_Choice display=Display.Always values=[Option 'Nothing'])
|
||||
set_database : Text -> Excel_Workbook ! Illegal_Argument
|
||||
- database: The target file to open as an Excel_Workbook.
|
||||
set_database : Text | File -> Excel_Workbook ! Illegal_Argument
|
||||
set_database self database =
|
||||
if database == self.database then self else
|
||||
file = File.new database
|
||||
if file.exists && file.is_directory.not then Excel_Workbook.new file self.xls_format else
|
||||
Error.throw (Illegal_Argument.Error "The specified file ('"+file.path+"') does not exist.")
|
||||
|
||||
## ICON metadata
|
||||
## PRIVATE
|
||||
ICON metadata
|
||||
Returns the list of schemas for the connection within the current database (or catalog).
|
||||
schemas : Vector (Text | Nothing)
|
||||
schemas self = [Nothing]
|
||||
|
||||
## ICON metadata
|
||||
## PRIVATE
|
||||
ICON metadata
|
||||
Returns the name of the current schema.
|
||||
schema : Text | Nothing
|
||||
schema self = Nothing
|
||||
|
||||
## ICON data_input
|
||||
Returns a new Connection with the specified schema set as default.
|
||||
## PRIVATE
|
||||
ICON data_input
|
||||
Returns a new Workbook with the specified schema set as default.
|
||||
|
||||
Arguments:
|
||||
- schema: The name of the schema to connect to.
|
||||
@ -147,12 +153,14 @@ type Excel_Workbook
|
||||
named_ranges self = self.with_java_workbook java_workbook->
|
||||
Vector.from_polyglot_array (ExcelReader.readRangeNames java_workbook)
|
||||
|
||||
## ICON metadata
|
||||
## PRIVATE
|
||||
ICON metadata
|
||||
Gets a list of the table types.
|
||||
table_types : Vector Text
|
||||
table_types self = ['Worksheet', 'Named Range']
|
||||
|
||||
## GROUP Standard.Base.Metadata
|
||||
## PRIVATE
|
||||
GROUP Standard.Base.Metadata
|
||||
ICON metadata
|
||||
Returns a materialised Table of all the matching views and tables.
|
||||
|
||||
@ -182,7 +190,8 @@ type Excel_Workbook
|
||||
|
||||
Table.from_rows ['Name', 'Type', 'Database', 'Schema'] filtered
|
||||
|
||||
## ICON data_input
|
||||
## PRIVATE
|
||||
ICON data_input
|
||||
Read a range into a Table.
|
||||
|
||||
Arguments:
|
||||
@ -196,7 +205,7 @@ type Excel_Workbook
|
||||
_ = [alias]
|
||||
self.read query headers=headers
|
||||
|
||||
## ALIAS range, sheet, worksheet
|
||||
## ALIAS range, sheet, worksheet, get
|
||||
GROUP Standard.Base.Input
|
||||
ICON data_input
|
||||
Read a range into a Table.
|
||||
@ -219,7 +228,8 @@ type Excel_Workbook
|
||||
_ : Text -> ExcelReader.readRangeByName java_workbook query java_headers 0 java_limit java_problem_aggregator
|
||||
limit.attach_warning (Table.Value java_table)
|
||||
|
||||
## GROUP Standard.Base.Input
|
||||
## PRIVATE
|
||||
GROUP Standard.Base.Input
|
||||
ICON data_input
|
||||
Read an Excel_Section from the Workbook
|
||||
|
||||
@ -251,7 +261,7 @@ type Excel_Workbook
|
||||
_ : Text -> ExcelReader.readRangeByName java_workbook address java_headers skip_rows java_limit java_problem_aggregator
|
||||
row_limit.attach_warning (Table.Value java_table)
|
||||
|
||||
## ALIAS get, worksheet
|
||||
## PRIVATE
|
||||
GROUP Standard.Base.Input
|
||||
ICON data_input
|
||||
Reads a worksheet from the workbook.
|
||||
@ -263,7 +273,8 @@ type Excel_Workbook
|
||||
@name (self-> Single_Choice display=Display.Always values=(self.sheet_names.map t-> Option t t.pretty))
|
||||
sheet : Text | Integer -> Headers -> Table
|
||||
sheet self name:(Text | Integer) headers:Headers=Headers.Detect_Headers =
|
||||
self.read_section (Excel_Section.Worksheet name headers 0 Nothing)
|
||||
Warning.attach (Deprecated.Warning "Standard.Table.Excel.Excel_Workbook.Excel_Workbook" "sheet" "Deprecated: use `read` instead.") <|
|
||||
self.read_section (Excel_Section.Worksheet name headers 0 Nothing)
|
||||
|
||||
## PRIVATE
|
||||
ADVANCED
|
||||
|
@ -18,4 +18,4 @@ type Rows_View
|
||||
ICON parse3
|
||||
Gets the specified row.
|
||||
at : Integer -> Any
|
||||
at self index = Row.Value self.table index
|
||||
at self index:Integer=0 = Row.Value self.table index
|
||||
|
@ -29,7 +29,7 @@ type Row
|
||||
- column: The name or index of the column being looked up.
|
||||
@column (self -> Widget_Helpers.make_column_name_selector self.table)
|
||||
at : (Integer | Text) -> Any
|
||||
at self column = self.table.at column . at self.index
|
||||
at self (column:(Integer | Text)=0) = self.table.at column . at self.index
|
||||
|
||||
## ICON parse3
|
||||
Gets the value of the specified column.
|
||||
@ -39,7 +39,7 @@ type Row
|
||||
- if_missing: The value to use if the column isn't present.
|
||||
@column (self -> Widget_Helpers.make_column_name_selector self.table)
|
||||
get : (Integer | Text) -> Any -> Any
|
||||
get self column ~if_missing=Nothing =
|
||||
get self (column:(Integer | Text)=0) ~if_missing=Nothing =
|
||||
table_column = self.table.get column
|
||||
case table_column of
|
||||
Nothing -> if_missing
|
||||
|
@ -245,7 +245,7 @@ type Table
|
||||
example_at = Examples.inventory_table.at -1
|
||||
@selector Widget_Helpers.make_column_name_selector
|
||||
at : Text | Integer -> Column ! No_Such_Column | Index_Out_Of_Bounds
|
||||
at self selector=0 = case selector of
|
||||
at self (selector:(Integer | Text)=0) = case selector of
|
||||
_ : Integer ->
|
||||
java_columns = Vector.from_polyglot_array self.java_table.getColumns
|
||||
Column.Value (java_columns.at selector)
|
||||
@ -273,11 +273,10 @@ type Table
|
||||
example_at = Examples.inventory_table.get -1
|
||||
@selector Widget_Helpers.make_column_name_selector
|
||||
get : Text | Integer -> Any -> Column | Any
|
||||
get self selector=0 ~if_missing=Nothing =
|
||||
get self (selector:(Integer | Text)=0) ~if_missing=Nothing =
|
||||
java_column = case selector of
|
||||
_ : Integer -> Vector.from_polyglot_array self.java_table.getColumns . get selector
|
||||
_ : Text -> self.java_table.getColumnByName selector
|
||||
_ -> Error.throw (Illegal_Argument.Error "expected 'selector' to be either a Text or an Integer, but got "+(Meta.get_simple_type_name selector)+".")
|
||||
if java_column.is_nothing then if_missing else Column.Value java_column
|
||||
|
||||
## ALIAS cell value, get cell
|
||||
@ -1571,7 +1570,7 @@ type Table
|
||||
@range Index_Sub_Range.default_widget
|
||||
take : (Index_Sub_Range | Range | Integer) -> Table
|
||||
take self range=(First 1) =
|
||||
Index_Sub_Range_Module.take_helper self.row_count self.rows.at self.slice (slice_ranges self) range
|
||||
Index_Sub_Range_Module.take_helper self.row_count (self.rows.at _) self.slice (slice_ranges self) range
|
||||
|
||||
## ALIAS skip, remove
|
||||
GROUP Standard.Base.Selections
|
||||
@ -1603,7 +1602,7 @@ type Table
|
||||
@range Index_Sub_Range.default_widget
|
||||
drop : (Index_Sub_Range | Range | Integer) -> Table
|
||||
drop self range=(First 1) =
|
||||
Index_Sub_Range_Module.drop_helper self.row_count self.rows.at self.slice (slice_ranges self) range
|
||||
Index_Sub_Range_Module.drop_helper self.row_count (self.rows.at _) self.slice (slice_ranges self) range
|
||||
|
||||
## PRIVATE
|
||||
Filter out all rows.
|
||||
|
@ -31,7 +31,7 @@ get_lazy_visualization_text_window text pos size chunk_width =
|
||||
y_range = pos_y.up_to ((pos_y + size_y).min lines)
|
||||
coordinates = x_range.map (x -> y_range.map (y -> [x,y])) . flatten
|
||||
chunks = coordinates.map (ix -> [ix, (get_text_chunk ix)])
|
||||
active_lines = y_range.map text.lines.at
|
||||
active_lines = y_range.map (text.lines.at _)
|
||||
max_line_length = (active_lines.map (line -> line.length)).fold 0 (l -> r -> l.max r)
|
||||
make_grid_visualization_response chunks lines max_line_length
|
||||
|
||||
|
@ -116,8 +116,7 @@ add_specs suite_builder setup =
|
||||
data.table.at 100 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
group_builder.specify "should fail with Type Error is not an Integer or Text" <|
|
||||
data.table.at (Pair.new 1 2) . should_fail_with Illegal_Argument
|
||||
data.table.at (Pair.new 1 2) . catch . to_display_text . should_equal "Illegal Argument: expected 'selector' to be either a Text or an Integer, but got Pair."
|
||||
Test.expect_panic_with (data.table.at (Pair.new 1 2)) Type_Error
|
||||
|
||||
suite_builder.group prefix+"Table.get" group_builder->
|
||||
data = Data.setup create_connection_fn setup.table_builder
|
||||
@ -150,8 +149,7 @@ add_specs suite_builder setup =
|
||||
data.table.get 100 column_1 . name . should_equal "foo"
|
||||
|
||||
group_builder.specify "should fail with Type Error is not an Integer or Text" <|
|
||||
data.table.get (Pair.new 1 2) . should_fail_with Illegal_Argument
|
||||
data.table.get (Pair.new 1 2) . catch . to_display_text . should_equal "Illegal Argument: expected 'selector' to be either a Text or an Integer, but got Pair."
|
||||
Test.expect_panic_with (data.table.at (Pair.new 1 2)) Type_Error
|
||||
|
||||
suite_builder.group prefix+"Table.set" group_builder->
|
||||
data = Data.setup create_connection_fn setup.table_builder
|
||||
|
@ -205,8 +205,8 @@ add_specs suite_builder setup =
|
||||
|
||||
rnd = data.table.take (Sample 3 seed=42)
|
||||
random_indices = [5, 6, 2]
|
||||
alpha_sample = random_indices.map (data.table.at "alpha" . to_vector . at)
|
||||
beta_sample = random_indices.map (data.table.at "beta" . to_vector . at)
|
||||
alpha_sample = random_indices.map (data.table.at "alpha" . to_vector . at _)
|
||||
beta_sample = random_indices.map (data.table.at "beta" . to_vector . at _)
|
||||
rnd.at "alpha" . to_vector . should_equal alpha_sample
|
||||
rnd.at "beta" . to_vector . should_equal beta_sample
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user