File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -992,6 +992,24 @@ DataFrameTest >> testDo [
992992 self assert: actual equals: expected.
993993]
994994
995+ { #category : #tests }
996+ DataFrameTest >> testDoCanModifyRows [
997+ | expected |
998+
999+ expected := DataFrame
1000+ withRows: #(
1001+ (BARCELONA 1.609 true)
1002+ (DUBAI 2.789 true )
1003+ (LONDON 8.788 false ))
1004+ rowNames: df rowNames
1005+ columnNames: df columnNames.
1006+
1007+ df do: [ :row |
1008+ row at: #City put: (row at: #City ) asUppercase ].
1009+
1010+ self assert: df equals: expected.
1011+ ]
1012+
9951013{ #category : #tests }
9961014DataFrameTest >> testEquality [
9971015
@@ -1586,3 +1604,22 @@ DataFrameTest >> testWithKeyDo [
15861604
15871605 self assert: actual equals: expected.
15881606]
1607+
1608+ { #category : #tests }
1609+ DataFrameTest >> testWithKeyDoCanModifyRows [
1610+ | expected |
1611+
1612+ expected := DataFrame
1613+ withRows: #(
1614+ (Barcelona 1.609 true)
1615+ (DUBAI 2.789 true )
1616+ (LONDON 8.788 false ))
1617+ rowNames: df rowNames
1618+ columnNames: df columnNames.
1619+
1620+ df withKeyDo: [ :row :key |
1621+ row name = ' A'
1622+ ifFalse: [ row at: #City put: (row at: #City ) asUppercase ] ].
1623+
1624+ self assert: df equals: expected.
1625+ ]
Original file line number Diff line number Diff line change @@ -647,9 +647,13 @@ DataFrame >> dimensions [
647647{ #category : #enumerating }
648648DataFrame >> do: aBlock [
649649" We enumerate through the data enrties - through rows of a data frame"
650-
650+ | row |
651+
651652 1 to: self numberOfRows do: [ :i |
652- aBlock value: (self rowAt: i) ].
653+ row := self rowAt: i.
654+ aBlock value: row.
655+ " A hack to allow modification of rows inside do block"
656+ self rowAt: i put: row asArray ].
653657]
654658
655659{ #category : #statistics }
@@ -1174,8 +1178,14 @@ DataFrame >> variance [
11741178{ #category : #enumerating }
11751179DataFrame >> withKeyDo: elementAndKeyBlock [
11761180
1177- 1 to: self size do: [ :index |
1181+ 1 to: self size do: [ :i |
1182+ | row |
1183+ row := (self rowAt: i).
1184+
11781185 elementAndKeyBlock
1179- value: (self rowAt: index)
1180- value: (rowNames at: index) ].
1186+ value: row
1187+ value: (rowNames at: i).
1188+
1189+ " A hack to allow modification of rows inside do block"
1190+ self rowAt: i put: row asArray ].
11811191]
You can’t perform that action at this time.
0 commit comments