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

readdlm() cannot process empty file #9

Open
innerlee opened this issue May 7, 2016 · 7 comments
Open

readdlm() cannot process empty file #9

innerlee opened this issue May 7, 2016 · 7 comments
Labels
help wanted Extra attention is needed stdlib

Comments

@innerlee
Copy link

innerlee commented May 7, 2016

  • julia ver: 0.4.5
  • os ver: win 10

reproduce:

julia> writedlm("emp.ty", [])
julia> readdlm("emp.ty")
ERROR: at row 0, column 0 : ArgumentError("number of rows in dims must be > 0, got 0")
 in error at error.jl:21

Is this behavior by design?

@ararslan
Copy link
Member

ararslan commented May 7, 2016

It appears to be by design given that there's an explicit error for it. What behavior would you have expected? A 0x0 array?

@ViralBShah
Copy link
Contributor

Cc @tanmaykm

@nalimilan
Copy link
Member

The problem is that readdlm can't know the number of columns of the result. So if in general your code works with two-columns arrays, a 0x0 array will likely raise an error later anyways. By throwing the error immediately, readdlm allows you to create a matrix of the correct size.

We could provide a way to specify the number of columns, and not raise an error if it's set. Currently AFAIK dims cannot be used for that.

@innerlee
Copy link
Author

I think 0x0 array is okay, because

  • I do not agree that a 0x0 array is useless, or equals an error.
  • Columns can vary, like rows. I mean, one might read, append columns to the data, and rewrite the file.
  • When accessing data, one checks the bounds, like in for i=1:length(sth). So, 0x0 will be safe in this case.
  • Its easier to check size than catch exceptions.

@alexmorley
Copy link

0x0 array was definitely was definitely the behaviour that I expected, else what it returns in this case could be specified with a keyword (like :throwifempty or something?)

@kshyatt kshyatt added the I/O label Jul 27, 2016
@StefanKarpinski StefanKarpinski added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Oct 27, 2016
@JeffBezanson JeffBezanson added bug Something isn't working stdlib and removed I/O labels May 21, 2018
@bjarthur
Copy link

a 0x0 array is also what i expected

@vtjnash vtjnash removed the bug Something isn't working label Feb 13, 2022
@vtjnash
Copy link
Contributor

vtjnash commented Feb 13, 2022

It seems like empty files might indicate errors, but no less so than arbitrarily truncated files (which we cannot detect). Do you want to make a PR to return a 0x0 Any array?

@ViralBShah ViralBShah transferred this issue from JuliaLang/julia Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed stdlib
Projects
None yet
Development

No branches or pull requests

10 participants