danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

559 replace does not accept falsy strings or numbers

Open babennettdev opened this issue 2 years ago • 1 comments

Overview

Fix for Issue #559 .

  • Series.replace() accepts 0 and '' for both oldValue and newValue.
  • Series.replace() accepts NaN for newValue.
  • Series.replace() throws if oldValue is NaN (notifies user that Series.fillNa() should be used instead).
  • DataFrame.replace() accepts 0 and '' for both oldValue and newValue.
  • DataFrame.replace() accepts NaN for newValue.
  • DataFrame.replace() throws if oldValue is NaN (notifies user that DataFrame.fillNa() should be used instead).
  • Updated unit tests for Series.replace().
  • Updated unit tests for DataFrame.replace().

babennettdev avatar Feb 23 '23 17:02 babennettdev

Hi, I've been checking a bit the pull request and it seems that there is a failure in the treatment of dates, this is the code that fails and what it expects, I don't know if it is due to the changes in the pull request or other changes.

Code:

test('DataFrame Dates', () => {
  let data = [
    ['Alice', 2, new Date('2029-01-01 01:00:00')],
    ['Bob', 5, new Date('2019-01-02')],
    ['Charlie', 30, new Date('2020-01-03 01:00:20')],
    ['Dennis', 89, new Date('2022-02-04 02:16:00')]
  ]
  let columns = ["Name", "Count", "Date"];
  let df = new dfd.DataFrame(data, { columns: columns });
  expect(df["Date"].dt.hours().values).toStrictEqual([1, 0, 1, 2]);
})

Error:

Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 1

  Array [
    1,
-   0,
+   1,
    1,
    2,
  ]

Regards ✌

ghost avatar Jul 10 '23 10:07 ghost