Skip to content

Commit 4f61df2

Browse files
Copied the dataframe so that it doesn't change the original.
1 parent 7c70f3c commit 4f61df2

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/DataFrame/DataFrame.class.st

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,21 +2263,22 @@ DataFrame >> toColumnsAt: arrayOfColumnNumbers applyElementwise: aBlock [
22632263
DataFrame >> toMarkdown [
22642264
" Prints the DataFrame as a Markdown formatted table"
22652265

2266-
| markdown columnWidths |
2267-
self addColumn: self rowNames named: '#' atPosition: 1.
2266+
| markdown columnWidths dataFrame |
2267+
dataFrame := self copy.
2268+
dataFrame addColumn: dataFrame rowNames named: '#' atPosition: 1.
22682269
markdown := WriteStream on: String new.
22692270
markdown nextPutAll: '| '.
22702271

2271-
columnWidths := self columnNames collect: [ :columnName |
2272+
columnWidths := dataFrame columnNames collect: [ :columnName |
22722273
| maxWidth |
22732274
maxWidth := columnName size.
2274-
self rows do: [ :row |
2275+
dataFrame rows do: [ :row |
22752276
| value |
22762277
value := row at: columnName.
22772278
maxWidth := maxWidth max: value printString size ].
22782279
maxWidth ].
22792280

2280-
self columnNames withIndexDo: [ :columnName :index |
2281+
dataFrame columnNames withIndexDo: [ :columnName :index |
22812282
| paddedColumnName |
22822283
paddedColumnName := columnName padRightTo: (columnWidths at: index).
22832284
markdown nextPutAll: paddedColumnName , ' | ' ].
@@ -2292,7 +2293,7 @@ DataFrame >> toMarkdown [
22922293

22932294
markdown cr.
22942295

2295-
self asArrayOfRows do: [ :row |
2296+
dataFrame asArrayOfRows do: [ :row |
22962297
markdown nextPutAll: '| '.
22972298
row withIndexDo: [ :value :index |
22982299
| paddedValue |

0 commit comments

Comments
 (0)