Skip to content

Commit b9e0259

Browse files
Added #sortByRowNames with tests.
1 parent baf02c7 commit b9e0259

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
@@ -5157,6 +5157,29 @@ DataFrameTest >> testSortByAll [
51575157
self assert: actual equals: expected
51585158
]
51595159

5160+
{ #category : #tests }
5161+
DataFrameTest >> testSortByRowNames [
5162+
5163+
| dataFrame expected sortedDF |
5164+
dataFrame := DataFrame withRows:
5165+
#( #( 'CD' 3 2 )
5166+
#( 'AC' 1 4 )
5167+
#( 'DB' 2 4 )
5168+
#( 'BA' 5 1 ) ).
5169+
dataFrame rowNames: #( 'CD' 'AC' 'DB' 'BA' ).
5170+
5171+
expected := DataFrame withRows:
5172+
#( #( 'AC' 1 4 )
5173+
#( 'BA' 5 1 )
5174+
#( 'CD' 3 2 )
5175+
#( 'DB' 2 4 ) ).
5176+
expected rowNames: #( 'AC' 'BA' 'CD' 'DB' ).
5177+
5178+
sortedDF := dataFrame sortByRowNames.
5179+
5180+
self assert: sortedDF equals: expected
5181+
]
5182+
51605183
{ #category : #tests }
51615184
DataFrameTest >> testSortByRowNamesUsing [
51625185
"sorts by second letter of row name"

src/DataFrame/DataFrame.class.st

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,13 @@ DataFrame >> sortByAll: arrayOfColumnNames [
24692469
^ self
24702470
]
24712471

2472+
{ #category : #sorting }
2473+
DataFrame >> sortByRowNames [
2474+
"Sorts the rows of the data frame based on the row names in ascending order"
2475+
2476+
self sortByRowNamesUsing: [ :a :b | a <= b ]
2477+
]
2478+
24722479
{ #category : #sorting }
24732480
DataFrame >> sortByRowNamesUsing: aBlock [
24742481
"Sorts the rows of the data frame based on the row names using the given comparison block"

0 commit comments

Comments
 (0)