xframe icon indicating copy to clipboard operation
xframe copied to clipboard

WIP:Support different kinds of io for xframe

Open daliuzhen1 opened this issue 5 years ago • 7 comments

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

daliuzhen1 avatar Nov 20 '19 09:11 daliuzhen1

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

daliuzhen1 avatar Nov 21 '19 10:11 daliuzhen1

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).

JohanMabille avatar Nov 21 '19 10:11 JohanMabille

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?

daliuzhen1 avatar Nov 21 '19 10:11 daliuzhen1

xtl::variant and xtl::any are not meant to be used together (also notice the xtl::any, std::any is C++17):

  • xtl::variant should 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 for xt::xvariable<xtl::variant<int, double, std::string>>.
  • xtl::any can 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 for xt::xvariable<xtl::any>>.

JohanMabille avatar Nov 21 '19 11:11 JohanMabille

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.

daliuzhen1 avatar Nov 21 '19 11:11 daliuzhen1

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.

wolfv avatar Nov 21 '19 12:11 wolfv

Hi @wolfv Sorry for late reply. Yes. you are right. I can use the type function. Thanks for your suggestion

daliuzhen1 avatar Nov 22 '19 01:11 daliuzhen1