PowerFlowData.jl
PowerFlowData.jl copied to clipboard
implement iteration over components
Would it be possible to implement iteration over the data tables?
for i in net.buses
@show i
end
Yes, iterating over the tables should definitely be something we support!
I think we have two options here:
- Take the DataFrames.jl route and say that tables are fundamentally 2-dimensional, so
for i in tableis ambiguous and you need to specify explicitly that you want to iterate over the rows- this is possible with
Tables.rowsorTables.namedtupleiterator, like:
for i in Tables.row(net.buses) ... end- potentially we could add define
eachrow(x::Records) = Tables.rows(x)if we thinkeachrowis a preferable spelling for this. Although i don't think it's such a bad thing for users to think about whether it isrows,namedtupleiteratororrowtablethat they actually want.
- this is possible with
- Take the CSV.jl route and say that row-wise iteration is what people want when iterating a table, so
for i in tableshould iterate rows- this i'd need to think about how best to implement
- CSV.jl does this via defining
CSV.Fileas<: AbstractVector{CSV.Row}(even thoughCSV.Fileis fundamentally implemented as a collection of columns, just likePowerFlowData.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 https://github.com/nickrobinson251/PowerFlowData.jl/issues/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
@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.
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?