GithubHelp home page GithubHelp logo

Comments (15)

ashleydavis avatar ashleydavis commented on May 18, 2024

Thanks for your feedback.

Are you able to submit your data so I can test this?

from data-forge-ts.

smohiuddin avatar smohiuddin commented on May 18, 2024

Attached
test-data.csv.zip

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

Thanks. Now you need to help me understand the code that produces the problem.

I've tried the following code and it seems ok:

const dataForge = require("data-forge");
require("data-forge-fs");

const df = await dataForge.readFile("./test-data.csv").parseCSV();

display(df.detectTypes());

Please let me know what changes you would make to that code to produce the problem.

I used Data-Forge Notebook to test that code.

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

This is what the result looks like in Data-Forge Notebook:

image

from data-forge-ts.

smohiuddin avatar smohiuddin commented on May 18, 2024
const dataFrame = fromCSV(csvInput, { dynamicTyping: true });
console.log(df.detectTypes().toString());

__index__  Type     Frequency           Column       
---------  -------  ------------------  -------------
0          string   8.1                 phone        
1          object   91.9                phone  

const updatedDf = dataFrame.transformSeries({ ['phone']: value => value &&  `+1 ${value}` });
console.log(df.detectTypes().toString());

__index__  Type       Frequency           Column       
---------  ---------  ------------------  -------------
0          string     8.1                 phone        
1          undefined  91.9                phone      

Seems like theres a discrepancy between how types are evaluated in fromCSV and after a transformSeries. I have also tried something like:

dataFrame.transformSeries({ ['phone']: value => value ? `+1 ${value}` : null });

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

I think your use of transformSeries is wrong.

I suspect it should look like this:

dataFrame.transformSeries({ phone: value => value ? `+1 ${value}` : null });

Also I'm not really sure why you are outputting null as value.

Typically Data-Forge treats undefined as an 'empty' value. But I don't think it does anything special with null.

I think the main problem here is that PapaParse (the CSV parser that Data-Forge uses) is returning null values for empty fields when dynamicTyping is enabled. I might be able to fix this by making Data-Forge treat nulls the same as undefined.

image

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

I need to think this through.

For now though you might use this workaround:

image

Basically rewrite null with undefined and it might work the way you expect.

In the meantime I'll see if I can fix this properly.

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

@smohiuddin Just letting you know I've just published Data-Forge version 1.7.7 and it now treats null values like it does undefined. This should solve your problem.

Please try it out and let me know if it works for you.

from data-forge-ts.

smohiuddin avatar smohiuddin commented on May 18, 2024

Thanks for this fix. After further investigation, it appears that data forge is only checking the first element of a column to determine the type instead of the distribution from detectTypes.

test-data-inverse.csv.zip

I am attaching the same data set as before except I added a string as the first element in the zip column and a number as the first element in the city state column.

data forge now detects these column types as string and number respectively.

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

Ah, well that's something you can already change!

When you construct your dataframe you should use the considerAllRows option:

const dataframe = new DataFrame({ values: [...], considerAllRows: true });

The reason it doesn't do that by default is because it can be quite expensive to compute for large data sets!

from data-forge-ts.

smohiuddin avatar smohiuddin commented on May 18, 2024

makes sense!

Whats the best way to do that if using readFile or parseCSV since those options are not available through there.

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

I was about to say you shouldn't have this problem if you are using readFile/parseCSV, but then I realise it's again related to the use of dynamicTyping.

You might be best to remove the dynamicTyping field because it doesn't seem to play nicely with your data (this is a feature of PapaParse and I don't have much control over it).

If you remove that you can manually type your data.

See the example on the landing page where it calls parseInts and parseDates to manually parse data types from columns:

image

from data-forge-ts.

smohiuddin avatar smohiuddin commented on May 18, 2024

The issue is we want to auto-detect the types as we may not know it in advance. can the data forge constructor accept the output of readFileSync?

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

This is a change that could definitely be made. Would you like to have a go at it? Be great to have you as a contributor.

I think you would need to make a change to the fromCSV function in Data-Forge and the parseCSV in Data-Forge FS.

If you are interested in doing this maybe we can discuss it more in the Data-Forge Gitter channel?

from data-forge-ts.

ashleydavis avatar ashleydavis commented on May 18, 2024

Closing due to no activity. Please reopen if this issue still needs attention.

from data-forge-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.