Open tomas-kucera opened 2 years ago
I surmise this:
p := make([]ohlcv, 1)
needs to read instead:
var p ohlcv
and thus:
fmt.Printf("data[%d]: O:%.2f H:%.2f L:%.2f C:%.2f V:%.2f \n", i, p.PriceOpen, p.PriceHigh, p.PriceLow, p.PriceClose, p.Volume)
Thanks for a quick response.
Took that code from the example but also tried what you are suggesting. Unfortunately that leads to this error:
panic: unsupported kind (struct), need slice or array
which makes sense, as the function definition is:
func (*hdf5.Table).Next(data interface{}) error
(hdf5.Table).Next on pkg.go.dev
Next reads packets from a packet table starting at the current index into the value pointed at by data. i.e. data is a pointer to an array or a slice.
Can it be that you are using some newer version?
EDIT: Just checked the implementations of the Next function in h5pt_table.go and they are identical. EDIT 2: BTW, I also tried ReadPackets instead of Next with the same results.
Did some more research!
If I replace the printing line with
fmt.Printf("data[%d]: %v\n", i, p)
Then there are two possible results dependant on the defintion of the struct:
full definition that includes the strings fails with this error comming from the fmt.Printf():
panic: runtime error: growslice: cap out of range
if the string are commented out, then the result is this:
data[1437]: [{1625183880000000000 7090182514096892258 1.814982667395619e-306 -3.79181233146521e-284 -4.643804396672689e-134 -9.500616071346912e+15 3.5854690526542615e+184}]
data[1438]: [{1625183940000000000 7090182514096892258 1.814982667395619e-306 5.9896317349078915e+183 3.434212986107372e+237 3.58550892285317e+184 -9.919075148868785e-38}]
data[1439]: [{1625184000000000000 7090182514096892258 1.814982667395619e-306 -3.3900115496356115e+111 -2.0293221659741413e+112 -3.177424435398634e-182 1.1485478191699172e+40}]
where the first column (Index) is perfectly correct but the rest is just messed up.
This leads me to think that the reading ignores the `hdf5:"column_name"`
and reads the values in sequence and thus causing to mess up the data completely.
This hypothesis is somewhat being broken by the fact that even if I leave the struct defintion full (including the strings) then the Next passes and if I do not attempt to print the string values (Exchange / Pair), then the values are displayed but wrong. Which is the original output.
I am being totally lost.
But have a simple question: How does handling string in structs for reading from HDF5 work?
I have noticed that in the master/cmd/test-go-table-01-readback/main.go file there is definition of struct:
type particle struct {
// name string `hdf5:"Name"` // FIXME(sbinet)
Lati int32 `hdf5:"Latitude"`
Longi int64 `hdf5:"Longitude"`
Pressure float32 `hdf5:"Pressure"`
Temperature float64 `hdf5:"Temperature"`
// isthep []int // FIXME(sbinet)
// jmohep [2][2]int64 // FIXME(sbinet)
}
That somehow indicates that strings can be an issue.
What are you trying to do?
I am trying to read HDF5 database (version 1.12.1).
The datatabase was populated using Python's h5py library. The data is pandas dataframe but guess that should be no problem as h5ls and HDFView app read the data without any issues.
What did you do?
I used the example from this repo for reading table. Also tried to use DataSet instead. This is the code excerpt:
What did you expect to happen?
I expected something like this:
What actually happened?
What I get is:
Also when trying to access Exchange or Pair attributes, I get the following error:
What version of Go, Gonum, Gonum/netlib and libhdf5 are you using?
Does this issue reproduce with the current master?
Yes, it does!