Skip to content

Commit 605d20e

Browse files
Added #sortDescendingByRowNames with tests.
1 parent b9e0259 commit 605d20e

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/DataFrame-Tests/DataFrameTest.class.st

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5272,6 +5272,29 @@ DataFrameTest >> testSortDescendingByAll [
52725272
self assert: actual equals: expected
52735273
]
52745274

5275+
{ #category : #tests }
5276+
DataFrameTest >> testSortDescendingByRowNames [
5277+
5278+
| dataFrame expected sortedDF |
5279+
dataFrame := DataFrame withRows:
5280+
#( #( 'CD' 3 2 )
5281+
#( 'AC' 1 4 )
5282+
#( 'DB' 2 4 )
5283+
#( 'BA' 5 1 ) ).
5284+
dataFrame rowNames: #( 'CD' 'AC' 'DB' 'BA' ).
5285+
5286+
expected := DataFrame withRows:
5287+
#( #( 'DB' 2 4 )
5288+
#( 'CD' 3 2 )
5289+
#( 'BA' 5 1 )
5290+
#( 'AC' 1 4 ) ).
5291+
expected rowNames: #( 'DB' 'CD' 'BA' 'AC' ).
5292+
5293+
sortedDF := dataFrame sortDescendingByRowNames.
5294+
5295+
self assert: sortedDF equals: expected
5296+
]
5297+
52755298
{ #category : #tests }
52765299
DataFrameTest >> testToColumnApplyElementwise [
52775300

src/DataFrame/DataFrame.class.st

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,13 @@ DataFrame >> sortDescendingByAll: arrayOfColumnNames [
25162516
^ self
25172517
]
25182518

2519+
{ #category : #sorting }
2520+
DataFrame >> sortDescendingByRowNames [
2521+
"Sorts the rows of the data frame based on the row names in ascending order"
2522+
2523+
self sortByRowNamesUsing: [ :a :b | a >= b ]
2524+
]
2525+
25192526
{ #category : #statistics }
25202527
DataFrame >> stdev [
25212528
"Standard deviation is a measure of how dispersed the data is in relation to the average"

0 commit comments

Comments
 (0)