(
oldValue: string | number | boolean,
newValue: string | number | boolean,
options?: { inplace?: boolean }
)
| 1530 | options?: { inplace?: boolean } |
| 1531 | ): Series |
| 1532 | replace( |
| 1533 | oldValue: string | number | boolean, |
| 1534 | newValue: string | number | boolean, |
| 1535 | options?: { inplace?: boolean } |
| 1536 | ): Series | void { |
| 1537 | const { inplace } = { inplace: false, ...options } |
| 1538 | |
| 1539 | if (typeof oldValue === 'number' && isNaN(oldValue)) { |
| 1540 | throw Error(`Params Error: Param 'oldValue' does not support NaN. Use Series.fillNa() instead.`); |
| 1541 | } |
| 1542 | |
| 1543 | if (!oldValue && typeof oldValue !== 'boolean' && typeof oldValue !== 'number' && typeof oldValue !== 'string') { |
| 1544 | throw Error(`Params Error: Must specify param 'oldValue' to replace`); |
| 1545 | } |
| 1546 | |
| 1547 | if (!newValue && typeof newValue !== 'boolean' && typeof newValue !== 'number' && typeof newValue !== 'string') { |
| 1548 | throw Error(`Params Error: Must specify param 'newValue' to replace with`); |
| 1549 | } |
| 1550 | |
| 1551 | const newArr = [...this.values].map((val) => { |
| 1552 | if (val === oldValue) { |
| 1553 | return newValue |
| 1554 | } else { |
| 1555 | return val |
| 1556 | } |
| 1557 | }); |
| 1558 | |
| 1559 | if (inplace) { |
| 1560 | this.$setValues(newArr as ArrayType1D) |
| 1561 | } else { |
| 1562 | const sf = this.copy(); |
| 1563 | sf.$setValues(newArr as ArrayType1D) |
| 1564 | return sf; |
| 1565 | } |
| 1566 | |
| 1567 | } |
| 1568 | |
| 1569 | /** |
| 1570 | * Drops all missing values (NaN, null, undefined) from a Series. |
nothing calls this directly
no test coverage detected