Skip to content

Commit 15158c1

Browse files
authored
Merge pull request #254 from Joshua-Dias-Barreto/markdownPrinter
Fixed #253.
2 parents 509b47a + 7962e3d commit 15158c1

2 files changed

Lines changed: 147 additions & 9 deletions

File tree

src/DataFrame-Tests/DataFrameTest.class.st

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,6 +5167,60 @@ DataFrameTest >> testToHtml [
51675167
self assert: df toHtml equals: expectedString
51685168
]
51695169

5170+
{ #category : #tests }
5171+
DataFrameTest >> testToHtmlWithNumericColumnNames [
5172+
5173+
| expectedString weather |
5174+
expectedString := '<table border="1" class="dataframe">
5175+
<thead>
5176+
<tr style="text-align: left;"> <th># </th>
5177+
<th>1 </th>
5178+
<th>2 </th>
5179+
<th>3 </th>
5180+
</tr>
5181+
</thead>
5182+
<tbody>
5183+
<tr> <th>''01:10''</th>
5184+
<td>2.4 </td>
5185+
<td>true </td>
5186+
<td>#rain</td>
5187+
</tr>
5188+
<tr> <th>''01:30''</th>
5189+
<td>0.5 </td>
5190+
<td>true </td>
5191+
<td>#rain</td>
5192+
</tr>
5193+
<tr> <th>''01:50''</th>
5194+
<td>-1.2</td>
5195+
<td>true </td>
5196+
<td>#snow</td>
5197+
</tr>
5198+
<tr> <th>''02:10''</th>
5199+
<td>-2.3</td>
5200+
<td>false</td>
5201+
<td>#- </td>
5202+
</tr>
5203+
<tr> <th>''02:30''</th>
5204+
<td>3.2 </td>
5205+
<td>true </td>
5206+
<td>#rain</td>
5207+
</tr>
5208+
</tbody>
5209+
</table>'.
5210+
weather := DataFrame withRows:
5211+
#( #( 2.4 true rain )
5212+
#( 0.5 true rain )
5213+
#( -1.2 true snow )
5214+
#( -2.3 false #- )
5215+
#( 3.2 true rain ) ).
5216+
5217+
weather columnNames: #( 1 2 3 ).
5218+
5219+
weather rowNames: #( '01:10' '01:30' '01:50' '02:10' '02:30' ).
5220+
5221+
self assert: weather toHtml equals: expectedString
5222+
]
5223+
51705224
{ #category : #tests }
51715225
DataFrameTest >> testToLatex [
51725226

@@ -5186,6 +5240,39 @@ DataFrameTest >> testToLatex [
51865240
self assert: df toLatex equals: expectedString
51875241
]
51885242

5243+
{ #category : #tests }
5244+
DataFrameTest >> testToLatexWithNumericColumnNames [
5245+
5246+
| expectedString weather |
5247+
expectedString := '\begin{tabular}{|l|l|l|l|}
5248+
\hline
5249+
\# & 1 & 2 & 3 \\
5250+
\hline
5251+
''01:10'' & 2.4 & true & #rain\\
5252+
\hline
5253+
''01:30'' & 0.5 & true & #rain\\
5254+
\hline
5255+
''01:50'' & -1.2 & true & #snow\\
5256+
\hline
5257+
''02:10'' & -2.3 & false & #- \\
5258+
\hline
5259+
''02:30'' & 3.2 & true & #rain\\
5260+
\hline
5261+
\end{tabular}'.
5262+
weather := DataFrame withRows:
5263+
#( #( 2.4 true rain )
5264+
#( 0.5 true rain )
5265+
#( -1.2 true snow )
5266+
#( -2.3 false #- )
5267+
#( 3.2 true rain ) ).
5268+
5269+
weather columnNames: #( 1 2 3 ).
5270+
5271+
weather rowNames: #( '01:10' '01:30' '01:50' '02:10' '02:30' ).
5272+
5273+
self assert: weather toLatex equals: expectedString
5274+
]
5275+
51895276
{ #category : #tests }
51905277
DataFrameTest >> testToMarkdown [
51915278

@@ -5199,6 +5286,32 @@ DataFrameTest >> testToMarkdown [
51995286
self assert: df toMarkdown equals: expectedString
52005287
]
52015288

5289+
{ #category : #tests }
5290+
DataFrameTest >> testToMarkdownWithNumericColumnNames [
5291+
5292+
| expectedString weather|
5293+
expectedString := '| # | 1 | 2 | 3 |
5294+
| ------- | ---- | ----- | ----- |
5295+
| ''01:10'' | 2.4 | true | #rain |
5296+
| ''01:30'' | 0.5 | true | #rain |
5297+
| ''01:50'' | -1.2 | true | #snow |
5298+
| ''02:10'' | -2.3 | false | #- |
5299+
| ''02:30'' | 3.2 | true | #rain |
5300+
'.
5301+
weather := DataFrame withRows: #(
5302+
(2.4 true rain)
5303+
(0.5 true rain)
5304+
(-1.2 true snow)
5305+
(-2.3 false -)
5306+
(3.2 true rain)).
5307+
5308+
weather columnNames: #( 1 2 3).
5309+
5310+
weather rowNames: #( '01:10' '01:30' '01:50' '02:10' '02:30').
5311+
5312+
self assert: weather toMarkdown equals: expectedString
5313+
]
5314+
52025315
{ #category : #tests }
52035316
DataFrameTest >> testToString [
52045317

@@ -5212,6 +5325,31 @@ DataFrameTest >> testToString [
52125325
self assert: df toString equals: expectedString
52135326
]
52145327

5328+
{ #category : #tests }
5329+
DataFrameTest >> testToStringWithNumericColumnNames [
5330+
5331+
| expectedString weather |
5332+
expectedString := '# 1 2 3
5333+
''01:10'' 2.4 true #rain
5334+
''01:30'' 0.5 true #rain
5335+
''01:50'' -1.2 true #snow
5336+
''02:10'' -2.3 false #-
5337+
''02:30'' 3.2 true #rain
5338+
'.
5339+
weather := DataFrame withRows:
5340+
#( #( 2.4 true rain )
5341+
#( 0.5 true rain )
5342+
#( -1.2 true snow )
5343+
#( -2.3 false #- )
5344+
#( 3.2 true rain ) ).
5345+
5346+
weather columnNames: #( 1 2 3 ).
5347+
5348+
weather rowNames: #( '01:10' '01:30' '01:50' '02:10' '02:30' ).
5349+
5350+
self assert: weather toString equals: expectedString
5351+
]
5352+
52155353
{ #category : #tests }
52165354
DataFrameTest >> testTransposed [
52175355

src/DataFrame/DataFrame.class.st

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

22772277
columnWidths := dataFrame columnNames collect: [ :columnName |
22782278
| maxWidth |
2279-
maxWidth := columnName size.
2279+
maxWidth := columnName asString size.
22802280
dataFrame rows do: [ :row |
22812281
| value |
22822282
value := row at: columnName.
@@ -2285,7 +2285,7 @@ DataFrame >> toHtml [
22852285

22862286
dataFrame columnNames withIndexDo: [ :columnName :index |
22872287
| paddedColumnName |
2288-
paddedColumnName := columnName padRightTo: (columnWidths at: index).
2288+
paddedColumnName := columnName asString padRightTo: (columnWidths at: index).
22892289
html
22902290
nextPutAll: ' <th>';
22912291
nextPutAll: paddedColumnName;
@@ -2350,7 +2350,7 @@ DataFrame >> toLatex [
23502350

23512351
columnWidths := dataFrame columnNames collect: [ :columnName |
23522352
| maxWidth |
2353-
maxWidth := columnName size.
2353+
maxWidth := columnName asString size.
23542354
dataFrame rows do: [ :row |
23552355
| value |
23562356
value := row at: columnName.
@@ -2359,7 +2359,7 @@ DataFrame >> toLatex [
23592359

23602360
dataFrame columnNames withIndexDo: [ :columnName :index |
23612361
| paddedColumnName |
2362-
paddedColumnName := columnName padRightTo: (columnWidths at: index).
2362+
paddedColumnName := columnName asString padRightTo: (columnWidths at: index).
23632363
index = dataFrame numberOfColumns
23642364
ifFalse: [ markdown nextPutAll: paddedColumnName , ' & ' ]
23652365
ifTrue: [ markdown nextPutAll: paddedColumnName ] ].
@@ -2398,7 +2398,7 @@ DataFrame >> toMarkdown [
23982398

23992399
columnWidths := dataFrame columnNames collect: [ :columnName |
24002400
| maxWidth |
2401-
maxWidth := columnName size.
2401+
maxWidth := columnName asString size.
24022402
dataFrame rows do: [ :row |
24032403
| value |
24042404
value := row at: columnName.
@@ -2407,7 +2407,7 @@ DataFrame >> toMarkdown [
24072407

24082408
dataFrame columnNames withIndexDo: [ :columnName :index |
24092409
| paddedColumnName |
2410-
paddedColumnName := columnName padRightTo: (columnWidths at: index).
2410+
paddedColumnName := columnName asString padRightTo: (columnWidths at: index).
24112411
markdown nextPutAll: paddedColumnName , ' | ' ].
24122412
markdown cr.
24132413
markdown nextPutAll: '| '.
@@ -2443,7 +2443,7 @@ DataFrame >> toString [
24432443

24442444
columnWidths := dataFrame columnNames collect: [ :columnName |
24452445
| maxWidth |
2446-
maxWidth := columnName size.
2446+
maxWidth := columnName asString size.
24472447
dataFrame rows do: [ :row |
24482448
| value |
24492449
value := row at: columnName.
@@ -2452,8 +2452,8 @@ DataFrame >> toString [
24522452

24532453
dataFrame columnNames withIndexDo: [ :columnName :index |
24542454
| paddedColumnName |
2455-
paddedColumnName := columnName padRightTo: (columnWidths at: index).
2456-
stringTable nextPutAll: paddedColumnName, ' ' ].
2455+
paddedColumnName := columnName asString padRightTo: (columnWidths at: index).
2456+
stringTable nextPutAll: paddedColumnName , ' ' ].
24572457
stringTable cr.
24582458

24592459

0 commit comments

Comments
 (0)