Skip to content

Commit

Permalink
Merge pull request #297 from nfdi4plants/table_join_296
Browse files Browse the repository at this point in the history
Extend ArcTable.Join logic
  • Loading branch information
HLWeil authored Jan 22, 2024
2 parents a0144e1 + 13428ca commit 70d3c85
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ and __JavaScript__! ❤️
| Version | Downloads |
| :--------|-----------:|
|<a href="https://www.nuget.org/packages/ARCtrl/"><img alt="Nuget" src="https://img.shields.io/nuget/vpre/ARCtrl?logo=nuget&color=%234fb3d9"></a>|<a href="https://www.nuget.org/packages/ARCtrl/"><img alt="Nuget" src="https://img.shields.io/nuget/dt/ARCtrl?color=%234FB3D9"></a>|
|<a href="https://www.npmjs.com/package/@nfdi4plants/arctrl"><img alt="NPM" src="https://img.shields.io/npm/v/%40nfdi4plants/arctrl/next?logo=npm&color=%234fb3d9"></a>|<a href="https://www.npmjs.com/package/@nfdi4plants/arctrl"><img alt="NPM" src="https://img.shields.io/npm/dt/%40nfdi4plants%2Farctrl?color=%234fb3d9"></a>|
|<a href="https://www.npmjs.com/package/@nfdi4plants/arctrl"><img alt="NPM" src="https://img.shields.io/npm/v/%40nfdi4plants/arctrl?logo=npm&color=%234fb3d9"></a>|<a href="https://www.npmjs.com/package/@nfdi4plants/arctrl"><img alt="NPM" src="https://img.shields.io/npm/dt/%40nfdi4plants%2Farctrl?color=%234fb3d9"></a>|


## Install
Expand Down
10 changes: 10 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### 1.0.5+b21e3bc (Released 2024-1-17)
* Additions:
* [[#b21e3bc](https://github.com/nfdi4plants/ARCtrl/commit/b21e3bcb0a5679b5ec5494555d9e9d23822bdc9a)] Extend ArcTable.Join :sparkles::white_check_mark:
* [[#a112468](https://github.com/nfdi4plants/ARCtrl/commit/a1124684ea02d23301b67743ff761112fe9389ab)] Update readme badge
* [[#a0144e1](https://github.com/nfdi4plants/ARCtrl/commit/a0144e1282bb1e8206378eb6bb8b23619eb666e6)] Merge pull request #295 from nfdi4plants/Freymaurer-patch-1
* [[#9e5c1f6](https://github.com/nfdi4plants/ARCtrl/commit/9e5c1f67b676d63dcb69b586089e1e74ca1c2814)] Update README.md
* [[#6e0755b](https://github.com/nfdi4plants/ARCtrl/commit/6e0755b5e1c28bb72814247dad1e4ab457e25e40)] update and release version 1.0.4
* Bugfixes:
* [[#8dd99e8](https://github.com/nfdi4plants/ARCtrl/commit/8dd99e82fc93add2950860d6eb185686be21f9ba)] Merge pull request #294 from nfdi4plants/fix_annotationValue_read

### 1.0.4+167fae8 (Released 2024-1-15)
* Additions:
* [[#167fae8](https://github.com/nfdi4plants/ARCtrl/commit/167fae8bcaa14d8e24055f60ac031b13d8b47199)] add json functions for better function names in js :sparkles:
Expand Down
2 changes: 1 addition & 1 deletion build/release_package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nfdi4plants/arctrl",
"version": "1.0.4+167fae8",
"version": "1.0.5+b21e3bc",
"description": "Top level ARC DataModel and API function descriptions.",
"type": "module",
"main": "index.js",
Expand Down
14 changes: 9 additions & 5 deletions src/ISA/ISA/ArcTypes/ArcTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,17 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, values: Syste
/// <summary>
/// This function can be used to join two arc tables.
/// </summary>
/// <param name="index">If not set default to append. -1 will also append.</param>
/// <param name="table">The table to join to this table.</param>
/// <param name="joinOptions">Can add only headers, header with unitized cell information, headers with values.</param>
/// <param name="forceReplace">if set to true will replace unique columns.</param>
member this.Join(table:ArcTable, ?joinOptions: TableJoinOptions, ?forceReplace: bool, ?SkipFillMissing) : unit =
member this.Join(table:ArcTable, ?index: int, ?joinOptions: TableJoinOptions, ?forceReplace: bool, ?skipFillMissing) : unit =
let joinOptions = defaultArg joinOptions TableJoinOptions.Headers
let forceReplace = defaultArg forceReplace false
let skipFillMissing = defaultArg skipFillMissing false
let mutable index = defaultArg index this.ColumnCount
index <- if index = -1 then this.ColumnCount else index //make -1 default to append to make function usage more fluent.
SanityChecks.validateColumnIndex index this.ColumnCount true
let onlyHeaders = joinOptions = TableJoinOptions.Headers
let columns =
let pre = table.Columns
Expand All @@ -528,20 +533,19 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, values: Syste
| WithValues -> pre
SanityChecks.validateNoDuplicateUniqueColumns columns
columns |> Array.iter (fun x -> SanityChecks.validateColumn x)
let mutable index = this.ColumnCount
columns
|> Array.iter (fun col ->
let prevHeadersCount = this.Headers.Count
Unchecked.addColumn col.Header col.Cells index forceReplace onlyHeaders this.Headers this.Values
// Check if more headers, otherwise `ArcTableAux.insertColumn` replaced a column and we do not need to increase index.
if this.Headers.Count > prevHeadersCount then index <- index + 1
)
if not(SkipFillMissing = Some true) then Unchecked.fillMissingCells this.Headers this.Values
if not(skipFillMissing) then Unchecked.fillMissingCells this.Headers this.Values

static member join(table:ArcTable, ?joinOptions: TableJoinOptions, ?forceReplace: bool) =
static member join(table:ArcTable, ?index: int, ?joinOptions: TableJoinOptions, ?forceReplace: bool) =
fun (this: ArcTable) ->
let copy = this.Copy()
copy.Join(table,?joinOptions=joinOptions,?forceReplace=forceReplace)
copy.Join(table,?index=index,?joinOptions=joinOptions,?forceReplace=forceReplace)
copy

static member insertParameterValue (t : ArcTable) (p : ProcessParameterValue) : ArcTable =
Expand Down
50 changes: 41 additions & 9 deletions tests/ISA/ISA.Tests/ArcTable.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2081,11 +2081,43 @@ let private tests_UpdateRefWithSheet =
]

let private tests_Join = testList "Join" [
testList "index" [
testCase "ensure default is append" <| fun _ ->
let table1 = create_testTable()
let columnCount = table1.ColumnCount
let table2 = create_testTable()
table2.RemoveColumn 0 // rmv input
table2.RemoveColumn 0 // rmv output
let expectedJoinCount = columnCount + table2.ColumnCount
table1.Join(table2)
Expect.equal table1.ColumnCount expectedJoinCount "new column count"
Expect.equal (table1.Headers.[columnCount]) (table2.Headers.[0]) "column equal"
testCase "ensure -1 defaults to append" <| fun _ ->
let table1 = create_testTable()
let columnCount = table1.ColumnCount
let table2 = create_testTable()
table2.RemoveColumn 0 // rmv input
table2.RemoveColumn 0 // rmv output
let expectedJoinCount = columnCount + table2.ColumnCount
table1.Join(table2,-1)
Expect.equal table1.ColumnCount expectedJoinCount "new column count"
Expect.equal (table1.Headers.[columnCount]) (table2.Headers.[0]) "column equal"
testCase "insert at start" <| fun _ ->
let table1 = create_testTable()
let columnCount = table1.ColumnCount
let table2 = create_testTable()
table2.RemoveColumn 0 // rmv input
table2.RemoveColumn 0 // rmv output
let expectedJoinCount = columnCount + table2.ColumnCount
table1.Join(table2,0)
Expect.equal table1.ColumnCount expectedJoinCount "new column count"
Expect.equal (table1.Headers.[0]) (table2.Headers.[0]) "column equal"
]
testList "TableJoinOption.Headers" [
testCase "Add to empty" <| fun _ ->
let table = ArcTable.init("MyTable")
let joinTable = create_testTable()
table.Join(joinTable,TableJoinOptions.Headers)
table.Join(joinTable,-1,TableJoinOptions.Headers)
Expect.equal table.ColumnCount 5 "columnCount"
// test headers
Expect.equal table.Headers.[0] (CompositeHeader.Input IOType.Source) "Header input"
Expand All @@ -2098,12 +2130,12 @@ let private tests_Join = testList "Join" [
testCase "Add to duplicate" <| fun _ ->
let table = create_testTable()
let joinTable = create_testTable()
let func = fun () -> table.Join(joinTable,TableJoinOptions.Headers)
let func = fun () -> table.Join(joinTable,-1,TableJoinOptions.Headers)
Expect.throws func "This should fail as we try to add multiple inputs/outputs to one table"
testCase "Add to duplicate, forceReplace" <| fun _ ->
let table = create_testTable()
let joinTable = create_testTable()
table.Join(joinTable,TableJoinOptions.Headers, true)
table.Join(joinTable,-1,TableJoinOptions.Headers,true)
Expect.equal table.ColumnCount 8 "We expect 8 columns as there are 5 per table with 2 unique 5 + (5-2) = 8"
// headers
Expect.equal table.Headers.[0] (CompositeHeader.Input IOType.Source) "Header input"
Expand All @@ -2123,7 +2155,7 @@ let private tests_Join = testList "Join" [
ResizeArray([CompositeHeader.Input IOType.ImageFile]),
System.Collections.Generic.Dictionary()
)
table.Join(joinTable,TableJoinOptions.Headers, true)
table.Join(joinTable,-1,TableJoinOptions.Headers,true)
Expect.equal table.ColumnCount 5 "columnCount"
// test headers
Expect.equal table.Headers.[0] (CompositeHeader.Input IOType.ImageFile) "Here should be new image input"
Expand All @@ -2142,7 +2174,7 @@ let private tests_Join = testList "Join" [
column_component
|]
joinTable.AddColumns(columns)
table.Join(joinTable,TableJoinOptions.WithUnit)
table.Join(joinTable,-1,TableJoinOptions.WithUnit)
Expect.equal table.ColumnCount 1 "column count"
Expect.equal table.RowCount 0 "row count"
testCase "Add to empty, with unit" <| fun _ ->
Expand All @@ -2158,11 +2190,11 @@ let private tests_Join = testList "Join" [
)
|]
joinTable.AddColumns(columns)
table.Join(joinTable,TableJoinOptions.WithUnit)
table.Join(joinTable,-1,TableJoinOptions.WithUnit, skipFillMissing=false)
Expect.equal table.ColumnCount 2 "column count"
Expect.equal table.RowCount 5 "row count"
Expect.equal table.Values.[0,0] (CompositeCell.createTerm OntologyAnnotation.empty) "empty term cell"
Expect.equal table.Values.[1,0] (CompositeCell.createUnitized("",oa_temperature)) "temperature unit cell"
Expect.equal table.Values.[(0,0)] (CompositeCell.createTerm OntologyAnnotation.empty) "empty term cell"
Expect.equal table.Values.[(1,0)] (CompositeCell.createUnitized("",oa_temperature)) "temperature unit cell"
]
testList "TableJoinOption.WithValues" [
testCase "Add to empty" <| fun _ ->
Expand All @@ -2178,7 +2210,7 @@ let private tests_Join = testList "Join" [
)
|]
joinTable.AddColumns(columns)
table.Join(joinTable,TableJoinOptions.WithValues)
table.Join(joinTable,-1,TableJoinOptions.WithValues)
Expect.equal table.ColumnCount 2 "column count"
Expect.equal table.RowCount 5 "row count"
Expect.equal table.Values.[0,0] (CompositeCell.createTerm oa_SCIEXInstrumentModel) "sciex instrument model"
Expand Down

0 comments on commit 70d3c85

Please sign in to comment.