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

WIP:Support different kinds of io for xframe #239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

daliuzhen1
Copy link

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
Copy link
Author

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

@JohanMabille
Copy link
Member

JohanMabille commented Nov 21, 2019

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

@daliuzhen1
Copy link
Author

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?

@JohanMabille
Copy link
Member

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

@daliuzhen1
Copy link
Author

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.

@wolfv
Copy link
Member

wolfv commented Nov 21, 2019

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.

@daliuzhen1
Copy link
Author

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

@daliuzhen1 daliuzhen1 changed the title Support different kinds of io for xframe WIP:Support different kinds of io for xframe Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants