@@ -295,6 +295,41 @@ DataFrameTest >> testAddRowSizeMismatch [
295295 self should: aBlock raise: SizeMismatch
296296]
297297
298+ { #category : #tests }
299+ DataFrameTest >> testApplyElementwise [
300+
301+ | dataFrame expected |
302+ dataFrame := DataFrame
303+ withRows:
304+ #( #( 1.1 1.7 1.3 ) #( 2.2 2.4 2.8 ) #( 3.5 3.2 3.3 ) )
305+ rowNames: #( A B C )
306+ columnNames: #( 1 2 3 ) .
307+ expected := DataFrame
308+ withRows: #( #( 1 1 1 ) #( 2 2 2 ) #( 3 3 3 ) )
309+ rowNames: #( A B C )
310+ columnNames: #( 1 2 3 ) .
311+
312+ dataFrame applyElementwise: [ :value | value floor ].
313+ self assert: dataFrame equals: expected
314+ ]
315+
316+ { #category : #tests }
317+ DataFrameTest >> testApplyToAllColumns [
318+
319+ | dataFrame actual expected |
320+ dataFrame := DataFrame
321+ withRows: #( #( 1 4 7 ) #( 2 5 8 ) #( 3 6 9 ) )
322+ rowNames: #( A B C )
323+ columnNames: #( 1 2 3 ) .
324+ expected := DataSeries
325+ withKeys: #( 1 2 3 )
326+ values: #( 3 6 9 )
327+ name: ' max' .
328+
329+ actual := dataFrame applyToAllColumns: #max .
330+ self assert: actual equals: expected
331+ ]
332+
298333{ #category : #tests }
299334DataFrameTest >> testAsArray [
300335
@@ -328,6 +363,20 @@ DataFrameTest >> testAsArrayOfRows [
328363 self assert: df asArrayOfRows equals: (expected collect: [ :e | e asArray ])
329364]
330365
366+ { #category : #tests }
367+ DataFrameTest >> testAsArrayOfRowsWithName [
368+
369+ | expected |
370+ expected := {
371+ #( 'A' 'Barcelona' 1.609 true ) asArray.
372+ #( 'B' 'Dubai' 2.789 true ) asArray.
373+ #( 'C' 'London' 8.788 false ) asArray }.
374+
375+ self
376+ assert: df asArrayOfRowsWithName
377+ equals: expected asOrderedCollection
378+ ]
379+
331380{ #category : #tests }
332381DataFrameTest >> testAt [
333382
@@ -1007,6 +1056,21 @@ DataFrameTest >> testCopy2 [
10071056 self assert: copy numberOfColumns equals: 3
10081057]
10091058
1059+ { #category : #tests }
1060+ DataFrameTest >> testCopyReplaceIn2DCollectionBy [
1061+
1062+ | expected |
1063+ expected := DataFrame withRows:
1064+ #( #( Barcelona 1.609 true ) #( Dubai 2.789 true )
1065+ #( London 8.788 true ) ).
1066+
1067+ expected rowNames: #( A B C ) .
1068+ expected columnNames: #( City Population BeenThere ) .
1069+
1070+ df copyReplace: false in2DCollectionBy: #( true true true ) .
1071+ self assert: df equals: expected
1072+ ]
1073+
10101074{ #category : #tests }
10111075DataFrameTest >> testCreateDataFrameWith3ColumnsAndNoRows [
10121076 | dataFrame |
@@ -1716,6 +1780,18 @@ DataFrameTest >> testFindAllIndicesOfAtColumnFloat [
17161780 self assert: (df findAllIndicesOf: 2.789 atColumn: ' Population' ) equals: #(2 4) asOrderedCollection
17171781]
17181782
1783+ { #category : #tests }
1784+ DataFrameTest >> testFirst [
1785+
1786+ | actual expected |
1787+ expected := DataSeries
1788+ withKeys: #( 'City' 'Population' 'BeenThere' )
1789+ values: #( 'Barcelona' 1.609 true )
1790+ name: ' A' .
1791+ actual := df first.
1792+ self assert: actual equals: expected
1793+ ]
1794+
17191795{ #category : #replacing }
17201796DataFrameTest >> testHasNils [
17211797
@@ -1913,6 +1989,34 @@ Data columns (total 3 columns):
19131989'
19141990]
19151991
1992+ { #category : #tests }
1993+ DataFrameTest >> testInitializeColumns [
1994+
1995+ | anArrayOfColumns dataFrame |
1996+ anArrayOfColumns := #( #( 'Barcelona' 'Dubai' 'London' )
1997+ #( 1.609 2.789 8.788 ) #( true true false ) ).
1998+ dataFrame := DataFrame new .
1999+ dataFrame initializeColumns: anArrayOfColumns.
2000+ dataFrame rowNames: #( 'A' 'B' 'C' ) .
2001+ dataFrame columnNames: #( 'City' 'Population' 'BeenThere' ) .
2002+
2003+ self assert: dataFrame equals: df
2004+ ]
2005+
2006+ { #category : #tests }
2007+ DataFrameTest >> testInitializeRows [
2008+
2009+ | anArrayOfRows dataFrame |
2010+ anArrayOfRows := #( #( 'Barcelona' 1.609 true )
2011+ #( 'Dubai' 2.789 true ) #( 'London' 8.788 false ) ).
2012+ dataFrame := DataFrame new .
2013+ dataFrame initializeRows: anArrayOfRows.
2014+ dataFrame rowNames: #( 'A' 'B' 'C' ) .
2015+ dataFrame columnNames: #( 'City' 'Population' 'BeenThere' ) .
2016+
2017+ self assert: dataFrame equals: df
2018+ ]
2019+
19162020{ #category : #tests }
19172021DataFrameTest >> testInjectInto [
19182022 | numericDataFrame actual expected |
0 commit comments