Skip to content

Commit 0d6e4cb

Browse files
Fixed Bug in #toHtml
1 parent 9b5f8fb commit 0d6e4cb

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/DataFrame-Tests/DataFrameTest.class.st

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,23 @@ DataFrameTest >> testAsArrayOfRowsWithName [
377377
equals: expected asOrderedCollection
378378
]
379379

380+
{ #category : #tests }
381+
DataFrameTest >> testAscendingSortBy [
382+
383+
| actual expected |
384+
385+
expected := DataFrame withRows: #(
386+
(Barcelona 1.609 true)
387+
(Dubai 2.789 true)
388+
(London 8.788 false)).
389+
390+
expected rowNames: #(A B C).
391+
expected columnNames: #(City Population BeenThere).
392+
393+
actual := df sortAscendingBy: #(Population).
394+
self assert: actual equals: expected
395+
]
396+
380397
{ #category : #tests }
381398
DataFrameTest >> testAt [
382399

@@ -5005,7 +5022,7 @@ DataFrameTest >> testSelectEmptyDataFrame [
50055022
]
50065023

50075024
{ #category : #tests }
5008-
DataFrameTest >> testSortBy [
5025+
DataFrameTest >> testSortAscendingBy [
50095026

50105027
| actual expected |
50115028

@@ -5017,7 +5034,7 @@ DataFrameTest >> testSortBy [
50175034
expected rowNames: #(A B C).
50185035
expected columnNames: #(City Population BeenThere).
50195036

5020-
actual := df sortBy: #Population.
5037+
actual := df sortAscendingBy: #(Population).
50215038
self assert: actual equals: expected
50225039
]
50235040

@@ -5053,7 +5070,7 @@ DataFrameTest >> testSortDescendingBy [
50535070
expected rowNames: #(C B A).
50545071
expected columnNames: #(City Population BeenThere).
50555072

5056-
actual := df sortDescendingBy: #Population.
5073+
actual := df sortDescendingBy: #(Population).
50575074
self assert: actual equals: expected
50585075
]
50595076

src/DataFrame/DataFrame.class.st

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,9 @@ DataFrame >> toHtml [
22762276

22772277
columnWidths := dataFrame columnNames collect: [ :columnName |
22782278
| maxWidth |
2279-
maxWidth := columnName size.
2279+
columnName isString
2280+
ifFalse: [ maxWidth := columnName asString size ]
2281+
ifTrue: [ maxWidth := columnName size ].
22802282
dataFrame rows do: [ :row |
22812283
| value |
22822284
value := row at: columnName.
@@ -2285,7 +2287,10 @@ DataFrame >> toHtml [
22852287

22862288
dataFrame columnNames withIndexDo: [ :columnName :index |
22872289
| paddedColumnName |
2288-
paddedColumnName := columnName padRightTo: (columnWidths at: index).
2290+
paddedColumnName := (columnName isString
2291+
ifFalse: [ columnName asString ]
2292+
ifTrue: [ columnName ]) padRightTo:
2293+
(columnWidths at: index).
22892294
html
22902295
nextPutAll: ' <th>';
22912296
nextPutAll: paddedColumnName;

0 commit comments

Comments
 (0)