@@ -466,7 +466,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
466
466
467
467
* @param other DataFrame to vertically add.
468
468
*/
469
- extend ( other : DataFrame ) : DataFrame ;
469
+ extend ( other : DataFrame < T > ) : DataFrame < T > ;
470
470
/**
471
471
* Fill null/missing values by a filling strategy
472
472
*
@@ -480,7 +480,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
480
480
* - "one"
481
481
* @returns DataFrame with None replaced with the filling strategy.
482
482
*/
483
- fillNull ( strategy : FillNullStrategy ) : DataFrame ;
483
+ fillNull ( strategy : FillNullStrategy ) : DataFrame < T > ;
484
484
/**
485
485
* Filter the rows in the DataFrame based on a predicate expression.
486
486
* ___
@@ -519,7 +519,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
519
519
* └─────┴─────┴─────┘
520
520
* ```
521
521
*/
522
- filter ( predicate : any ) : DataFrame ;
522
+ filter ( predicate : any ) : DataFrame < T > ;
523
523
/**
524
524
* Find the index of a column by name.
525
525
* ___
@@ -764,7 +764,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
764
764
/**
765
765
* Interpolate intermediate values. The interpolation method is linear.
766
766
*/
767
- interpolate ( ) : DataFrame ;
767
+ interpolate ( ) : DataFrame < T > ;
768
768
/**
769
769
* Get a mask of all duplicated rows in this DataFrame.
770
770
*/
@@ -937,8 +937,11 @@ export interface DataFrame<T extends Record<string, Series> = any>
937
937
* Get first N rows as DataFrame.
938
938
* @see {@link head }
939
939
*/
940
- limit ( length ?: number ) : DataFrame ;
941
- map ( func : ( ...args : any [ ] ) => any ) : any [ ] ;
940
+ limit ( length ?: number ) : DataFrame < T > ;
941
+ map < ReturnT > (
942
+ // TODO: strong types for the mapping function
943
+ func : ( row : any [ ] , i : number , arr : any [ ] [ ] ) => ReturnT ,
944
+ ) : ReturnT [ ] ;
942
945
943
946
/**
944
947
* Aggregate the columns of this DataFrame to their maximum value.
@@ -962,8 +965,8 @@ export interface DataFrame<T extends Record<string, Series> = any>
962
965
* ╰─────┴─────┴──────╯
963
966
* ```
964
967
*/
965
- max ( ) : DataFrame ;
966
- max ( axis : 0 ) : DataFrame ;
968
+ max ( ) : DataFrame < T > ;
969
+ max ( axis : 0 ) : DataFrame < T > ;
967
970
max ( axis : 1 ) : Series ;
968
971
/**
969
972
* Aggregate the columns of this DataFrame to their mean value.
@@ -972,8 +975,8 @@ export interface DataFrame<T extends Record<string, Series> = any>
972
975
* @param axis - either 0 or 1
973
976
* @param nullStrategy - this argument is only used if axis == 1
974
977
*/
975
- mean ( ) : DataFrame ;
976
- mean ( axis : 0 ) : DataFrame ;
978
+ mean ( ) : DataFrame < T > ;
979
+ mean ( axis : 0 ) : DataFrame < T > ;
977
980
mean ( axis : 1 ) : Series ;
978
981
mean ( axis : 1 , nullStrategy ?: "ignore" | "propagate" ) : Series ;
979
982
/**
@@ -997,7 +1000,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
997
1000
* ╰─────┴─────┴──────╯
998
1001
* ```
999
1002
*/
1000
- median ( ) : DataFrame ;
1003
+ median ( ) : DataFrame < T > ;
1001
1004
/**
1002
1005
* Unpivot a DataFrame from wide to long format.
1003
1006
* @deprecated *since 0.13.0* use {@link unpivot}
@@ -1059,8 +1062,8 @@ export interface DataFrame<T extends Record<string, Series> = any>
1059
1062
* ╰─────┴─────┴──────╯
1060
1063
* ```
1061
1064
*/
1062
- min ( ) : DataFrame ;
1063
- min ( axis : 0 ) : DataFrame ;
1065
+ min ( ) : DataFrame < T > ;
1066
+ min ( axis : 0 ) : DataFrame < T > ;
1064
1067
min ( axis : 1 ) : Series ;
1065
1068
/**
1066
1069
* Get number of chunks used by the ChunkedArrays of this DataFrame.
@@ -1087,12 +1090,14 @@ export interface DataFrame<T extends Record<string, Series> = any>
1087
1090
* └─────┴─────┴─────┘
1088
1091
* ```
1089
1092
*/
1090
- nullCount ( ) : DataFrame ;
1093
+ nullCount ( ) : DataFrame < {
1094
+ [ K in keyof T ] : Series < JsToDtype < number > , K & string > ;
1095
+ } > ;
1091
1096
partitionBy (
1092
1097
cols : string | string [ ] ,
1093
1098
stable ?: boolean ,
1094
1099
includeKey ?: boolean ,
1095
- ) : DataFrame [ ] ;
1100
+ ) : DataFrame < T > [ ] ;
1096
1101
partitionBy < T > (
1097
1102
cols : string | string [ ] ,
1098
1103
stable : boolean ,
@@ -1210,13 +1215,13 @@ export interface DataFrame<T extends Record<string, Series> = any>
1210
1215
* ╰─────┴─────┴──────╯
1211
1216
* ```
1212
1217
*/
1213
- quantile ( quantile : number ) : DataFrame ;
1218
+ quantile ( quantile : number ) : DataFrame < T > ;
1214
1219
/**
1215
1220
* __Rechunk the data in this DataFrame to a contiguous allocation.__
1216
1221
*
1217
1222
* This will make sure all subsequent operations have optimal and predictable performance.
1218
1223
*/
1219
- rechunk ( ) : DataFrame ;
1224
+ rechunk ( ) : DataFrame < T > ;
1220
1225
/**
1221
1226
* __Rename column names.__
1222
1227
* ___
@@ -1443,12 +1448,15 @@ export interface DataFrame<T extends Record<string, Series> = any>
1443
1448
* └─────┴─────┴─────┘
1444
1449
* ```
1445
1450
*/
1446
- shiftAndFill ( n : number , fillValue : number ) : DataFrame ;
1447
- shiftAndFill ( { n, fillValue } : { n : number ; fillValue : number } ) : DataFrame ;
1451
+ shiftAndFill ( n : number , fillValue : number ) : DataFrame < T > ;
1452
+ shiftAndFill ( {
1453
+ n,
1454
+ fillValue,
1455
+ } : { n : number ; fillValue : number } ) : DataFrame < T > ;
1448
1456
/**
1449
1457
* Shrink memory usage of this DataFrame to fit the exact capacity needed to hold the data.
1450
1458
*/
1451
- shrinkToFit ( ) : DataFrame ;
1459
+ shrinkToFit ( ) : DataFrame < T > ;
1452
1460
shrinkToFit ( inPlace : true ) : void ;
1453
1461
shrinkToFit ( { inPlace } : { inPlace : true } ) : void ;
1454
1462
/**
@@ -1477,8 +1485,8 @@ export interface DataFrame<T extends Record<string, Series> = any>
1477
1485
* └─────┴─────┴─────┘
1478
1486
* ```
1479
1487
*/
1480
- slice ( { offset, length } : { offset : number ; length : number } ) : DataFrame ;
1481
- slice ( offset : number , length : number ) : DataFrame ;
1488
+ slice ( { offset, length } : { offset : number ; length : number } ) : DataFrame < T > ;
1489
+ slice ( offset : number , length : number ) : DataFrame < T > ;
1482
1490
/**
1483
1491
* Sort the DataFrame by column.
1484
1492
* ___
@@ -1493,7 +1501,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1493
1501
descending ?: boolean ,
1494
1502
nullsLast ?: boolean ,
1495
1503
maintainOrder ?: boolean ,
1496
- ) : DataFrame ;
1504
+ ) : DataFrame < T > ;
1497
1505
sort ( {
1498
1506
by,
1499
1507
reverse, // deprecated
@@ -1504,7 +1512,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1504
1512
reverse ?: boolean ; // deprecated
1505
1513
nullsLast ?: boolean ;
1506
1514
maintainOrder ?: boolean ;
1507
- } ) : DataFrame ;
1515
+ } ) : DataFrame < T > ;
1508
1516
sort ( {
1509
1517
by,
1510
1518
descending,
@@ -1514,7 +1522,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1514
1522
descending ?: boolean ;
1515
1523
nullsLast ?: boolean ;
1516
1524
maintainOrder ?: boolean ;
1517
- } ) : DataFrame ;
1525
+ } ) : DataFrame < T > ;
1518
1526
/**
1519
1527
* Aggregate the columns of this DataFrame to their standard deviation value.
1520
1528
* ___
@@ -1536,16 +1544,16 @@ export interface DataFrame<T extends Record<string, Series> = any>
1536
1544
* ╰─────┴─────┴──────╯
1537
1545
* ```
1538
1546
*/
1539
- std ( ) : DataFrame ;
1547
+ std ( ) : DataFrame < T > ;
1540
1548
/**
1541
1549
* Aggregate the columns of this DataFrame to their mean value.
1542
1550
* ___
1543
1551
*
1544
1552
* @param axis - either 0 or 1
1545
1553
* @param nullStrategy - this argument is only used if axis == 1
1546
1554
*/
1547
- sum ( ) : DataFrame ;
1548
- sum ( axis : 0 ) : DataFrame ;
1555
+ sum ( ) : DataFrame < T > ;
1556
+ sum ( axis : 0 ) : DataFrame < T > ;
1549
1557
sum ( axis : 1 ) : Series ;
1550
1558
sum ( axis : 1 , nullStrategy ?: "ignore" | "propagate" ) : Series ;
1551
1559
/**
@@ -1595,7 +1603,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1595
1603
* ╰─────────┴─────╯
1596
1604
* ```
1597
1605
*/
1598
- tail ( length ?: number ) : DataFrame ;
1606
+ tail ( length ?: number ) : DataFrame < T > ;
1599
1607
/**
1600
1608
* @deprecated *since 0.4.0* use {@link writeCSV}
1601
1609
* @category Deprecated
@@ -1614,7 +1622,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1614
1622
* ```
1615
1623
* @category IO
1616
1624
*/
1617
- toRecords ( ) : Record < string , any > [ ] ;
1625
+ toRecords ( ) : { [ K in keyof T ] : DTypeToJs < T [ K ] [ "dtype" ] > | null } [ ] ;
1618
1626
1619
1627
/**
1620
1628
* compat with `JSON.stringify`
@@ -1644,7 +1652,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1644
1652
* ```
1645
1653
* @category IO
1646
1654
*/
1647
- toObject ( ) : { [ K in keyof T ] : DTypeToJs < T [ K ] [ "dtype" ] > [ ] } ;
1655
+ toObject ( ) : { [ K in keyof T ] : DTypeToJs < T [ K ] [ "dtype" ] | null > [ ] } ;
1648
1656
1649
1657
/**
1650
1658
* @deprecated *since 0.4.0* use {@link writeIPC}
@@ -1656,7 +1664,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1656
1664
* @category IO Deprecated
1657
1665
*/
1658
1666
toParquet ( destination ?, options ?) ;
1659
- toSeries ( index ?: number ) : Series ;
1667
+ toSeries ( index ?: number ) : T [ keyof T ] ;
1660
1668
toString ( ) : string ;
1661
1669
/**
1662
1670
* Convert a ``DataFrame`` to a ``Series`` of type ``Struct``
@@ -1768,12 +1776,12 @@ export interface DataFrame<T extends Record<string, Series> = any>
1768
1776
maintainOrder ?: boolean ,
1769
1777
subset ?: ColumnSelection ,
1770
1778
keep ?: "first" | "last" ,
1771
- ) : DataFrame ;
1779
+ ) : DataFrame < T > ;
1772
1780
unique ( opts : {
1773
1781
maintainOrder ?: boolean ;
1774
1782
subset ?: ColumnSelection ;
1775
1783
keep ?: "first" | "last" ;
1776
- } ) : DataFrame ;
1784
+ } ) : DataFrame < T > ;
1777
1785
/**
1778
1786
Decompose a struct into its fields. The fields will be inserted in to the `DataFrame` on the
1779
1787
location of the `struct` type.
@@ -1833,7 +1841,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1833
1841
* ╰─────┴─────┴──────╯
1834
1842
* ```
1835
1843
*/
1836
- var ( ) : DataFrame ;
1844
+ var ( ) : DataFrame < T > ;
1837
1845
/**
1838
1846
* Grow this DataFrame vertically by stacking a DataFrame to it.
1839
1847
* @param df - DataFrame to stack.
@@ -1866,12 +1874,16 @@ export interface DataFrame<T extends Record<string, Series> = any>
1866
1874
* ╰─────┴─────┴─────╯
1867
1875
* ```
1868
1876
*/
1869
- vstack ( df : DataFrame ) : DataFrame ;
1877
+ vstack ( df : DataFrame < T > ) : DataFrame < T > ;
1870
1878
/**
1871
1879
* Return a new DataFrame with the column added or replaced.
1872
1880
* @param column - Series, where the name of the Series refers to the column in the DataFrame.
1873
1881
*/
1874
- withColumn ( column : Series | Expr ) : DataFrame ;
1882
+ withColumn < SeriesTypeT extends DataType , SeriesNameT extends string > (
1883
+ column : Series < SeriesTypeT , SeriesNameT > ,
1884
+ ) : DataFrame <
1885
+ Simplify < T & { [ K in SeriesNameT ] : Series < SeriesTypeT , SeriesNameT > } >
1886
+ > ;
1875
1887
withColumn ( column : Series | Expr ) : DataFrame ;
1876
1888
withColumns ( ...columns : ( Expr | Series ) [ ] ) : DataFrame ;
1877
1889
/**
@@ -1896,7 +1908,7 @@ export interface DataFrame<T extends Record<string, Series> = any>
1896
1908
*/
1897
1909
withRowCount ( name ?: string ) : DataFrame ;
1898
1910
/** @see {@link filter } */
1899
- where ( predicate : any ) : DataFrame ;
1911
+ where ( predicate : any ) : DataFrame < T > ;
1900
1912
/**
1901
1913
Upsample a DataFrame at a regular frequency.
1902
1914
@@ -1972,13 +1984,13 @@ shape: (7, 3)
1972
1984
every : string ,
1973
1985
by ?: string | string [ ] ,
1974
1986
maintainOrder ?: boolean ,
1975
- ) : DataFrame ;
1987
+ ) : DataFrame < T > ;
1976
1988
upsample ( opts : {
1977
1989
timeColumn : string ;
1978
1990
every : string ;
1979
1991
by ?: string | string [ ] ;
1980
1992
maintainOrder ?: boolean ;
1981
- } ) : DataFrame ;
1993
+ } ) : DataFrame < T > ;
1982
1994
}
1983
1995
1984
1996
function prepareOtherArg ( anyValue : any ) : Series {
0 commit comments