Giter Site home page Giter Site logo

Comments (8)

amytych avatar amytych commented on May 30, 2024

Thanks for pointing that out @techieshark!

I think we might be better of with using + for parsing numbers, since indeed it behaves better than parseFloat. I don't think we should go as far as trying to handle formatted numbers, we could mention that in the docs.

What do you think @nickslevine?

from zebras.

nickslevine avatar nickslevine commented on May 30, 2024

Thanks for pointing out, @techieshark!

@amytych Seems as if the + operator doesn't fix the problem with the commas in number-strings, unless I'm missing something?

Couldn't hurt to put a warning in the docs to start and then file an enhancement issue for smarter parsing? What do you both think?

from zebras.

amytych avatar amytych commented on May 30, 2024

Seems as if the + operator doesn't fix the problem with the commas in number

Hehe, yes, I'm aware, I just meant it's better in a way that it returns NaN when it can't parse a string as a number, which seems more appropriate than a totally incorrect number like parseFloat does, e.g:

image

As for the smarter parsing I'm worried it might be a mine field and out of scope of this library. Dealing with localized formats might be too much of a hustle, as also pointed out in the SO thread linked in the issue it's not trivial to do in a reliable manner. (tldr: commas might mean very different things in formatted strings)

from zebras.

amytych avatar amytych commented on May 30, 2024

One more note, seems that using + would make it behave similar to pandas.to_numeric() with errors="coerce" setting?

https://repl.it/repls/VainWiltedSeptagon
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_numeric.html

from zebras.

nickslevine avatar nickslevine commented on May 30, 2024

@amytych cool cool, that all makes a lot of sense!

from zebras.

nickslevine avatar nickslevine commented on May 30, 2024

Just switched parseFloat() with + and added a note re:commas in the README. @techieshark thanks for flagging!

@amytych - I wasn't quite sure how to update the docs website - mind reminding me how the build process works? Thanks!

from zebras.

amytych avatar amytych commented on May 30, 2024

Great you actioned this @nickslevine, thanks!

I'd still consider a PR route even for such a seemingly small case, some things worth thinking about a bit more here:

  • improving tests to cover as many edge cases as possible
  • should we consider handling empty strings? +"" === 0 ☚ī¸
  • when releasing we should perhaps bump the major version since it might not be backwards compatible?
  • worth explaining the behavior a bit more within the parseNums docs as well (or at least repeat what you've put in the main README)?

I'll look into publishing new docs 👍

from zebras.

nickslevine avatar nickslevine commented on May 30, 2024

That all makes sense - sound good!

from zebras.

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.