@@ -214,7 +214,10 @@ export class Series<T extends Scalar = Scalar> {
214214
215215 // ─── arithmetic ───────────────────────────────────────────────────────────
216216
217- private _scalarOp ( other : T | Series < T > , fn : ( a : number , b : number ) => number ) : Series < number > {
217+ private _scalarOp (
218+ other : number | Series < Scalar > ,
219+ fn : ( a : number , b : number ) => number ,
220+ ) : Series < number > {
218221 const isScalar = ! ( other instanceof Series ) ;
219222 if ( isScalar ) {
220223 const b = other as number ;
@@ -229,7 +232,7 @@ export class Series<T extends Scalar = Scalar> {
229232 name : this . name ,
230233 } ) ;
231234 }
232- const o = other as Series < T > ;
235+ const o = other as Series < Scalar > ;
233236 if ( o . size !== this . size ) {
234237 throw new RangeError (
235238 `Cannot operate on Series of different sizes: ${ this . size } vs ${ o . size } ` ,
@@ -249,46 +252,49 @@ export class Series<T extends Scalar = Scalar> {
249252 }
250253
251254 /** Element-wise addition. */
252- add ( other : T | Series < T > ) : Series < number > {
255+ add ( other : number | Series < Scalar > ) : Series < number > {
253256 return this . _scalarOp ( other , ( a , b ) => a + b ) ;
254257 }
255258
256259 /** Element-wise subtraction. */
257- sub ( other : T | Series < T > ) : Series < number > {
260+ sub ( other : number | Series < Scalar > ) : Series < number > {
258261 return this . _scalarOp ( other , ( a , b ) => a - b ) ;
259262 }
260263
261264 /** Element-wise multiplication. */
262- mul ( other : T | Series < T > ) : Series < number > {
265+ mul ( other : number | Series < Scalar > ) : Series < number > {
263266 return this . _scalarOp ( other , ( a , b ) => a * b ) ;
264267 }
265268
266269 /** Element-wise division (true division, returns float). */
267- div ( other : T | Series < T > ) : Series < number > {
270+ div ( other : number | Series < Scalar > ) : Series < number > {
268271 return this . _scalarOp ( other , ( a , b ) => a / b ) ;
269272 }
270273
271274 /** Element-wise floor division. */
272- floordiv ( other : T | Series < T > ) : Series < number > {
275+ floordiv ( other : number | Series < Scalar > ) : Series < number > {
273276 return this . _scalarOp ( other , ( a , b ) => Math . floor ( a / b ) ) ;
274277 }
275278
276279 /** Element-wise modulo. */
277- mod ( other : T | Series < T > ) : Series < number > {
280+ mod ( other : number | Series < Scalar > ) : Series < number > {
278281 return this . _scalarOp ( other , ( a , b ) => a % b ) ;
279282 }
280283
281284 /** Element-wise exponentiation. */
282- pow ( other : T | Series < T > ) : Series < number > {
285+ pow ( other : number | Series < Scalar > ) : Series < number > {
283286 return this . _scalarOp ( other , ( a , b ) => a ** b ) ;
284287 }
285288
286289 // ─── comparison ───────────────────────────────────────────────────────────
287290
288- private _cmpOp ( other : T | Series < T > , fn : ( a : T , b : T ) => boolean ) : Series < boolean > {
291+ private _cmpOp (
292+ other : Scalar | Series < Scalar > ,
293+ fn : ( a : Scalar , b : Scalar ) => boolean ,
294+ ) : Series < boolean > {
289295 const isScalar = ! ( other instanceof Series ) ;
290296 if ( isScalar ) {
291- const b = other as T ;
297+ const b = other as Scalar ;
292298 const newData = this . _values . map ( ( a ) => fn ( a , b ) ) ;
293299 return new Series < boolean > ( {
294300 data : newData ,
@@ -297,11 +303,11 @@ export class Series<T extends Scalar = Scalar> {
297303 name : this . name ,
298304 } ) ;
299305 }
300- const o = other as Series < T > ;
306+ const o = other as Series < Scalar > ;
301307 if ( o . size !== this . size ) {
302308 throw new RangeError ( `Cannot compare Series of different sizes: ${ this . size } vs ${ o . size } ` ) ;
303309 }
304- const newData = this . _values . map ( ( a , i ) => fn ( a , o . _values [ i ] as T ) ) ;
310+ const newData = this . _values . map ( ( a , i ) => fn ( a , o . _values [ i ] as Scalar ) ) ;
305311 return new Series < boolean > ( {
306312 data : newData ,
307313 index : this . index ,
@@ -310,15 +316,15 @@ export class Series<T extends Scalar = Scalar> {
310316 } ) ;
311317 }
312318
313- eq ( other : T | Series < T > ) : Series < boolean > {
319+ eq ( other : Scalar | Series < Scalar > ) : Series < boolean > {
314320 return this . _cmpOp ( other , ( a , b ) => a === b ) ;
315321 }
316322
317- ne ( other : T | Series < T > ) : Series < boolean > {
323+ ne ( other : Scalar | Series < Scalar > ) : Series < boolean > {
318324 return this . _cmpOp ( other , ( a , b ) => a !== b ) ;
319325 }
320326
321- lt ( other : T | Series < T > ) : Series < boolean > {
327+ lt ( other : Scalar | Series < Scalar > ) : Series < boolean > {
322328 return this . _cmpOp ( other , ( a , b ) => {
323329 if ( a === null || b === null ) {
324330 return false ;
@@ -327,7 +333,7 @@ export class Series<T extends Scalar = Scalar> {
327333 } ) ;
328334 }
329335
330- le ( other : T | Series < T > ) : Series < boolean > {
336+ le ( other : Scalar | Series < Scalar > ) : Series < boolean > {
331337 return this . _cmpOp ( other , ( a , b ) => {
332338 if ( a === null || b === null ) {
333339 return false ;
@@ -336,7 +342,7 @@ export class Series<T extends Scalar = Scalar> {
336342 } ) ;
337343 }
338344
339- gt ( other : T | Series < T > ) : Series < boolean > {
345+ gt ( other : Scalar | Series < Scalar > ) : Series < boolean > {
340346 return this . _cmpOp ( other , ( a , b ) => {
341347 if ( a === null || b === null ) {
342348 return false ;
@@ -345,7 +351,7 @@ export class Series<T extends Scalar = Scalar> {
345351 } ) ;
346352 }
347353
348- ge ( other : T | Series < T > ) : Series < boolean > {
354+ ge ( other : Scalar | Series < Scalar > ) : Series < boolean > {
349355 return this . _cmpOp ( other , ( a , b ) => {
350356 if ( a === null || b === null ) {
351357 return false ;
@@ -648,8 +654,8 @@ export class Series<T extends Scalar = Scalar> {
648654 // ─── set operations ───────────────────────────────────────────────────────
649655
650656 /** True when `value` exists in this Series. */
651- isin ( values : readonly T [ ] ) : Series < boolean > {
652- const set = new Set < T > ( values ) ;
657+ isin ( values : readonly Scalar [ ] ) : Series < boolean > {
658+ const set = new Set < Scalar > ( values ) ;
653659 return new Series < boolean > ( {
654660 data : this . _values . map ( ( v ) => set . has ( v ) ) ,
655661 index : this . index ,
0 commit comments