File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3869,6 +3869,30 @@ DataFrameTest >> testReplaceNilsWithMode [
38693869 self assert: df replaceNilsWithMode equals: expected
38703870]
38713871
3872+ { #category : #tests }
3873+ DataFrameTest >> testReplaceNilsWithNextRowValue [
3874+
3875+ |expected |
3876+
3877+ df := DataFrame withRows: #(
3878+ (7 1 nil)
3879+ (8 nil 3 )
3880+ (nil 2 nil )).
3881+
3882+ df rowNames: #(A B C) .
3883+ df columnNames: #(Column1 Column2 Column3) .
3884+
3885+ expected := DataFrame withRows: #(
3886+ (7 1 3)
3887+ (8 2 3 )
3888+ (nil 2 nil )).
3889+
3890+ expected rowNames: #(A B C) .
3891+ expected columnNames: #(Column1 Column2 Column3) .
3892+
3893+ self assert: (df replaceNilsWithNextRowValue) equals: expected
3894+ ]
3895+
38723896{ #category : #replacing }
38733897DataFrameTest >> testReplaceNilsWithPreviousRowValue [
38743898
Original file line number Diff line number Diff line change @@ -1793,6 +1793,18 @@ DataFrame >> replaceNilsWithMode [
17931793 modeOfColumn := nil ]
17941794]
17951795
1796+ { #category : #replacing }
1797+ DataFrame >> replaceNilsWithNextRowValue [
1798+
1799+ | value numberOfRows |
1800+ numberOfRows := self numberOfRows.
1801+ 1 to: self numberOfColumns do: [ :i |
1802+ self numberOfRows to: 1 by: - 1 do: [ :j |
1803+ j < numberOfRows ifTrue: [
1804+ (self at: j at: i) ifNil: [ self at: j at: i put: value ] ].
1805+ value := self at: j at: i ] ]
1806+ ]
1807+
17961808{ #category : #replacing }
17971809DataFrame >> replaceNilsWithPreviousRowValue [
17981810 " Replaces all nil values of a data frame with the previous non-nil value of the column in which it is present"
You can’t perform that action at this time.
0 commit comments