@@ -23,7 +23,7 @@ export default class Groupby {
2323 colDtype : ArrayType1D
2424 colIndex : ArrayType1D
2525 groupDict ?: any
26- groupColNames ?: ArrayType1D
26+ groupColNames ?: Array < string >
2727
2828 constructor ( keyCol : ArrayType1D , data : ArrayType2D | null , columnName : ArrayType1D , colDtype :ArrayType1D , colIndex : ArrayType1D ) {
2929
@@ -138,15 +138,15 @@ export default class Groupby {
138138 this . colIndex
139139 )
140140 gp . colDict = colDict
141- gp . groupColNames = colNames
141+ gp . groupColNames = colNames as Array < string >
142142
143143 return gp
144144 }
145145
146146 arithemetic ( operation : { [ key : string ] : string } | string ) : { [ key : string ] : { } } {
147147
148148 const opsName = [ "mean" , "sum" , "count" , "mode" , "std" , "var" , "cumsum" , "cumprod" ,
149- "cummax" , "cummin" , "median" ] ;
149+ "cummax" , "cummin" , "median" , "min" ] ;
150150 if ( typeof operation === "string" ) {
151151 if ( ! opsName . includes ( operation ) ) {
152152 throw new Error ( `group operation: ${ operation } is not valid` )
@@ -160,20 +160,21 @@ export default class Groupby {
160160 } )
161161 }
162162 let colDict : { [ key : string ] : { } } = { ...this . colDict }
163- for ( const [ key , values ] of Object . entries ( this . colDict ) ) {
163+ for ( const [ key , values ] of Object . entries ( colDict ) ) {
164164 let colVal : { [ key : string ] : Array < number > } = { }
165165 let keyVal : any = { ...values }
166- for ( let colKey in this . groupColNames ) {
167- let colName = this . groupColNames [ colKey ] as string
166+ let groupColNames : Array < string > = this . groupColNames as Array < string >
167+ for ( let colKey = 0 ; colKey < groupColNames . length ; colKey ++ ) {
168+ let colName = groupColNames [ colKey ]
168169 let colIndex = this . columnName . indexOf ( colName )
169170 let colDtype = this . colDtype [ colIndex ]
170171 if ( colDtype === "string" ) throw new Error ( `Can't perform math operation on column ${ colName } ` )
171172
172173 if ( typeof operation === "string" ) {
173- colVal [ key ] = this . groupMathLog ( keyVal [ colName ] , operation )
174+ colVal [ colName ] = this . groupMathLog ( keyVal [ colName ] , operation )
174175 }
175176 else {
176- colVal [ key ] = this . groupMathLog ( keyVal [ colName ] , operation [ colName ] )
177+ colVal [ colName ] = this . groupMathLog ( keyVal [ colName ] , operation [ colName ] )
177178 }
178179 }
179180 colDict [ key ] = colVal
0 commit comments