You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let data = { "Name": ["Apples", "Mango", "Banana", "Pear"],
"Count": [21, 5, 30, 10],
"Price": [200, 300, 40, 250] }
let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]})
df.print()
let sub_df = df.loc({rows: ["a"]})
sub_df.print()
In browser, this will cause error:
Uncaught Error: IndexError: Specified index (a) not found
at t._loc (startup:4:47)
at t.loc (startup:4:47)
at pen.js?key=pen.js-8a2f7821-cb23-e0d2-07e7-2b53e94c09e0:7:17
This will only happen when the rows have exactly one element, if it's let sub_df = df.loc({rows: ["a", "b"]}), then it is normal.
In function _loc, when rows.length == 1 && typeof rows[0] == "string", the implementation check if ":" not exist then assumes rows is a number, then casts it to Number(), so in your case {rows: ["a"]} results in NaN row index thus the exception.
Activity
junduck commentedon Nov 12, 2025
I can confirm this bug.
In function _loc, when rows.length == 1 && typeof rows[0] == "string", the implementation check if
":"not exist then assumes rows is a number, then casts it to Number(), so in your case {rows: ["a"]} results in NaN row index thus the exception.This is business logic flaw I'll send a fix.
Fixed loc with one row cause error