Skip to content

Data columns overwrite DataFrame's functions #671

Open
@rkuang9

Description

@rkuang9

Describe the bug
Loaded data columns are able to overwrite DataFrame's functions. When data where a column labeledsum is loaded, .sum() throws TypeError: df.sum is not a function.

Function causing this: https://github.com/javascriptdata/danfojs/blame/6b4431fcc40cce8c02beea9d187f5cad70c0e92e/src/danfojs-base/core/frame.ts#L61

It is called in several places, including DataFrame's constructor: https://github.com/javascriptdata/danfojs/blame/6b4431fcc40cce8c02beea9d187f5cad70c0e92e/src/danfojs-base/core/frame.ts#L53

To Reproduce
Using the code from the sum() documentation: https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.sum, but relabeling column A to sum

let data = {
    "sum": [-20.1, 30, 47.3, -20], // <---- changed from "A" to "sum"
    "B": [34, -4, 5, 6], // <--- try changing "B" to "print" to overwrite print()
    "C": [20, -20, 30, -40]
}

let df = new DataFrame(data)

df.print()

let df_sum = df.sum()
df_sum.print()

Throws the error TypeError: df.sum is not a function

Expected behavior
Expected to see the output from the documentation

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ -20.1             │ 34                │ 20                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 30                │ -4                │ -20               ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 47.3              │ 5                 │ 30                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ -20               │ 6                 │ -40               ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔═══╤══════╗
║ 0 │ 33.9 ║
╟───┼──────╢
║ 1 │ 6    ║
╟───┼──────╢
║ 2 │ 82.3 ║
╟───┼──────╢
║ 3 │ -54  ║
╚═══╧══════╝

Desktop :

  • Language: TypeScript
  • OS: any
  • Browser: any
  • Version: 1.1.2 (code still there in 1.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions