@@ -504,27 +504,42 @@ DataFrame >> asArrayOfRowsWithName [
504504{ #category : #accessing }
505505DataFrame >> at: aNumber [
506506 " Returns the row of a DataFrame at row index aNumber"
507-
507+
508+ " (#(#(1 2) #(3 4)) asDataFrame at: 1) >>> (#(1 2) asDataSeries)"
509+
510+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame at: 2) >>> (#(r2c1 r2c2) asDataSeries)"
511+
508512 ^ self rowAt: aNumber
509513]
510514
511515{ #category : #accessing }
512516DataFrame >> at: rowNumber at: columnNumber [
513517 " Returns the value whose row index is rowNumber and column index is columnNumber"
514-
518+
519+ " (#(#(1 2) #(3 4)) asDataFrame at: 1 at:1) >>> 1"
520+
521+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame at: 2 at: 1) >>> #r2c1"
522+
515523 ^ contents at: rowNumber at: columnNumber
516524]
517525
518526{ #category : #accessing }
519527DataFrame >> at: rowNumber at: columnNumber put: value [
520528 " Replaces the original value of a DataFrame at row index rowNumber and column index columnNumber with a given value"
521-
529+
530+ " (#(#(1 2) #(3 4)) asDataFrame at: 1 at:1 put: 5) >>> (#(#(5 2) #(3 4)) asDataFrame)"
531+
532+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame at: 2 at: 1 put: #R2C1) >>> (#(#(r1c1 r1c2) #(R2C1 r2c2)) asDataFrame)"
533+
522534 contents at: rowNumber at: columnNumber put: value
523535]
524536
525537{ #category : #accessing }
526538DataFrame >> at: rowIndex at: columnIndex transform: aBlock [
527539 " Evaluate aBlock on the value at the intersection of rowIndex and columnIndex and replace that value with the result"
540+
541+ " (#(#(1 2) #(3 4)) asDataFrame at: 1 at:1 transform: [:x| x - 1]) >>>(#(#(0 2) #(3 4)) asDataFrame)"
542+
528543 | value |
529544 value := self at: rowIndex at: columnIndex.
530545 self at: rowIndex at: columnIndex put: (aBlock value: value)
@@ -533,13 +548,20 @@ DataFrame >> at: rowIndex at: columnIndex transform: aBlock [
533548{ #category : #accessing }
534549DataFrame >> at: aNumber transform: aBlock [
535550 " Evaluate aBlock on the row at aNumber and replace that row with the result"
551+
552+ " (#(#(1 2) #(3 4)) asDataFrame at: 1 transform: [:x| x - 1]) >>>(#(#(0 1) #(3 4)) asDataFrame)"
553+
536554 ^ self rowAt: aNumber transform: aBlock
537555]
538556
539557{ #category : #accessing }
540558DataFrame >> atAll: indexes [
541559 " For polymorphisme with other collections."
542560
561+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame atAll: #(1 3)) >>> (#(#(1 2) #(5 6)) asDataFrame)"
562+
563+ " (#(#(r1c1 r1c2) #(r2c1 r2c2) #(r3c1 r3c2)) asDataFrame atAll: #(1 3)) >>> (#(#(r1c1 r1c2) #(r3c1 r3c2)) asDataFrame)"
564+
543565 ^ self rowsAt: indexes
544566]
545567
@@ -679,25 +701,37 @@ DataFrame >> column: columnName transform: aBlock ifAbsent: exceptionBlock [
679701{ #category : #accessing }
680702DataFrame >> columnAt: aNumber [
681703 " Returns the column of a DataFrame at column index aNumber"
682-
683- ^ (DataSeries withKeys: self rowNames values: (contents columnAt: aNumber))
704+
705+ " (#(#(1 2) #(5 6)) asDataFrame columnAt: 2) >>> (#(2 6) asDataSeries) "
706+
707+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame columnAt: 2) >>> (#(r1c2 r2c2) asDataSeries) "
708+
709+ ^ (DataSeries
710+ withKeys: self rowNames
711+ values: (contents columnAt: aNumber))
684712 name: (self columnNames at: aNumber);
685713 yourself
686714]
687715
688716{ #category : #accessing }
689717DataFrame >> columnAt: aNumber put: anArray [
690718 " Replaces the column at column index aNumber with contents of the array anArray"
691-
692- anArray size = self numberOfRows
693- ifFalse: [ SizeMismatch signal ].
719+
720+ " (#(#(1 2) #(3 4)) asDataFrame columnAt: 2 put: #(5 6)) >>> (#(#(1 5) #(3 6)) asDataFrame) "
721+
722+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame columnAt: 2 put: #(R1C2 R2C2)) >>> (#(#(r1c1 R1C2) #(r2c1 R2C2)) asDataFrame) "
723+
724+ anArray size = self numberOfRows ifFalse: [ SizeMismatch signal ].
694725
695726 contents columnAt: aNumber put: anArray
696727]
697728
698729{ #category : #accessing }
699730DataFrame >> columnAt: aNumber transform: aBlock [
700731 " Evaluate aBlock on the column at aNumber and replace that column with the result"
732+
733+ " (#(#(1 2) #(3 4)) asDataFrame columnAt: 2 transform: [ :x | x / 2 ]) >>> (#(#(1 1) #(3 2)) asDataFrame) "
734+
701735 | column |
702736 column := self columnAt: aNumber.
703737 self columnAt: aNumber put: (aBlock value: column) asArray
@@ -734,6 +768,10 @@ DataFrame >> columnNames: aCollection [
734768DataFrame >> columns [
735769 " Returns a collection of all columns"
736770
771+ " (#(#(1 2) #(3 4)) asDataFrame columns) >>> (#( #(1 3) #(2 4) ) collect: #asDataSeries) "
772+
773+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame columns) >>> (#( #(r1c1 r2c1) #(r1c2 r2c2) ) collect: #asDataSeries) "
774+
737775 ^ (1 to: self numberOfColumns) collect: [ :j | self columnAt: j ]
738776]
739777
@@ -765,37 +803,46 @@ DataFrame >> columns: anArrayOfColumnNames put: anArrayOfArrays [
765803DataFrame >> columnsAt: anArrayOfNumbers [
766804 " Returns a collection of columns whose column indices are present in the array anArrayOfNumbers"
767805
768- | newColumnNames |
806+ " (#(#(1 2 3) #(4 5 6)) asDataFrame columnsAt: #(1 3)) >>> (#(#(1 3) #(4 6)) asDataFrame) "
769807
770- newColumnNames := (anArrayOfNumbers collect: [ :i |
771- self columnNames at: i ]).
808+ " (#(#(r1c1 r1c2 r1c3) #(r2c1 r2c2 r2c3)) asDataFrame columnsAt: #(1 3)) >>> (#(#(r1c1 r1c3) #(r2c1 r2c3)) asDataFrame)"
809+
810+ | newColumnNames |
811+ newColumnNames := anArrayOfNumbers collect: [ :i |
812+ self columnNames at: i ].
772813
773814 ^ DataFrame
774- withDataFrameInternal: (self contents columnsAt: anArrayOfNumbers)
775- rowNames: self rowNames
776- columnNames: newColumnNames
815+ withDataFrameInternal: (self contents columnsAt: anArrayOfNumbers)
816+ rowNames: self rowNames
817+ columnNames: newColumnNames
777818]
778819
779820{ #category : #accessing }
780821DataFrame >> columnsAt: anArrayOfNumbers put: anArrayOfArrays [
781822 " Replaces the columns whose column indices are present in the array anArrayOfNumbers with the contents of the array of arrays anArrayOfArrays"
782823
783- anArrayOfArrays size = anArrayOfNumbers size
784- ifFalse: [ SizeMismatch signal ].
824+ " (#(#(1 2 3) #(4 5 6)) asDataFrame columnsAt: #(1 3) put: #(#(10 40) #(30 60))) >>> (#(#(10 2 30) #(40 5 60)) asDataFrame)"
785825
786- anArrayOfNumbers with: anArrayOfArrays do: [ :index :array |
787- self columnAt: index put: array ]
826+ anArrayOfArrays size = anArrayOfNumbers size ifFalse: [
827+ SizeMismatch signal ].
828+
829+ anArrayOfNumbers
830+ with: anArrayOfArrays
831+ do: [ :index :array | self columnAt: index put: array ]
788832]
789833
790834{ #category : #accessing }
791835DataFrame >> columnsFrom: begin to: end [
792836 " Returns a collection of columns whose column indices are present between begin and end"
793837
794- | array |
838+ " (#(#(1 2 3) #(4 5 6)) asDataFrame columnsFrom: 1 to: 2) >>> (#(#(1 2) #(4 5)) asDataFrame) "
795839
840+ " (#(#(r1c1 r1c2 r1c3) #(r2c1 r2c2 r2c3)) asDataFrame columnsFrom: 1 to: 2) >>> (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame)"
841+
842+ | array |
796843 array := begin < end
797- ifTrue: [ (begin to: end) asArray ]
798- ifFalse: [ (end to: begin) asArray reverse ].
844+ ifTrue: [ (begin to: end) asArray ]
845+ ifFalse: [ (end to: begin) asArray reverse ].
799846
800847 ^ self columnsAt: array
801848]
@@ -804,14 +851,15 @@ DataFrame >> columnsFrom: begin to: end [
804851DataFrame >> columnsFrom: firstNumber to: secondNumber put: anArrayOfArrays [
805852 " Replaces the columns whose column indices are present between firstNumber and secondNumber with the contents of the array of arrays anArrayOfArrays"
806853
807- | interval |
854+ " (#(#(1 2 3) #(4 5 6)) asDataFrame columnsFrom: 1 to: 2 put:#(#(7 8) #(9 10))) >>> (#(#(7 9 3) #(8 10 6)) asDataFrame) "
808855
856+ | interval |
809857 anArrayOfArrays size = ((firstNumber - secondNumber) abs + 1 )
810858 ifFalse: [ SizeMismatch signal ].
811859
812860 interval := secondNumber >= firstNumber
813- ifTrue: [ ( firstNumber to: secondNumber) ]
814- ifFalse: [ (secondNumber to: firstNumber) reversed ].
861+ ifTrue: [ firstNumber to: secondNumber ]
862+ ifFalse: [ (secondNumber to: firstNumber) reversed ].
815863
816864 interval withIndexDo: [ :columnIndex :i |
817865 self columnAt: columnIndex put: (anArrayOfArrays at: i) ]
@@ -977,8 +1025,14 @@ DataFrame >> describe [
9771025{ #category : #accessing }
9781026DataFrame >> dimensions [
9791027 " Returns the number of rows and number of columns in a DataFrame"
980-
981- ^ (self numberOfRows) @ (self numberOfColumns)
1028+
1029+ " (#(#(1 2) #(3 4)) asDataFrame dimensions) >>> (2@2)"
1030+
1031+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame dimensions) >>> (3@2)"
1032+
1033+ " (#(#(1 2 3) #(4 5 6)) asDataFrame dimensions) >>> (2@3)"
1034+
1035+ ^ self numberOfRows @ self numberOfColumns
9821036]
9831037
9841038{ #category : #enumerating }
@@ -1012,7 +1066,11 @@ DataFrame >> findAllIndicesOf: anObject atColumn: columnName [
10121066{ #category : #accessing }
10131067DataFrame >> first [
10141068 " Returns the first row of the DataFrame"
1015-
1069+
1070+ " (#(#(1 2) #(3 4)) asDataFrame first) >>> (#(1 2) asDataSeries)"
1071+
1072+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame first) >>> (#(r1c1 r1c2) asDataSeries)"
1073+
10161074 ^ self at: 1
10171075]
10181076
@@ -1114,7 +1172,11 @@ DataFrame >> head [
11141172{ #category : #accessing }
11151173DataFrame >> head: aNumber [
11161174 " Returns the first aNumber rows of a DataFrame"
1117-
1175+
1176+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame head: 2) >>> (#(#(1 2) #(3 4)) asDataFrame)"
1177+
1178+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame head: 1) >>> (#(#(r1c1 r1c2)) asDataFrame)"
1179+
11181180 ^ self rowsAt: (1 to: (self numberOfRows min: aNumber))
11191181]
11201182
@@ -1437,7 +1499,11 @@ DataFrame >> normalized [
14371499{ #category : #accessing }
14381500DataFrame >> numberOfColumns [
14391501 " Returns the number of columns of a DataFrame"
1440-
1502+
1503+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame numberOfColumns) >>> 2 "
1504+
1505+ " (#(#(1 2 3) #(4 5 6)) asDataFrame numberOfColumns) >>> 3 "
1506+
14411507 ^ contents numberOfColumns
14421508]
14431509
@@ -1457,6 +1523,10 @@ DataFrame >> numberOfNils [
14571523DataFrame >> numberOfRows [
14581524 " Returns the number of rows of a DataFrame"
14591525
1526+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame numberOfRows) >>> 3 "
1527+
1528+ " (#(#(1 2 3) #(4 5 6)) asDataFrame numberOfRows) >>> 2 "
1529+
14601530 ^ contents numberOfRows
14611531]
14621532
@@ -2019,6 +2089,10 @@ DataFrame >> row: rowName transform: aBlock ifAbsent: exceptionBlock [
20192089DataFrame >> rowAt: aNumber [
20202090 " Returns the row of a DataFrame at row index aNumber"
20212091
2092+ " (#(#(1 2) #(5 6)) asDataFrame rowAt: 2) >>> (#(5 6) asDataSeries) "
2093+
2094+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame rowAt: 2) >>> (#(r2c1 r2c2) asDataSeries) "
2095+
20222096 | series |
20232097 series := (contents rowAt: aNumber) asDataSeries.
20242098 series name: (self rowNames at: aNumber).
@@ -2030,15 +2104,21 @@ DataFrame >> rowAt: aNumber [
20302104DataFrame >> rowAt: aNumber put: anArray [
20312105 " Replaces the row at row index aNumber with contents of the array anArray"
20322106
2033- anArray size = self numberOfColumns
2034- ifFalse: [ SizeMismatch signal ].
2107+ " (#(#(1 2) #(3 4)) asDataFrame rowAt: 2 put: #(5 6)) >>> (#(#(1 2) #(5 6)) asDataFrame) "
2108+
2109+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame rowAt: 2 put: #(R2C1 R2C2)) >>> (#(#(r1c1 r1c2) #(R2C1 R2C2)) asDataFrame) "
2110+
2111+ anArray size = self numberOfColumns ifFalse: [ SizeMismatch signal ].
20352112
20362113 contents rowAt: aNumber put: anArray
20372114]
20382115
20392116{ #category : #accessing }
20402117DataFrame >> rowAt: aNumber transform: aBlock [
20412118 " Evaluate aBlock on the row at aNumber and replace that row with the result"
2119+
2120+ " (#(#(1 2) #(3 4)) asDataFrame rowAt: 2 transform: [ :x | x + 1 ]) >>> (#(#(1 2) #(4 5)) asDataFrame) "
2121+
20422122 | row |
20432123 row := self rowAt: aNumber.
20442124 self rowAt: aNumber put: (aBlock value: row) asArray
@@ -2066,6 +2146,10 @@ DataFrame >> rowNames: anArray [
20662146DataFrame >> rows [
20672147 " Returns a collection of all rows"
20682148
2149+ " (#(#(1 2) #(3 4)) asDataFrame rows) >>> (#( #(1 2) #(3 4) ) collect: #asDataSeries) "
2150+
2151+ " (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame rows) >>> (#( #(r1c1 r1c2) #(r2c1 r2c2) ) collect: #asDataSeries) "
2152+
20692153 ^ (1 to: self numberOfRows) collect: [ :j | self rowAt: j ]
20702154]
20712155
@@ -2097,47 +2181,57 @@ DataFrame >> rows: anArrayOfRowNames put: anArrayOfArrays [
20972181DataFrame >> rowsAt: anArrayOfNumbers [
20982182 " Returns a collection of rows whose row indices are present in the array anArrayOfNumbers"
20992183
2100- | newRowNames |
2184+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame rowsAt: #(1 3)) >>> (#(#(1 2) #(5 6)) asDataFrame) "
21012185
2102- newRowNames := (anArrayOfNumbers collect: [ :i |
2103- self rowNames at: i ]).
2186+ " (#(#(r1c1 r1c2) #(r2c1 r2c2) #(r3c1 r3c2)) asDataFrame rowsAt: #(1 3)) >>> (#(#(r1c1 r1c2) #(r3c1 r3c2)) asDataFrame)"
2187+
2188+ | newRowNames |
2189+ newRowNames := anArrayOfNumbers collect: [ :i | self rowNames at: i ].
21042190
21052191 ^ DataFrame
2106- withDataFrameInternal: (self contents rowsAt: anArrayOfNumbers)
2107- rowNames: newRowNames
2108- columnNames: self columnNames
2192+ withDataFrameInternal: (self contents rowsAt: anArrayOfNumbers)
2193+ rowNames: newRowNames
2194+ columnNames: self columnNames
21092195]
21102196
21112197{ #category : #accessing }
21122198DataFrame >> rowsAt: anArrayOfNumbers put: anArrayOfArrays [
21132199 " Replaces the rows whose row indices are present in the array anArrayOfNumbers with the contents of the array of arrays anArrayOfArrays"
21142200
2115- anArrayOfArrays size = anArrayOfNumbers size
2116- ifFalse: [ SizeMismatch signal ].
2201+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame rowsAt: #(1 3) put: #((10 20)(50 60))) >>> (#(#(10 20) #(3 4) #(50 60)) asDataFrame)"
21172202
2118- anArrayOfNumbers with: anArrayOfArrays do: [ :index :array |
2119- self rowAt: index put: array ]
2203+ anArrayOfArrays size = anArrayOfNumbers size ifFalse: [
2204+ SizeMismatch signal ].
2205+
2206+ anArrayOfNumbers
2207+ with: anArrayOfArrays
2208+ do: [ :index :array | self rowAt: index put: array ]
21202209]
21212210
21222211{ #category : #accessing }
21232212DataFrame >> rowsFrom: begin to: end [
21242213 " Returns a collection of rows whose row indices are present between begin and end"
21252214
2215+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame rowsFrom: 1 to: 2) >>> (#(#(1 2) #(3 4)) asDataFrame)"
2216+
2217+ " (#(#(r1c1 r1c2) #(r2c1 r2c2) #(r3c1 r3c2)) asDataFrame rowsFrom: 1 to: 2) >>> (#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame)"
2218+
21262219 ^ self rowsAt: (begin to: end)
21272220]
21282221
21292222{ #category : #accessing }
21302223DataFrame >> rowsFrom: firstNumber to: secondNumber put: anArrayOfArrays [
21312224 " Replaces the rows whose row indices are present between firstNumber and secondNumber with the contents of the array of arrays anArrayOfArrays"
21322225
2133- | interval |
2226+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame rowsFrom: 1 to: 2 put: #(#(7 8) #(9 10))) >>> (#(#(7 8) #(9 10) #(5 6)) asDataFrame) "
21342227
2228+ | interval |
21352229 anArrayOfArrays size = ((firstNumber - secondNumber) abs + 1 )
21362230 ifFalse: [ SizeMismatch signal ].
21372231
21382232 interval := secondNumber >= firstNumber
2139- ifTrue: [ ( firstNumber to: secondNumber) ]
2140- ifFalse: [ (secondNumber to: firstNumber) reversed ].
2233+ ifTrue: [ firstNumber to: secondNumber ]
2234+ ifFalse: [ (secondNumber to: firstNumber) reversed ].
21412235
21422236 interval withIndexDo: [ :rowIndex :i |
21432237 self rowAt: rowIndex put: (anArrayOfArrays at: i) ]
@@ -2167,7 +2261,13 @@ DataFrame >> setDefaultRowColumnNames [
21672261{ #category : #accessing }
21682262DataFrame >> size [
21692263 " Returns the number of rows of a DataFrame"
2170-
2264+
2265+ " (#(#(1 2) #(3 4) #(5 6)) asDataFrame size) >>> 3 "
2266+
2267+ " (#(#(1 2 3) #(4 5 6)) asDataFrame size) >>> 2 "
2268+
2269+ " (#() asDataFrame size) >>> 0 "
2270+
21712271 ^ self numberOfRows
21722272]
21732273
0 commit comments