Skip to content

Commit

Permalink
Implemented to read/write std:pairs columns from/to files
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmoein committed Aug 27, 2024
1 parent 91fa3b3 commit 0db4655
Show file tree
Hide file tree
Showing 10 changed files with 840 additions and 102 deletions.
3 changes: 3 additions & 0 deletions data/sample_data_2.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ str_col_2:28:<string>:XXXX10,XXXX11,XXXX01,XXXX02,XXXX03,XXXX6,XXXX7,Running fas
dbl_col_3:28:<double>:2.009,3.111,10,4.2222,5.3333,12,6.25,10,0.9999,1.2345,4.2345,3,8,3.3333,2.2345,4.25,3.2345,0.009,1.111,5.25,11,5.2345,2.2222,1.009,2.111,9,3.2222,4.3333,
dbl_col_2_2:28:<double>:0.87865,-0.6999,0.4111,0.1902,-0.4888,0.2,0.1056,0.1,0.06743,0.998,0.15678,0.923,0.0111,-0.8888,0.3456,0.0056,0.056,0.07865,-0.9999,0.0456,0.14,0.00345,0.1002,0.078654,-0.8999,0.01119,0.8002,-0.9888,
bool_col_2:28:<bool>:0,1,1,1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,
str_str_pair_col:5:<str_str_pair>:<First String 11:Second String 11>,<:>,<:Second String 13>,<First String 14:>,<First String 15:Second String 15>,
dbl_dbl_pair_col:5:<dbl_dbl_pair>:<1234:456.7>,<:>,<:456.8>,<456.9:>,<789.1:789.2>,
str_dbl_pair_col:5:<str_dbl_pair>:<First String 11:456.7>,<:>,<:456.8>,<First String 14:>,<First String 15:789.2>,
24 changes: 12 additions & 12 deletions docs/HTML/DataFrame.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are used to load data into the DataFrame" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Loading Data</td>
<td title="These are used to load data into the DataFrame" style="text-align:center;background-color:LightGrey;color:DarkBlue">Loading Data &nbsp;&nbsp; <font size="+2">&#128666;</font></td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -225,7 +225,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are used to get data from DataFrame" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Getting Data</td>
<td title="These are used to get data from DataFrame" style="text-align:center;background-color:LightGrey;color:DarkBlue">Getting Data &nbsp;&nbsp; <font size="+2">&#x1F6D2;</font></td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand All @@ -249,7 +249,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are used to get information from data" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Getting Information</td>
<td title="These are used to get information from data" style="text-align:center;background-color:LightGrey;color:DarkBlue">Getting Information &nbsp;&nbsp; <font size="+2">&#x2139;</font></td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -337,7 +337,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are used to slice the data in the DataFrame" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Slicing Data</td>
<td title="These are used to slice the data in the DataFrame" style="text-align:center;background-color:LightGrey;color:DarkBlue">Slicing Data &nbsp;&nbsp; <font size="+2">&#128298;</font></td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -381,7 +381,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are used to group/combine data in the DataFrame" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Mixing Data</td>
<td title="These are used to group/combine data in the DataFrame" style="text-align:center;background-color:LightGrey;color:DarkBlue">Mixing Data &nbsp;&nbsp; <font size="+2">&#x1F469;</font></td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -409,7 +409,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are used to modify data in the DataFrame" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Modifying Data</td>
<td title="These are used to modify data in the DataFrame" style="text-align:center;background-color:LightGrey;color:DarkBlue">Modifying Data &nbsp;&nbsp; <font size="+2">&#x1F9F0;</font></td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -501,7 +501,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are used to input/output data to/from DataFrame" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Input/Output</td>
<td title="These are used to input/output data to/from DataFrame" style="text-align:center;background-color:LightGrey;color:DarkBlue">Input/Output &nbsp;&nbsp; <font size="+2">&#128268;</font></td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -529,7 +529,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are other functionalities of DataFrame" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Miscellaneous</td>
<td title="These are other functionalities of DataFrame" style="text-align:center;background-color:LightGrey;color:DarkBlue">Miscellaneous &nbsp;&nbsp; <font size="+2">&#x2747;</font></td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -810,7 +810,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These visitors change the input column in-place " style="text-align:center;background-color:DarkGrey;color:DarkBlue">Transformers &amp;<BR>Filters</td>
<td title="These visitors change the input column in-place " style="text-align:center;background-color:LightGrey;color:DarkBlue">Transformers &amp;<BR>Filters</td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -1380,7 +1380,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are arithmetic operators between DataFrames" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Arithmetic<BR>Operators</td>
<td title="These are arithmetic operators between DataFrames" style="text-align:center;background-color:LightGrey;color:DarkBlue">Arithmetic<BR>Operators</td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -1416,7 +1416,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These are exceptions thrown by this library" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Exceptions</td>
<td title="These are exceptions thrown by this library" style="text-align:center;background-color:LightGrey;color:DarkBlue">Exceptions</td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down Expand Up @@ -1541,7 +1541,7 @@ <H2 ID="2"><font color="blue">API Reference with code samples <font size="+4">&#
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td title="These populate the thread-pool" style="text-align:center;background-color:DarkGrey;color:DarkBlue">Multithreading<BR>Static Functions</td>
<td title="These populate the thread-pool" style="text-align:center;background-color:LightGrey;color:DarkBlue">Multithreading<BR>Static Functions</td>
</tr>

<tr class="item" onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
Expand Down
22 changes: 15 additions & 7 deletions docs/HTML/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,37 @@
</PRE>
In case of io_format::csv2, io_format::csv, and io_format::binary the following additional types are also supported:
<PRE>
dbl_vec -- A vector of double precision values,
str_dbl_pair -- std::pair&lt;std::string, double&gt;.
The pair is printed as "&lt;s:d&gt;,&lt;s:d&gt;, ...
Where s's are strings and d's are doubles.
str_str_pair -- std::pair&lt;std::string, std::string&gt;.
The pair is printed as "&lt;s1:s2&gt;,&lt;s1:s2&gt;, ...
Where s's are strings.
dbl_dbl_pair -- std::pair&lt;double, double&gt;.
The pair is printed as "&lt;d1:d2&gt;,&lt;d1:d2&gt;, ...
Where d's are doubles.
dbl_vec -- std::vector&lt;double&gt;.
The vector is printed as "s[d1|d2|...]"
where s is the size of the vector and
d's are the double values.
str_vec -- A vector of std::string values,
str_vec -- std::vector&lt;std::string&gt;.
The vector is printed as "s[str1|str2|...]"
where s is the size of the vector
and str's are the strings.
dbl_set -- A set of double precision values,
dbl_set -- std::set&lt;double&gt;.
The set is printed as "s[d1|d2|...]"
where s is the size of the set
and d's are the double values.
str_set -- A set of std::string values,
str_set -- std::set&lt;std::string&gt;.
The set is printed as "s[str1|str2|...]"
where s is the size of the set
and str's are the strings.
str_dbl_map -- A map of string keys to double
str_dbl_map -- std::map&lt;std::string, double&gt;.
precision values, The map is printed
as "s{k1:v1|k2:v2|...}"
where s is the size of the map
and k's and v's are keys and values.
str_dbl_unomap -- An unordered map of string keys
to double precision values,
str_dbl_unomap -- std::unoredered_map&lt;std::string, double&gt;.
The map is printed as "s{k1:v1|k2:v2|...}"
where s is the size of the map and k's
and v's are keys and values.
Expand Down
51 changes: 33 additions & 18 deletions docs/HTML/write.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,39 @@
</PRE>
In case of io_format::csv2, io_format::csv, and io_format::binary the following additional types are also supported:
<PRE>
dbl_vec -- A vector of double precision values, The vector is printed
as "s[d1|d2|...]" where s is the size of the vector and d's
are the double values.
str_vec -- A vector of std::string values, The vector is printed as
"s[str1|str2|...]" where s is the size of the vector and
str's are the strings.
dbl_set -- A set of double precision values, The set is printed as
"s[d1|d2|...]" where s is the size of the set and d's
are the double values.
str_set -- A set of std::string values, The set is printed as
"s[str1|str2|...]" where s is the size of the set and
str's are the strings.
str_dbl_map -- A map of string keys to double precision values, The map is
printed as "s{k1:v1|k2:v2|...}" where s is the size of
the map and k's and v's are keys and values.
str_dbl_unomap -- An unordered map of string keys to double precision values,
The map is printed as "s{k1:v1|k2:v2|...}" where s is the
size of the map and k's and v's are keys and values.
str_dbl_pair -- std::pair&lt;std::string, double&gt;.
The pair is printed as "&lt;s:d&gt;,&lt;s:d&gt;, ...
Where s's are strings and d's are doubles.
str_str_pair -- std::pair&lt;std::string, std::string&gt;.
The pair is printed as "&lt;s1:s2&gt;,&lt;s1:s2&gt;, ...
Where s's are strings.
dbl_dbl_pair -- std::pair&lt;double, double&gt;.
The pair is printed as "&lt;d1:d2&gt;,&lt;d1:d2&gt;, ...
Where d's are doubles.
dbl_vec -- std::vector&lt;double&gt;.
The vector is printed as "s[d1|d2|...]"
where s is the size of the vector and
d's are the double values.
str_vec -- std::vector&lt;std::string&gt;.
The vector is printed as "s[str1|str2|...]"
where s is the size of the vector
and str's are the strings.
dbl_set -- std::set&lt;double&gt;.
The set is printed as "s[d1|d2|...]"
where s is the size of the set
and d's are the double values.
str_set -- std::set&lt;std::string&gt;.
The set is printed as "s[str1|str2|...]"
where s is the size of the set
and str's are the strings.
str_dbl_map -- std::map&lt;std::string, double&gt;.
precision values, The map is printed
as "s{k1:v1|k2:v2|...}"
where s is the size of the map
and k's and v's are keys and values.
str_dbl_unomap -- std::unoredered_map&lt;std::string, double&gt;.
The map is printed as "s{k1:v1|k2:v2|...}"
where s is the size of the map and k's
</PRE>

In case of io_format::csv2 the following additional types are also supported:
Expand Down
29 changes: 21 additions & 8 deletions include/DataFrame/Internals/DataFrame_misc.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,39 @@ DataFrame<I, H>::print_binary_functor_<Ts ...>::operator() (const T &vec) {

std::strncpy(col_name, name, sizeof(col_name));
os.write(col_name, sizeof(col_name));

const long local_start_row = std::min (long(vec.size()), start_row);
const long local_end_row = std::min (long(vec.size()), end_row);

if constexpr (std::is_same_v<ValueType, std::string>)
_write_binary_string_(os, vec, start_row, end_row);
_write_binary_string_(os, vec, local_start_row, local_end_row);
else if constexpr (std::is_same_v<ValueType, DateTime>)
_write_binary_datetime_(os, vec, start_row, end_row);
_write_binary_datetime_(os, vec, local_start_row, local_end_row);
else if constexpr (std::is_same_v<ValueType, std::vector<double>>)
_write_binary_dbl_vec_(os, vec, start_row, end_row);
_write_binary_dbl_vec_(os, vec, local_start_row, local_end_row);
else if constexpr (std::is_same_v<ValueType, std::vector<std::string>> ||
std::is_same_v<ValueType, std::vector<const char *>>)
_write_binary_str_vec_(os, vec, start_row, end_row);
_write_binary_str_vec_(os, vec, local_start_row, local_end_row);
else if constexpr (std::is_same_v<ValueType, std::set<double>>)
_write_binary_dbl_set_(os, vec, start_row, end_row);
_write_binary_dbl_set_(os, vec, local_start_row, local_end_row);
else if constexpr (std::is_same_v<ValueType, std::set<std::string>> ||
std::is_same_v<ValueType, std::set<const char *>>)
_write_binary_str_set_(os, vec, start_row, end_row);
_write_binary_str_set_(os, vec, local_start_row, local_end_row);
else if constexpr (
std::is_same_v<ValueType, std::map<std::string, double>> ||
std::is_same_v<ValueType, std::unordered_map<std::string, double>>)
_write_binary_str_dbl_map_(os, vec, start_row, end_row);
_write_binary_str_dbl_map_(os, vec, local_start_row, local_end_row);
else if constexpr (
std::is_same_v<ValueType, std::pair<std::string, double>>)
_write_binary_str_dbl_pair_(os, vec, local_start_row, local_end_row);
else if constexpr (
std::is_same_v<ValueType, std::pair<std::string, std::string>>)
_write_binary_str_str_pair_(os, vec, local_start_row, local_end_row);
else if constexpr (
std::is_same_v<ValueType, std::pair<double, double>>)
_write_binary_dbl_dbl_pair_(os, vec, local_start_row, local_end_row);
else
_write_binary_data_(os, vec, start_row, end_row);
_write_binary_data_(os, vec, local_start_row, local_end_row);

return;
}
Expand Down
Loading

0 comments on commit 0db4655

Please sign in to comment.