alex-hhh / data-frame

A data frame implementation for Racket
https://alex-hhh.github.io/2018/08/racket-data-frame-package.html
Other
37 stars 10 forks source link

data-frame/read-csv numbers in scientific notation as string #12

Closed md-arif-shaikh closed 3 years ago

md-arif-shaikh commented 3 years ago

Hi @alex-hhh, my CSV file contains numbers both in the normal format as well as scientific notation. I noticed that the numbers in scientific notations, for example, 7.423934362508338e-05 is imported as string, i. e, "7.423934362508338e-05". This causes problems, for example when I try to plot the data using

#lang racket
(require plot)
(require data-frame)
(define eob (df-read/csv "./eob.csv" #:quoted-numbers? #t))
(plot (list (axes)
            (points (df-select* eob "time" "amp"))))

gives the following error

points: contract violation
  expected: real?
  given: "9.744929335518598e-05"
  in: an element of
      a part of the or/c of
      an element of
      a part of the or/c of
      the 1st argument of
      (->*
       ((or/c
         natural?
         (sequence/c
          (or/c natural? (sequence/c real?)))))
       (#:alpha
        (>=/c 0)
        #:color
        (or/c
         string?
         symbol?
         (and/c
          exact-integer?
          negative?
          (not/c fixnum?))
         (and/c
          exact-integer?
          positive?
          (not/c fixnum?))
         (and/c fixnum? negative?)
         (and/c fixnum? positive? (not/c index?))
         (and/c index? positive? (not/c byte?))
         g444
         1
         0
         (recursive-contract g470 #:impersonator)
         (list/c real? real? real?))
        #:fill-color
        (or/c
         string?
         symbol?
         (and/c
          exact-integer?
          negative?
          (not/c fixnum?))
         (and/c
          exact-integer?
          positive?
          (not/c fixnum?))
         (and/c fixnum? negative?)
         (and/c fixnum? positive? (not/c index?))
         (and/c index? positive? (not/c byte?))
         g444
         1
         0
         (recursive-contract g470 #:impersonator)
         (list/c real? real? real?))
        #:label
        (or/c string? #f pict?)
        #:line-width
        (>=/c 0)
        #:size
        (>=/c 0)
        #:sym
        (or/c
         string?
         char?
         (and/c
          exact-integer?
          negative?
          (not/c fixnum?))
         (and/c
          exact-integer?
          positive?
          (not/c fixnum?))
         (and/c fixnum? negative?)
         (and/c fixnum? positive? (not/c index?))
         (and/c index? positive? (not/c byte?))
         g444
         1
         0
         'dot
         'point
         'pixel
         'plus
         'times
         'asterisk
         '5asterisk
         'odot
         'oplus
         'otimes
         'oasterisk
         'o5asterisk
         'circle
         'square
         'diamond
         'triangle
         'fullcircle
         'fullsquare
         'fulldiamond
         'fulltriangle
         'triangleup
         'triangledown
         'triangleleft
         'triangleright
         'fulltriangleup
         'fulltriangledown
         'fulltriangleleft
         'fulltriangleright
         'rightarrow
         'leftarrow
         'uparrow
         'downarrow
         '4star
         '5star
         '6star
         '7star
         '8star
         'full4star
         'full5star
         'full6star
         'full7star
         'full8star
         'circle1
         'circle2
         'circle3
         'circle4
         'circle5
         'circle6
         'circle7
         'circle8
         'bullet
         'fullcircle1
         'fullcircle2
         'fullcircle3
         'fullcircle4
         'fullcircle5
         'fullcircle6
         'fullcircle7
         'fullcircle8
         'none)
        #:x-jitter
        (>=/c 0)
        #:x-max
        (or/c real? #f)
        #:x-min
        (or/c real? #f)
        #:y-jitter
        (>=/c 0)
        #:y-max
        (or/c real? #f)
        #:y-min
        (or/c real? #f))
       any)
  contract from: 
      <pkgs>/plot-lib/plot/private/plot2d/point.rkt
  blaming: /Users/arif/Documents/test-data-frame.rkt
   (assuming the contract is correct)
  at: <pkgs>/plot-lib/plot/private/plot2d/point.rkt:47:9
alex-hhh commented 3 years ago

Thanks for reporting it. I pushed a fix to the package. You will need to update your package using "raco pkg update" to get the new version.

md-arif-shaikh commented 3 years ago

Does not seem to fix the issue. I am getting exactly the same issue as mentioned before.

alex-hhh commented 3 years ago

It looks like I only handled the case where the numbers were quoted. I pushed a fix for the case when the numbers are not quoted. Can you please update your package and try again? If it still does not work, can you please provide a small CSV file which illustrates the problem? Thanks, Alex.

md-arif-shaikh commented 3 years ago

It works now. Thanks a lot.