Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/danfojs-base/core/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2759,16 +2759,24 @@ export default class DataFrame extends NDframe implements DataFrameInterface {
): DataFrame | void {
const { columns, inplace } = { inplace: false, ...options }

if (oldValue === undefined) {
throw Error(`Params Error: Must specify param 'oldValue' to replace`);
}

if (newValue === undefined) {
throw Error(`Params Error: Must specify param 'newValue' to replace with`);
}

if (typeof oldValue === 'number' && isNaN(oldValue)) {
throw Error(`Params Error: Param 'oldValue' does not support NaN. Use DataFrame.fillNa() instead.`);
throw Error(`Params Error: Param 'oldValue' does not support NaN. Use Series.fillNa() instead.`);
}

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

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

let newData: ArrayType2D = []
Expand Down
16 changes: 12 additions & 4 deletions src/danfojs-base/core/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1536,16 +1536,24 @@ export default class Series extends NDframe implements SeriesInterface {
): Series | void {
const { inplace } = { inplace: false, ...options }

if (oldValue === undefined) {
throw Error(`Params Error: Must specify param 'oldValue' to replace`);
}

if (newValue === undefined) {
throw Error(`Params Error: Must specify param 'newValue' to replace with`);
}

if (typeof oldValue === 'number' && isNaN(oldValue)) {
throw Error(`Params Error: Param 'oldValue' does not support NaN. Use Series.fillNa() instead.`);
}

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

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

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