Code Monkey home page Code Monkey logo

Comments (3)

quinnj avatar quinnj commented on June 30, 2024

To test if a CSV.Source is done, I would use

Data.isdone(s, row, col)

but otherwise, eof(s.io) should work fine too.

  1. There's an internal CSV.STATE variable of type Ref{CSV.ParsingState}. CSV.ParsingState is an enum with values
@enum ParsingState None Delimiter EOF Newline

Basically, each call to CSV.parsefield implicitly sets this CSV.STATE variable with the state of parsing when the parsing was finished:

  • None: the default state
  • Delimiter: parsing encountered a delimiter character which ended the CSV.parsefield function
  • EOF: parsing encountered the EOF
  • Newline: parsing encountered a newline which caused parsing to stop
  1. Currently there is no way to "skip" a field, though I have some notes jotted down somewhere with some considerations around doing something like this. I'll try to dig them up and post them here and maybe see how much work it would take to get it working. For now, though, what you're doing is best practice (just parse a string and continue on).

from csv.jl.

tpapp avatar tpapp commented on June 30, 2024

Thanks, this works fine. Could you consider adding API functions eof and eol, ideally with a CSV.Source as their argument? (I am assuming that eventually the state will be migrated into CSV.Source to avoid globals, but I could be mistaken as I did not study the source deeply).

from csv.jl.

quinnj avatar quinnj commented on June 30, 2024

On current master, you can now do CSV.File(file; kwargs...) which returns a lazy-materializing row-iterator. You could accomplish the original goal by doing something like:

struct CustomType
    a::Int
    b::Float64
    c::String
end

customtypes = CustomType[]

for row in CSV.File(file; kwargs...)
    if should_keep(row.a)
        push!(customtypes, CustomType(row.a, row.b, row.c)
    end
end

In this case, only the a, b, and c column values will actually be parsed from the csv file.

from csv.jl.

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.