Skip to content

Commit 0be7b95

Browse files
authored
Merge pull request #242 from Joshua-Dias-Barreto/untestedMethods
Added DataFrame>> #removeDuplicateRows
2 parents 4031b8f + 48b8cb8 commit 0be7b95

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/DataFrame-Tests/DataFrameTest.class.st

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,26 @@ DataFrameTest >> testRemoveColumnsWithNilsAtRowOutOfRange [
36943694
self should: [ df removeColumnsWithNilsAtRow: 100 ] raise: SubscriptOutOfBounds
36953695
]
36963696

3697+
{ #category : #tests }
3698+
DataFrameTest >> testRemoveDuplicatedRows [
3699+
3700+
|dataFrame|
3701+
3702+
dataFrame := DataFrame withRows: #(
3703+
(Barcelona 1.609 true)
3704+
(Dubai 2.789 true)
3705+
(London 8.788 false)
3706+
(Barcelona 1.609 true)
3707+
(London 8.788 false)).
3708+
3709+
dataFrame rowNames: #(A B C D E).
3710+
dataFrame columnNames: #(City Population BeenThere).
3711+
3712+
dataFrame removeDuplicatedRows.
3713+
self assert: df equals: dataFrame.
3714+
3715+
]
3716+
36973717
{ #category : #removing }
36983718
DataFrameTest >> testRemoveRow [
36993719

src/DataFrame/DataFrame.class.st

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,22 @@ DataFrame >> removeColumnsWithNilsAtRowNamed: rowName [
16671667
self removeColumnsOfRowElementsSatisfing: [ :ele | ele isNil ] onRowNamed: rowName
16681668
]
16691669

1670+
{ #category : #removing }
1671+
DataFrame >> removeDuplicatedRows [
1672+
"Removes duplicate rows of a dataframe except the first unique row"
1673+
1674+
| numberOfRows nextRowIndex currentRow row aSet |
1675+
aSet := Set new.
1676+
numberOfRows := self numberOfRows.
1677+
1 to: numberOfRows do: [ :currentRowIndex |
1678+
currentRow := self rowAt: currentRowIndex.
1679+
nextRowIndex := currentRowIndex + 1.
1680+
nextRowIndex to: numberOfRows do: [ :index |
1681+
row := self rowAt: index.
1682+
row values = currentRow values ifTrue: [ aSet add: index ] ] ].
1683+
^ self removeRowsAt: aSet
1684+
]
1685+
16701686
{ #category : #removing }
16711687
DataFrame >> removeRow: rowName [
16721688
"Removes the row named rowName from a data frame"

0 commit comments

Comments
 (0)