File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -1104,6 +1104,22 @@ describe("dataframe", () => {
1104
1104
const actual = df . transpose ( { includeHeader : false , columnNames : "abc" } ) ;
1105
1105
expect ( actual ) . toFrameEqual ( expected ) ;
1106
1106
} ) ;
1107
+ test ( "transpose:columnNames:array" , ( ) => {
1108
+ const expected = pl . DataFrame ( {
1109
+ a : [ 1 , 1 ] ,
1110
+ b : [ 2 , 2 ] ,
1111
+ c : [ 3 , 3 ] ,
1112
+ } ) ;
1113
+ const df = pl . DataFrame ( {
1114
+ a : [ 1 , 2 , 3 ] ,
1115
+ b : [ 1 , 2 , 3 ] ,
1116
+ } ) ;
1117
+ const actual = df . transpose ( {
1118
+ includeHeader : false ,
1119
+ columnNames : [ "a" , "b" , "c" ] ,
1120
+ } ) ;
1121
+ expect ( actual ) . toFrameEqual ( expected ) ;
1122
+ } ) ;
1107
1123
test ( "transpose:columnNames:generator" , ( ) => {
1108
1124
const expected = pl . DataFrame ( {
1109
1125
col_0 : [ 1 , 1 ] ,
Original file line number Diff line number Diff line change @@ -1594,7 +1594,7 @@ export interface DataFrame
1594
1594
includeHeader ?: boolean ;
1595
1595
headerName ?: string ;
1596
1596
columnNames ?: Iterable < string > ;
1597
- } ) ;
1597
+ } ) : DataFrame ;
1598
1598
/**
1599
1599
* Drop duplicate rows from this DataFrame.
1600
1600
* Note that this fails if there is a column of type `List` in the DataFrame.
@@ -2521,7 +2521,7 @@ export const _DataFrame = (_df: any): DataFrame => {
2521
2521
const headeName = options ?. headerName ?? "column" ;
2522
2522
const keep_names_as = includeHeader ? headeName : undefined ;
2523
2523
if ( options ?. columnNames ) {
2524
- function takeNItems ( iterable : Iterable < string > , n ) {
2524
+ function takeNItems ( iterable : Iterable < string > , n : number ) {
2525
2525
const result : Array < string > = [ ] ;
2526
2526
let i = 0 ;
2527
2527
for ( const item of iterable ) {
@@ -2534,7 +2534,7 @@ export const _DataFrame = (_df: any): DataFrame => {
2534
2534
return result ;
2535
2535
}
2536
2536
options . columnNames = Array . isArray ( options . columnNames )
2537
- ? options . columnNames . slice ( this . height )
2537
+ ? options . columnNames . slice ( 0 , this . height )
2538
2538
: takeNItems ( options . columnNames , this . height ) ;
2539
2539
}
2540
2540
if ( ! options ?. columnNames ) {
You can’t perform that action at this time.
0 commit comments