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

Handle missing value #16

Open
dongli opened this issue Sep 13, 2021 · 4 comments
Open

Handle missing value #16

dongli opened this issue Sep 13, 2021 · 4 comments

Comments

@dongli
Copy link

dongli commented Sep 13, 2021

Here is the test CSV file:

foo,bar
1.0,2.0
,4.0
5.0,
7.0,

And with following codes:

program test

  use csv_module

  implicit none

  type(csv_file) f
  logical status_ok
  character(10), allocatable :: columns(:)
  integer i
  real(8), allocatable :: x(:)

  call f%read('test.csv', header_row=1, status_ok=status_ok)
  print *, 'status_ok =', status_ok

  call f%get_header(columns, status_ok)
  print *, 'status_ok =', status_ok
  print *, columns

  call f%get(1, x, status_ok)
  print *, 'status_ok =', status_ok
  do i = 1, size(x)
    print *, x(i)
  end do

end program test

The output is:

 status_ok = T
 status_ok = F
 foo       bar
 status_ok = T
   1.00000000000000
  0.000000000000000E+000  ! <-- Assume this should be missing value
   5.00000000000000
   7.00000000000000

As you can see, the second value is expected to be missing value, but I got 0.000000000000000E+000, which may cause difficulty to judge whether the value is valid or not. Can we specify the missing value when get as:

call f%get(1, x, missing_value=99999.0, status_ok=status_ok)
@jvdp1
Copy link

jvdp1 commented Oct 28, 2021

I am just running in this issue: I have CSV files with temperature measurements, and some missing values (empty cells in the CSV files).
Missing values are replaced by "0", and these cannot be detected after reading the file (because a temperature could be equal to 0).

I forked this project, and modified the in this branch such that missing values (defined as '1,,3' or '1, ,3') are replaced by a string provided by the user, e.g.,:

call f%read('file.csv', missing = '-9999', status_ok= status_ok)

It does the job for my case. But I may overlook things.

@epagone
Copy link

epagone commented Nov 19, 2023

I think that this is an important enhancement. Is there a reason why @jvdp1's fork changes cannot be imported?

@jvdp1
Copy link

jvdp1 commented Nov 19, 2023

Hi. I don't know. Probably because I never open a PR? If @jacobwilliams agrees, I can open a PR from my fork.

@jacobwilliams
Copy link
Owner

Sure! Send a pull request and I'll look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants