WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c604929

Browse files
committed
Fixed Replacing a value with 0 with dataframe.replace throws an error
Fixes #621
1 parent 6b4431f commit c604929

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/danfojs-base/core/frame.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,16 +2759,24 @@ export default class DataFrame extends NDframe implements DataFrameInterface {
27592759
): DataFrame | void {
27602760
const { columns, inplace } = { inplace: false, ...options }
27612761

2762+
if (oldValue === undefined) {
2763+
throw Error(`Params Error: Must specify param 'oldValue' to replace`);
2764+
}
2765+
2766+
if (newValue === undefined) {
2767+
throw Error(`Params Error: Must specify param 'newValue' to replace with`);
2768+
}
2769+
27622770
if (typeof oldValue === 'number' && isNaN(oldValue)) {
2763-
throw Error(`Params Error: Param 'oldValue' does not support NaN. Use DataFrame.fillNa() instead.`);
2771+
throw Error(`Params Error: Param 'oldValue' does not support NaN. Use Series.fillNa() instead.`);
27642772
}
27652773

2766-
if (!oldValue && typeof oldValue !== 'boolean' && typeof oldValue !== 'number' && typeof oldValue !== 'string') {
2767-
throw Error(`Params Error: Must specify param 'oldValue' to replace`);
2774+
if (typeof oldValue !== 'boolean' && typeof oldValue !== 'number' && typeof oldValue !== 'string') {
2775+
throw Error(`Params Error: Param 'oldValue' must be of type string or number or boolean.`);
27682776
}
27692777

2770-
if (!newValue && typeof newValue !== 'boolean' && typeof newValue !== 'number' && typeof newValue !== 'string') {
2771-
throw Error(`Params Error: Must specify param 'newValue' to replace with`);
2778+
if (typeof newValue !== 'boolean' && typeof newValue !== 'number' && typeof newValue !== 'string') {
2779+
throw Error(`Params Error: Param 'newValue' must be of type string or number or boolean.`);
27722780
}
27732781

27742782
let newData: ArrayType2D = []

src/danfojs-base/core/series.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,16 +1536,24 @@ export default class Series extends NDframe implements SeriesInterface {
15361536
): Series | void {
15371537
const { inplace } = { inplace: false, ...options }
15381538

1539+
if (oldValue === undefined) {
1540+
throw Error(`Params Error: Must specify param 'oldValue' to replace`);
1541+
}
1542+
1543+
if (newValue === undefined) {
1544+
throw Error(`Params Error: Must specify param 'newValue' to replace with`);
1545+
}
1546+
15391547
if (typeof oldValue === 'number' && isNaN(oldValue)) {
15401548
throw Error(`Params Error: Param 'oldValue' does not support NaN. Use Series.fillNa() instead.`);
15411549
}
15421550

1543-
if (!oldValue && typeof oldValue !== 'boolean' && typeof oldValue !== 'number' && typeof oldValue !== 'string') {
1544-
throw Error(`Params Error: Must specify param 'oldValue' to replace`);
1551+
if (typeof oldValue !== 'boolean' && typeof oldValue !== 'number' && typeof oldValue !== 'string') {
1552+
throw Error(`Params Error: Param 'oldValue' must be of type string or number or boolean.`);
15451553
}
15461554

1547-
if (!newValue && typeof newValue !== 'boolean' && typeof newValue !== 'number' && typeof newValue !== 'string') {
1548-
throw Error(`Params Error: Must specify param 'newValue' to replace with`);
1555+
if (typeof newValue !== 'boolean' && typeof newValue !== 'number' && typeof newValue !== 'string') {
1556+
throw Error(`Params Error: Param 'newValue' must be of type string or number or boolean.`);
15491557
}
15501558

15511559
const newArr = [...this.values].map((val) => {

0 commit comments

Comments
 (0)