Skip to content

loc with one row cause error #597

Open

Description

@Requiemu
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.

Activity

  1. junduck commented on Nov 12, 2025

    @junduck

    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.

  2. added a commit that references this issue on Nov 12, 2025
    7c3f273
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions