@@ -1058,6 +1058,30 @@ DataFrameTest >> testInequality [
10581058 self assert: (df5 = df1) not .
10591059]
10601060
1061+ { #category : #tests }
1062+ DataFrameTest >> testInjectInto [
1063+ | numericDataFrame actual expected |
1064+
1065+ numericDataFrame := DataFrame
1066+ withRows: #(
1067+ (4.5 86 24)
1068+ (2.3 60 14 )
1069+ (1.2 56 16 )
1070+ (- 1.0 12 18 ))
1071+ rowNames: #(A B C D)
1072+ columnNames: #(temperature humidity wind) .
1073+
1074+ expected := DataSeries
1075+ withKeys: #(temperature humidity wind)
1076+ values: #(7.0 214 72)
1077+ name: ' (no name)' .
1078+
1079+ actual := numericDataFrame inject: 0 into:
1080+ [ :sum :each | sum + each ].
1081+
1082+ self assert: actual equals: expected.
1083+ ]
1084+
10611085{ #category : #tests }
10621086DataFrameTest >> testPrintOn [
10631087
@@ -1072,6 +1096,23 @@ DataFrameTest >> testPrintOn [
10721096 self assert: actual equals: expected.
10731097]
10741098
1099+ { #category : #tests }
1100+ DataFrameTest >> testReject [
1101+ | actual expected |
1102+
1103+ expected := DataFrame
1104+ withRows: #(
1105+ (Dubai 2.789 true)
1106+ (London 8.788 false ))
1107+ rowNames: #(B C)
1108+ columnNames: df columnNames.
1109+
1110+ actual := df reject:
1111+ [ :row | (row at: #Population ) < 2 ].
1112+
1113+ self assert: actual equals: expected.
1114+ ]
1115+
10751116{ #category : #tests }
10761117DataFrameTest >> testRemoveColumn [
10771118
@@ -1423,6 +1464,23 @@ DataFrameTest >> testRowsPut [
14231464 self assert: dataFrame equals: expected.
14241465]
14251466
1467+ { #category : #tests }
1468+ DataFrameTest >> testSelect [
1469+ | actual expected |
1470+
1471+ expected := DataFrame
1472+ withRows: #(
1473+ (Dubai 2.789 true)
1474+ (London 8.788 false ))
1475+ rowNames: #(B C)
1476+ columnNames: df columnNames.
1477+
1478+ actual := df select:
1479+ [ :row | (row at: #Population ) > 2 ].
1480+
1481+ self assert: actual equals: expected.
1482+ ]
1483+
14261484{ #category : #tests }
14271485DataFrameTest >> testSortBy [
14281486
@@ -1583,6 +1641,106 @@ DataFrameTest >> testVarSizeInstanceCreation [
15831641 self assert: dataFrame columnNames equals: #(1 2) asOrderedCollection.
15841642]
15851643
1644+ { #category : #tests }
1645+ DataFrameTest >> testWithIndexCollect [
1646+ | expectedDf expectedResult actualResult |
1647+
1648+ expectedDf := DataFrame withRows: #(
1649+ (Barcelona 1.609 true)
1650+ (Dubai 2.789 true )
1651+ (London 8.788 false )).
1652+
1653+ expectedDf rowNames: #(A B C) .
1654+ expectedDf columnNames: #(City Population BeenThere) .
1655+
1656+ expectedResult := DataFrame withRows: #(
1657+ ('BARCELONA' 2)
1658+ (' DUBAI' 4 )
1659+ (' LONDON' 11 )).
1660+
1661+ expectedResult rowNames: #(A B C) .
1662+ expectedResult columnNames: #(City Population) .
1663+
1664+ actualResult := df withIndexCollect: [ :row :index |
1665+ row at: #City put: (row at: #City ) asUppercase.
1666+ row at: #Population put: (row at: #Population ) asInteger + index.
1667+ row removeAt: #BeenThere .
1668+ row ].
1669+
1670+ self assert: actualResult equals: expectedResult.
1671+ self assert: df equals: expectedDf.
1672+ ]
1673+
1674+ { #category : #tests }
1675+ DataFrameTest >> testWithIndexDo [
1676+
1677+ | actual expected |
1678+
1679+ expected := {
1680+ 1 - > (DataSeries withKeys: df columnNames values: #(Barcelona 1.609 true) name: ' A' ) .
1681+ 2 - > (DataSeries withKeys: df columnNames values: #(Dubai 2.789 true) name: ' B' ) .
1682+ 3 - > (DataSeries withKeys: df columnNames values: #(London 8.788 false) name: ' C' ) } asDictionary.
1683+
1684+ actual := Dictionary new .
1685+
1686+ df withIndexDo: [ :each :index |
1687+ actual at: index put: each ].
1688+
1689+ self assert: actual equals: expected.
1690+ ]
1691+
1692+ { #category : #tests }
1693+ DataFrameTest >> testWithIndexDoCanModifyRows [
1694+ | expected |
1695+
1696+ expected := DataFrame
1697+ withRows: #(
1698+ (Barcelona 1.609 true)
1699+ (Dubai 4.789 true )
1700+ (London 11.788 false ))
1701+ rowNames: df rowNames
1702+ columnNames: df columnNames.
1703+
1704+ df withIndexDo: [ :row :index |
1705+ row name = ' A'
1706+ ifFalse: [ row at: #Population put: ((row at: #Population ) + index) ] ].
1707+
1708+ self assert: df equals: expected.
1709+ ]
1710+
1711+ { #category : #tests }
1712+ DataFrameTest >> testWithIndexReject [
1713+ | actual expected |
1714+
1715+ expected := DataFrame
1716+ withRows: #(
1717+ (Barcelona 1.609 true)
1718+ (London 8.788 false ))
1719+ rowNames: #(A C)
1720+ columnNames: df columnNames.
1721+
1722+ actual := df withIndexReject: [ :row :index |
1723+ ((row at: #Population ) > 2 ) and : [ index % 2 = 0 ] ].
1724+
1725+ self assert: actual equals: expected.
1726+ ]
1727+
1728+ { #category : #tests }
1729+ DataFrameTest >> testWithIndexSelect [
1730+ | actual expected |
1731+
1732+ expected := DataFrame
1733+ withRows: #(
1734+ (Dubai 2.789 true) )
1735+ rowNames: #(B)
1736+ columnNames: df columnNames.
1737+
1738+ actual := df withIndexSelect: [ :row :index |
1739+ ((row at: #Population ) > 2 ) and : [ index % 2 = 0 ] ].
1740+
1741+ self assert: actual equals: expected.
1742+ ]
1743+
15861744{ #category : #tests }
15871745DataFrameTest >> testWithRowNameDo [
15881746
0 commit comments