xframe
xframe copied to clipboard
WIP:Support different kinds of io for xframe
Backgroud Pandas support parse kinds of format file. https://pandas.pydata.org/pandas-docs/stable/reference/io.html
First plan parse sas file (include sas7bdat and xport). The following link is sas7bdat format. https://cran.r-project.org/web/packages/sas7bdat/vignettes/sas7bdat.pdf
Hi @JohanMabille I have a question. How can i put different kinds of column type to a xvarible? Not only double using variable_type = xvariable<double, coordinate_type>; For example, a matrix like this, string, double, int aaa,23.5,10 bbb,23.4,20
This is not possible, a variable is supposed to hold ohmogeneous values. For storing different types, a xframe object should be used (not available yet), that would store xvariable<double>, xvariable<int>, and xvariable<string>.
An easier way to workaround this would be to store a variant in the variable (but I don't know if that would build actually) xvariable<xtl::variant<double, int, string>>, but then you have to know the type and cast when you want to access a value (or use visitors).
HI @JohanMabille OK, thanks for your reply. Now i want to parse a file and put them into xvarible. I think i need get type when parse file. The column type is dynamic. So i think i need return a xvariable<xtl::variantstd::any...> like this and the column types. But i dont know how to implement it. Do you have some suggestions?
xtl::variant and xtl::any are not meant to be used together (also notice the xtl::any, std::any is C++17):
xtl::variantshould be used when the number of different types is small and known when you write the code. If you know that your file can only contain int, double and strings then go forxt::xvariable<xtl::variant<int, double, std::string>>.xtl::anycan hold any type, there is absolutely no restriction. However this comes at a cost: you totally loose the type information, and retrieving the real type requires dynamic cast. If your file cna virtually hold any type, then go forxt::xvariable<xtl::any>>.
Hi @JohanMabille Thanks for your quick reply and your suggestions. Yes, you are right, i understand the difference between any and variant. I think i should use xtl::any and return the type to the function caller for now. I will use xframe replace it in the future. Thank you.
Actually you still have the type information since std::any actually has a type() function that you can call to get the typeid of whatever is stored inside. Just no static type info.
Hi @wolfv Sorry for late reply. Yes. you are right. I can use the type function. Thanks for your suggestion