Skip to content

Dataframe "nunique" is broken. Quick fix suggested. #338

Closed
@KingWebsites

Description

@KingWebsites

I believe the nunique function for a dataFrame is broken.

Steps to reproduce the behavior:
If I add an extra item to each column of the test data then the nunique function creates an error.

Here's the new code adapted from the API Reference (browser) with an extra item added to each column:

		let data = {
			"A": [-20, 30, 47.3, -20, 50],
			"B": [34, -4, 5, 6, 8],
			"C": [20, 20, 30, 30, 30],
			"D": ["a", "b", "c", "c", "d"]
		}

		let df = new dfd.DataFrame(data);
		df.nunique().print();

Expected result:
I expect to see a new single-column dataframe with rows containing the total number of unique items for that row.

But I get an error of: "IndexError: You provided an index of length 5 but Ndframe rows has lenght of 4"

I believe somewhere the count of rows and columns is getting swapped by mistake. If the dataset is turned back into a 4x4 grid it works. It just doesn't like this new 4x5 one. The test data is 4x4 so the error is never seen during test.

Suggested fix:
Apologies for not having the skills to fix this myself but I think the fix is to change this conditional from 0 to 1 in both these files:
danfojs/danfojs-browser/src/core/frame.js ln. 2019
danfojs/danfojs-node/src/core/frame.js ln. 2021

Change
if (axis === 0) {
to
if (axis === 1) {

My rough fix by downloading the bundle.js and editing that conditional has fixed the issue for me.

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