Skip to content

Commit bc7c1c8

Browse files
committed
Add speedup for data-imputers
1 parent 5d3d177 commit bc7c1c8

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/DataFrame/DataFrame.class.st

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,21 @@ DataFrame >> contents [
773773
^ contents
774774
]
775775

776+
{ #category : #copying }
777+
DataFrame >> copyReplace: missingValue in2DCollectionBy: arrayOfReplacementValues [
778+
"I am a 2D collection and the goal is to return a copy replace the missing values by the values of my second parameter. The good value is the index of the missing value in the sub collection.
779+
780+
I am needed for the project pharo-ai/data-imputers. I can work without that method but the time it will take to replace the missing values will be huuuuuuuuuuuge"
781+
782+
| copy |
783+
copy := self copy.
784+
1 to: self numberOfColumns do: [ :columnIndex |
785+
| replacementValue |
786+
replacementValue := arrayOfReplacementValues at: columnIndex.
787+
1 to: self numberOfRows do: [ :rowIndex | (self at: rowIndex at: columnIndex) = missingValue ifTrue: [ self copy at: rowIndex at: columnIndex put: replacementValue ] ] ].
788+
^ copy
789+
]
790+
776791
{ #category : #statistics }
777792
DataFrame >> correlationMatrix [
778793
"Calculate a correlation matrix (correlation of every column with every column) using Pearson's correlation coefficient"
@@ -1625,10 +1640,10 @@ DataFrame >> replaceAllNilsWithZeros [
16251640
{ #category : #replacing }
16261641
DataFrame >> replaceNilsWith: anObject [
16271642

1628-
1 to: self numberOfColumns do: [ :i |
1629-
1 to: self numberOfRows do: [ :j |
1630-
(self at: j at: i) ifNil:
1631-
[ self at: j at: i put: anObject ] ]
1643+
1 to: self numberOfColumns do: [ :columnIndex |
1644+
1 to: self numberOfRows do: [ :rowIndex |
1645+
(self at: rowIndex at: columnIndex) ifNil:
1646+
[ self at: rowIndex at: columnIndex put: anObject ] ]
16321647
]
16331648
]
16341649

0 commit comments

Comments
 (0)