@@ -295,6 +295,47 @@ 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 )
305+ #( 2.2 2.4 2.8 )
306+ #( 3.5 3.2 3.3 ) )
307+ rowNames: #( A B C )
308+ columnNames: #( 1 2 3 ) .
309+ expected := DataFrame
310+ withRows: #( #( 1 1 1 )
311+ #( 2 2 2 )
312+ #( 3 3 3 ) )
313+ rowNames: #( A B C )
314+ columnNames: #( 1 2 3 ) .
315+
316+ dataFrame applyElementwise: [ :value | value floor ].
317+ self assert: dataFrame equals: expected
318+ ]
319+
320+ { #category : #tests }
321+ DataFrameTest >> testApplyToAllColumns [
322+
323+ | dataFrame actual expected |
324+ dataFrame := DataFrame
325+ withRows: #( #( 1 4 7 )
326+ #( 2 5 8 )
327+ #( 3 6 9 ) )
328+ rowNames: #( A B C )
329+ columnNames: #( 1 2 3 ) .
330+ expected := DataSeries
331+ withKeys: #( 1 2 3 )
332+ values: #( 3 6 9 )
333+ name: ' max' .
334+
335+ actual := dataFrame applyToAllColumns: #max .
336+ self assert: actual equals: expected
337+ ]
338+
298339{ #category : #tests }
299340DataFrameTest >> testAsArray [
300341
@@ -328,6 +369,20 @@ DataFrameTest >> testAsArrayOfRows [
328369 self assert: df asArrayOfRows equals: (expected collect: [ :e | e asArray ])
329370]
330371
372+ { #category : #tests }
373+ DataFrameTest >> testAsArrayOfRowsWithName [
374+
375+ | expected |
376+ expected := {
377+ #( 'A' 'Barcelona' 1.609 true ) asArray.
378+ #( 'B' 'Dubai' 2.789 true ) asArray.
379+ #( 'C' 'London' 8.788 false ) asArray }.
380+
381+ self
382+ assert: df asArrayOfRowsWithName
383+ equals: expected asOrderedCollection
384+ ]
385+
331386{ #category : #tests }
332387DataFrameTest >> testAt [
333388
@@ -1007,6 +1062,22 @@ DataFrameTest >> testCopy2 [
10071062 self assert: copy numberOfColumns equals: 3
10081063]
10091064
1065+ { #category : #tests }
1066+ DataFrameTest >> testCopyReplaceIn2DCollectionBy [
1067+
1068+ | expected |
1069+ expected := DataFrame withRows:
1070+ #( #( Barcelona 1.609 true )
1071+ #( Dubai 2.789 true )
1072+ #( London 8.788 true ) ).
1073+
1074+ expected rowNames: #( A B C ) .
1075+ expected columnNames: #( City Population BeenThere ) .
1076+
1077+ df copyReplace: false in2DCollectionBy: #( true true true ) .
1078+ self assert: df equals: expected
1079+ ]
1080+
10101081{ #category : #tests }
10111082DataFrameTest >> testCreateDataFrameWith3ColumnsAndNoRows [
10121083 | dataFrame |
@@ -1716,6 +1787,18 @@ DataFrameTest >> testFindAllIndicesOfAtColumnFloat [
17161787 self assert: (df findAllIndicesOf: 2.789 atColumn: ' Population' ) equals: #(2 4) asOrderedCollection
17171788]
17181789
1790+ { #category : #tests }
1791+ DataFrameTest >> testFirst [
1792+
1793+ | actual expected |
1794+ expected := DataSeries
1795+ withKeys: #( 'City' 'Population' 'BeenThere' )
1796+ values: #( 'Barcelona' 1.609 true )
1797+ name: ' A' .
1798+ actual := df first.
1799+ self assert: actual equals: expected
1800+ ]
1801+
17191802{ #category : #replacing }
17201803DataFrameTest >> testHasNils [
17211804
@@ -1913,6 +1996,35 @@ Data columns (total 3 columns):
19131996'
19141997]
19151998
1999+ { #category : #tests }
2000+ DataFrameTest >> testInitializeColumns [
2001+
2002+ | anArrayOfColumns dataFrame |
2003+ anArrayOfColumns := #( #( 'Barcelona' 'Dubai' 'London' )
2004+ #( 1.609 2.789 8.788 ) #( true true false ) ).
2005+ dataFrame := DataFrame new .
2006+ dataFrame initializeColumns: anArrayOfColumns.
2007+ dataFrame rowNames: #( 'A' 'B' 'C' ) .
2008+ dataFrame columnNames: #( 'City' 'Population' 'BeenThere' ) .
2009+
2010+ self assert: dataFrame equals: df
2011+ ]
2012+
2013+ { #category : #tests }
2014+ DataFrameTest >> testInitializeRows [
2015+
2016+ | anArrayOfRows dataFrame |
2017+ anArrayOfRows := #( #( 'Barcelona' 1.609 true )
2018+ #( 'Dubai' 2.789 true )
2019+ #( 'London' 8.788 false ) ).
2020+ dataFrame := DataFrame new .
2021+ dataFrame initializeRows: anArrayOfRows.
2022+ dataFrame rowNames: #( 'A' 'B' 'C' ) .
2023+ dataFrame columnNames: #( 'City' 'Population' 'BeenThere' ) .
2024+
2025+ self assert: dataFrame equals: df
2026+ ]
2027+
19162028{ #category : #tests }
19172029DataFrameTest >> testInjectInto [
19182030 | numericDataFrame actual expected |
0 commit comments