File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -421,6 +421,52 @@ DataFrameTest >> testAsArrayOfRowsWithName [
421421 equals: expected asOrderedCollection
422422]
423423
424+ { #category : #tests }
425+ DataFrameTest >> testAsDataFrame [
426+
427+ | actual expected |
428+ actual := #( #( 1 2 3 )
429+ #( 4 5 6 )
430+ #( 7 8 9 ) ) asDataFrame.
431+ expected := DataFrame withRows: #( #( 1 2 3 ) #( 4 5 6 ) #( 7 8 9 ) ).
432+
433+ self assert: actual equals: expected
434+ ]
435+
436+ { #category : #tests }
437+ DataFrameTest >> testAsDataFrameEmpty [
438+
439+ | actual expected |
440+ actual := #() asDataFrame.
441+ expected := DataFrame new .
442+
443+ self assert: actual equals: expected
444+ ]
445+
446+ { #category : #tests }
447+ DataFrameTest >> testAsDataFrameEmptyColumns [
448+
449+ | actual expected |
450+ actual := #( #()
451+ #()
452+ #() ) asDataFrame.
453+ expected := DataFrame new : 3 @ 0 .
454+
455+ self assert: actual equals: expected
456+ ]
457+
458+ { #category : #tests }
459+ DataFrameTest >> testAsDataFrameWithUnevenRowElements [
460+
461+ | actual expected |
462+ actual := #( #( 1 2 )
463+ #( 3 4 5 )
464+ #( 6 7 8 9 ) ) asDataFrame.
465+ expected := DataFrame withRows: #( #( 1 2 ) #( 3 4 5 ) #( 6 7 8 9 ) ).
466+
467+ self assert: actual equals: expected
468+ ]
469+
424470{ #category : #tests }
425471DataFrameTest >> testAt [
426472
Original file line number Diff line number Diff line change @@ -6,6 +6,28 @@ Collection >> ** arg [
66 ^ self raisedTo: arg
77]
88
9+ { #category : #' *DataFrame' }
10+ Collection >> asDataFrame [
11+
12+ | numberOfRows numberOfColumns dataFrame |
13+ numberOfRows := self size.
14+ numberOfColumns := 0 .
15+ numberOfRows = 0 ifFalse: [
16+ numberOfColumns := (self collect: #size ) max ].
17+ dataFrame := DataFrame new : numberOfRows @ numberOfColumns.
18+
19+ 1 to: numberOfRows do: [ :rowIndex |
20+ | row |
21+ row := self at: rowIndex.
22+ 1 to: numberOfColumns do: [ :colIndex |
23+ | value |
24+ value := row at: colIndex ifAbsent: [ nil ].
25+ dataFrame at: rowIndex at: colIndex put: value ] ].
26+
27+
28+ ^ dataFrame
29+ ]
30+
931{ #category : #' *DataFrame-Core-Base' }
1032Collection >> asDataSeries [
1133
You can’t perform that action at this time.
0 commit comments