Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
KingWebsites opened this issue Jan 7, 2022 · 2 comments
Closed

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

KingWebsites opened this issue Jan 7, 2022 · 2 comments

Comments

@KingWebsites
Copy link

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.

@risenW
Copy link
Member

risenW commented Jan 9, 2022

Thanks for raising this issue, I’ll take a look ASAP.

@risenW
Copy link
Member

risenW commented Jan 12, 2022

@KingWebsites @michael-pont Can you install and use the latest Typescript version (v1.0.0). This has been fixed.

If you need help migrating to the latest version, see: https://danfo.jsdata.org/examples/migrating-to-the-stable-version-of-danfo.js

@risenW risenW closed this as completed Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants