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

implement iteration over components #75

Open
jd-lara opened this issue Jun 15, 2022 · 3 comments
Open

implement iteration over components #75

jd-lara opened this issue Jun 15, 2022 · 3 comments
Labels
idea needs some investigation before we decide

Comments

@jd-lara
Copy link
Contributor

jd-lara commented Jun 15, 2022

Would it be possible to implement iteration over the data tables?

for i in net.buses
       @show i 
       end
@nickrobinson251
Copy link
Owner

nickrobinson251 commented Jun 15, 2022

Yes, iterating over the tables should definitely be something we support!

I think we have two options here:

  1. Take the DataFrames.jl route and say that tables are fundamentally 2-dimensional, so for i in table is ambiguous and you need to specify explicitly that you want to iterate over the rows
    • this is possible with Tables.rows or Tables.namedtupleiterator, like:
    for i in Tables.row(net.buses)
      ...
    end
    • potentially we could add define eachrow(x::Records) = Tables.rows(x) if we think eachrow is a preferable spelling for this. Although i don't think it's such a bad thing for users to think about whether it is rows, namedtupleiterator or rowtable that they actually want.
  2. Take the CSV.jl route and say that row-wise iteration is what people want when iterating a table, so for i in table should iterate rows
    • this i'd need to think about how best to implement
    • CSV.jl does this via defining CSV.File as <: AbstractVector{CSV.Row} (even though CSV.File is fundamentally implemented as a collection of columns, just like PowerFlowData.Records).

Do you think using Tables.jl is sufficient? e.g.

for i in Tables.rows(net.buses)
       @show i 
end

If so, that already works (well, except i need to fix #76)

Or do you think we should take option 2 and figure out how to make for i in net.buses do the same thing as for i in Tables.rows(net.buses)?


xref #4

@jd-lara
Copy link
Contributor Author

jd-lara commented Jun 16, 2022

@nickrobinson251 there is no need really to do for i in Tables.row(net.buses) since the field net.buses is already a vector we can iterate over.

The best option would be to iterate over the whole row so that the fields can be accessed like a DataFrame.

@nickrobinson251
Copy link
Owner

I don't think i understand, sorry 😊 could you show me what you'd like to be able to write and what the behaviour would be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea needs some investigation before we decide
Projects
None yet
Development

No branches or pull requests

2 participants