danfojs
danfojs copied to clipboard
If dataframe has column called 'index,' df.index refers to the column, causing hard-to-decipher errors.
Describe the bug
When creating a DataFrame
by providing an Object
, if one of the columns is called 'index,' then 'df.indexwill point to that column instead of the actual
DataFrame` index. This caused very hard-to-decipher errors when I was working with a table I did not know contained such a column.
To Reproduce
let obj = {
foo: [1,2,3,4,5],
bar: [5,6,7,8,9],
index: ['a','b','c','d','e']
}
df = new DataFrame(obj).setIndex('foo')
df.index.includes(1) //Throws error
Expected behavior
df.index
should give the index of df
. Failing that, a warning that I've created a DataFrame
with a column named index.
I have this same issue when I have a json file with some data which has a column named "index", This is for when I have only one record in the json
subIdx = this.index.slice(0, maxRow);
^
TypeError: this.index.slice is not a function
and this is for when I have multiple records
Error: IndexError: Row index must contain unique values
and when I get rid of the column named "index", it works.
Sample data
[
{
"_id": "6419c10b7027bac2b373350c",
"index": 1,
"guid": "aa9af45c-3435-473d-bbf1-e7d5ef276684",
"isActive": false,
"balance": "$2,489.81",
"picture": "http://placehold.it/32x32",
"age": 32,
"eyeColor": "green",
"name": "Mara Herrera",
"gender": "female",
"company": "PHARMEX",
"email": "[email protected]",
"phone": "+1 (841) 575-2666",
"address": "195 Front Street, Emerald, Colorado, 2400",
"about": "Reprehenderit non qui officia cupidatat minim ad aliquip est eiusmod sit fugiat dolore consequat voluptate. Exercitation in et non fugiat aliquip. Ullamco laboris proident duis commodo pariatur enim tempor velit. Eiusmod culpa adipisicing ad dolor cupidatat voluptate officia cillum occaecat anim mollit velit.\r\n",
"registered": "2021-08-08T02:45:49 -00:00",
"latitude": 47.497364,
"longitude": -36.733145,
"tags": [
"deserunt",
"incididunt",
"quis",
"consequat",
"dolor",
"tempor",
"nisi"
],
"friends": [
{
"id": 0,
"name": "Yang Landry"
},
{
"id": 1,
"name": "Peterson Salazar"
},
{
"id": 2,
"name": "Consuelo White"
}
],
"greeting": "Hello, Mara Herrera! You have 3 unread messages.",
"favoriteFruit": "strawberry"
}
]
Yes, I can confirm that creating a DataFrame with a column named 'index', or adding a column named 'index', breaks the DataFrame (prints nothing, does not seem to have any rows)