Skip to content

Commit

Permalink
Added docs for read/write of char from/to files
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmoein committed Jan 22, 2024
1 parent ca58afc commit 9fae568
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 38 deletions.
20 changes: 13 additions & 7 deletions docs/HTML/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,23 @@
<BR>
In all formats the following data types are supported:
<PRE>
float
double
float -- float
double -- double
longdouble -- long double
int
short -- short int
ushort -- unsigned short int
int -- int
uint -- unsigned int
long
long -- long int
longlong -- long long int
ulong -- unsigned long
ulong -- unsigned long int
ulonglong -- unsigned long long int
string
bool
char -- char
uchar -- unsigned char
string -- std::string
string -- const char *
string -- char *
bool -- bool
DateTime -- DateTime data in format of &lt;Epoch seconds&gt;.&lt;nanoseconds&gt; (1516179600.874123908)
</PRE>
In case of io_format::csv2 the following additional types are also supported:
Expand Down
20 changes: 13 additions & 7 deletions docs/HTML/write.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,23 @@
<BR>
In all formats the following data types are supported:
<PRE>
float
double
float -- float
double -- double
longdouble -- long double
int
short -- short int
ushort -- unsigned short int
int -- int
uint -- unsigned int
long
long -- long int
longlong -- long long int
ulong -- unsigned long
ulong -- unsigned long int
ulonglong -- unsigned long long int
string
bool
char -- char
uchar -- unsigned char
string -- std::string
string -- const char *
string -- char *
bool -- bool
DateTime -- DateTime data in format of &lt;Epoch seconds&gt;.&lt;nanoseconds&gt; (1516179600.874123908)
</PRE>
In case of io_format::csv2 the following additional types are also supported:
Expand Down
4 changes: 2 additions & 2 deletions include/DataFrame/Internals/DataFrame_misc.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ DataFrame<I, H>::print_csv_functor_<Ts ...>::operator() (const T &vec) {

if (vec_size > 0) {
for (long i = sr; i < er; ++i)
os << vec[i] << ',';
_write_csv_df_index_(os, vec[i]) << ',';
}
os << '\n';

Expand Down Expand Up @@ -266,7 +266,7 @@ template<typename T>
void DataFrame<I, H>::
print_csv2_data_functor_<S, Ts ...>::operator() (const T &vec) {

if (vec.size() > index) os << vec[index];
if (vec.size() > index) _write_csv_df_index_(os, vec[index]);
return;
}

Expand Down
45 changes: 45 additions & 0 deletions include/DataFrame/Internals/DataFrame_standalone.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <DataFrame/Utils/DateTime.h>
#include <DataFrame/Utils/Threads/ThreadGranularity.h>

#include <cctype>
#include <cstdlib>
#include <cstring>
#include <future>
Expand Down Expand Up @@ -582,6 +583,28 @@ inline static S &_write_json_df_index_(S &o, const std::string &value) {

// ----------------------------------------------------------------------------

template<typename S>
inline static S &_write_json_df_index_(S &o, char value) {

if (std::isprint(value))
return (o << value);
else
return (o << static_cast<int>(value));
}

// ----------------------------------------------------------------------------

template<typename S>
inline static S &_write_json_df_index_(S &o, unsigned char value) {

if (std::isprint(value))
return (o << value);
else
return (o << static_cast<unsigned int>(value));
}

// ----------------------------------------------------------------------------

inline static void
_get_token_from_file_ (std::istream &file,
char delim,
Expand Down Expand Up @@ -830,6 +853,28 @@ inline static S &_write_csv_df_index_(S &o, const DateTime &value) {

// ----------------------------------------------------------------------------

template<typename S>
inline static S &_write_csv_df_index_(S &o, char value) {

if (std::isprint(value))
return (o << value);
else
return (o << static_cast<int>(value));
}

// ----------------------------------------------------------------------------

template<typename S>
inline static S &_write_csv_df_index_(S &o, unsigned char value) {

if (std::isprint(value))
return (o << value);
else
return (o << static_cast<unsigned int>(value));
}

// ----------------------------------------------------------------------------

//
// Specializing std::hash for tuples
//
Expand Down
44 changes: 22 additions & 22 deletions test/dataframe_tester_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ str_col:28:<string>:XXXX10,XXXX11,XXXX01,XXXX02,XXXX03,XXXX6,XXXX7,Running fast,
dbl_col: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: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: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,
char_col:11:<char>:,,x,,A,,,�,,A,,
char_col:11:<char>:0,0,x,0,A,0,0,-6,0,A,0,

INDEX:28:<DateTime>:1547825036.3,1516179600.874123908,1516093200.234,1516006800.234098,1515920400.2309,1515834000.89,1515747600.123456789,1515661200.12309,1515574800.4562387,1515488400.2345609,1515402000.78,1515315600.340987645,1515229200.309812765,1515142800.93451984,1515056400.671092346,1514970000.450137234,1514883600.91256923,1514797200.67,1514624400.4562,1514538000.5,1514451600.0,1514365200.896120945,1514278800.783452098,378205200000.561209834,409741200000.346,441277200000.340987,472899600.0,504435600.871234561,
ul_col:28:<ulong>:123450,123451,123452,123450,123455,123450,123449,123448,123451,123452,123452,123450,123455,123450,123454,123453,123456,123457,123458,123459,123460,123441,123442,123432,123433,123434,123435,123436,
Expand Down Expand Up @@ -752,12 +752,12 @@ col_3:1:<double>:15,
col_str:1:<string>:11,
col_4:1:<double>:22,

INDEX:1:<ulong>:123452,
col_1:1:<double>:3,
col_2:1:<double>:10,
col_3:1:<double>:17,
col_str:1:<string>:33,
col_4:1:<double>:24,
INDEX:1:<ulong>:123451,
col_1:1:<double>:2,
col_2:1:<double>:9,
col_3:1:<double>:16,
col_str:1:<string>:22,
col_4:1:<double>:23,


Testing write(json) ...
Expand Down Expand Up @@ -1343,9 +1343,9 @@ ul_col:28:<ulong>,xint_col:28:<int>,str_col:25:<string>,dbl_col:27:<double>,dbl_
Testing no_index_reads ...
INDEX:28:<ulong>,ul_col:28:<ulong>,dbl_col_2:26:<double>,bool_col:6:<bool>,str_col:28:<string>,xint_col:28:<int>,dbl_col:27:<double>,char_col:25:<char>,uchar_col:25:<uchar>,ul_col_2:28:<ulong>,dbl_col_2_2:26:<double>,bool_col_2:6:<bool>,str_col_2:28:<string>,xint_col_2:28:<int>,dbl_col_3_2:27:<double>,ul_col_no_idx:28:<ulong>,dbl_col_2_no_idx:26:<double>,bool_col_no_idx:6:<bool>,str_col_no_idx:28:<string>,xint_col_no_idx:28:<int>,dbl_col_no_idx:27:<double>
123450,123450,0.998,1,4% of something,1,1.2345,C,B,123450,0.998,1,4% of something,1,1.2345,123450,0.998,1,4% of something,1,1.2345
123451,123451,0.3456,1,Description 4/5,2,2.2345,,B,123451,0.3456,1,Description 4/5,2,2.2345,123451,0.3456,1,Description 4/5,2,2.2345
123451,123451,0.3456,1,Description 4/5,2,2.2345,23,B,123451,0.3456,1,Description 4/5,2,2.2345,123451,0.3456,1,Description 4/5,2,2.2345
123452,123452,0.056,1,This is bad,3,3.2345,^,&,123452,0.056,1,This is bad,3,3.2345,123452,0.056,1,This is bad,3,3.2345
123450,123450,0.15678,0,3.4% of GDP,4,4.2345,F,,123450,0.15678,0,3.4% of GDP,4,4.2345,123450,0.15678,0,3.4% of GDP,4,4.2345
123450,123450,0.15678,0,3.4% of GDP,4,4.2345,F,250,123450,0.15678,0,3.4% of GDP,4,4.2345,123450,0.15678,0,3.4% of GDP,4,4.2345
123455,123455,0.00345,0,Market drops,5,5.2345,x,B,123455,0.00345,0,Market drops,5,5.2345,123455,0.00345,0,Market drops,5,5.2345
123450,123450,0.923,1,Market pulls back,3,3,N,B,123450,0.923,1,Market pulls back,3,3,123450,0.923,1,Market pulls back,3,3
123449,123449,0.06743,,$15 increase,7,0.9999,C,B,123449,0.06743,,$15 increase,7,0.9999,123449,0.06743,,$15 increase,7,0.9999
Expand Down Expand Up @@ -1374,17 +1374,17 @@ INDEX:28:<ulong>,ul_col:28:<ulong>,dbl_col_2:26:<double>,bool_col:6:<bool>,str_c


INDEX:28:<ulong>,ul_col:28:<ulong>,xint_col:28:<int>,str_col:28:<string>,dbl_col:28:<double>,dbl_col_2:28:<double>,bool_col:28:<bool>,ul_col_2:28:<ulong>,xint_col_2:28:<int>,str_col_2:28:<string>,dbl_col_3:28:<double>,dbl_col_2_2:28:<double>,bool_col_2:28:<bool>,ul_col_no_idx:28:<ulong>,xint_col_no_idx:28:<int>,str_col_no_idx:28:<string>,dbl_col_no_idx:28:<double>,dbl_col_2_no_idx:28:<double>,bool_col_no_idx:28:<bool>,char_col:11:<char>
123432,123450,35,XXXX10,2.009,0.87865,0,123450,35,XXXX10,2.009,0.87865,0,123450,35,XXXX10,2.009,0.87865,0,
123433,123451,36,XXXX11,3.111,-0.6999,1,123451,36,XXXX11,3.111,-0.6999,1,123451,36,XXXX11,3.111,-0.6999,1,
123432,123450,35,XXXX10,2.009,0.87865,0,123450,35,XXXX10,2.009,0.87865,0,123450,35,XXXX10,2.009,0.87865,0,0
123433,123451,36,XXXX11,3.111,-0.6999,1,123451,36,XXXX11,3.111,-0.6999,1,123451,36,XXXX11,3.111,-0.6999,1,0
123434,123452,40,XXXX01,10,0.4111,1,123452,40,XXXX01,10,0.4111,1,123452,40,XXXX01,10,0.4111,1,x
123435,123450,45,XXXX02,4.2222,0.1902,1,123450,45,XXXX02,4.2222,0.1902,1,123450,45,XXXX02,4.2222,0.1902,1,
123435,123450,45,XXXX02,4.2222,0.1902,1,123450,45,XXXX02,4.2222,0.1902,1,123450,45,XXXX02,4.2222,0.1902,1,0
123436,123455,46,XXXX03,5.3333,-0.4888,0,123455,46,XXXX03,5.3333,-0.4888,0,123455,46,XXXX03,5.3333,-0.4888,0,A
123441,123450,33,XXXX6,12,0.2,0,123450,33,XXXX6,12,0.2,0,123450,33,XXXX6,12,0.2,0,
123442,123449,34,XXXX7,6.25,0.1056,1,123449,34,XXXX7,6.25,0.1056,1,123449,34,XXXX7,6.25,0.1056,1,
123448,123448,8,Running fast,10,0.1,0,123448,8,Running fast,10,0.1,0,123448,8,Running fast,10,0.1,0,
123449,123451,7,$15 increase,0.9999,0.06743,0,123451,7,$15 increase,0.9999,0.06743,0,123451,7,$15 increase,0.9999,0.06743,0,
123441,123450,33,XXXX6,12,0.2,0,123450,33,XXXX6,12,0.2,0,123450,33,XXXX6,12,0.2,0,0
123442,123449,34,XXXX7,6.25,0.1056,1,123449,34,XXXX7,6.25,0.1056,1,123449,34,XXXX7,6.25,0.1056,1,0
123448,123448,8,Running fast,10,0.1,0,123448,8,Running fast,10,0.1,0,123448,8,Running fast,10,0.1,0,-6
123449,123451,7,$15 increase,0.9999,0.06743,0,123451,7,$15 increase,0.9999,0.06743,0,123451,7,$15 increase,0.9999,0.06743,0,0
123450,123452,1,4% of something,1.2345,0.998,0,123452,1,4% of something,1.2345,0.998,0,123452,1,4% of something,1.2345,0.998,0,A
123450,123452,4,3.4% of GDP,4.2345,0.15678,1,123452,4,3.4% of GDP,4.2345,0.15678,1,123452,4,3.4% of GDP,4.2345,0.15678,1,
123450,123452,4,3.4% of GDP,4.2345,0.15678,1,123452,4,3.4% of GDP,4.2345,0.15678,1,123452,4,3.4% of GDP,4.2345,0.15678,1,0
123450,123450,6,Market pulls back,3,0.923,0,123450,6,Market pulls back,3,0.923,0,123450,6,Market pulls back,3,0.923,0,
123450,123455,12,Bonds vs. Equities,8,0.0111,1,123455,12,Bonds vs. Equities,8,0.0111,1,123455,12,Bonds vs. Equities,8,0.0111,1,
123450,123450,14,Here comes the sun,3.3333,-0.8888,0,123450,14,Here comes the sun,3.3333,-0.8888,0,123450,14,Here comes the sun,3.3333,-0.8888,0,
Expand All @@ -1410,14 +1410,14 @@ INDEX:12:<ulong>,col_3:12:<double>,col_4:6:<double>,col_str:12:<string>,col_2:12
123451,16,23,22,9,2,C,C,16,23,22,9,2,16,23,22,9,2,C,C
123452,17,24,33,10,3,F,F,17,24,33,10,3,17,24,33,10,3,F,F
123453,18,25,aa,11,4,$,$,18,25,aa,11,4,18,25,aa,11,4,$,$
123454,19,26,bb,12,5,,,19,26,bb,12,5,19,26,bb,12,5,,
123454,19,26,bb,12,5,0,0,19,26,bb,12,5,19,26,bb,12,5,0,0
123455,20,27,cc,13,6,8,8,20,27,cc,13,6,20,27,cc,13,6,8,8
123456,21,,dd,14,7,x,,21,,dd,14,7,21,,dd,14,7,x,
123456,21,,dd,14,7,x,220,21,,dd,14,7,21,,dd,14,7,x,220
123457,22,,tt,15,8,X,X,22,,tt,15,8,22,,tt,15,8,X,X
123458,23,,uu,16,9,h,h,23,,uu,16,9,23,,uu,16,9,h,h
123459,24,,ii,17,10,u,&,24,,ii,17,10,24,,ii,17,10,u,&
123460,25,,88,18,11,,,25,,88,18,11,25,,88,18,11,,
555555,555.543,,This is a test,777.78,55.55,N,,555.543,,This is a test,777.78,55.55,555.543,,This is a test,777.78,55.55,N,
123460,25,,88,18,11,18,18,25,,88,18,11,25,,88,18,11,18,18
555555,555.543,,This is a test,777.78,55.55,N,255,555.543,,This is a test,777.78,55.55,555.543,,This is a test,777.78,55.55,N,255


Testing KamaVisitor{ } ...
Expand Down Expand Up @@ -2026,7 +2026,7 @@ INDEX:10:<ulong>,string col:10:<string>,Cool Column:10:<string>,numbers:10:<doub
Standard deviation of IBM close prices: 38.3090214006
Correlation between AAPL and IBM close prices: 0.390679511924
The last exponentailly weighted correlation between AAPL and IBM close prices: -0.276248958749
Means of clusters are: 0.0329624207247, -0.00729677926173, -0.0377825146663, 0.00713882726679,
Means of clusters are: -0.0359585603715, 0.00857242079174, 0.0372221454254, -0.00620279540623,
IBM returns 50% quantile: 0.000224447189179, 75% quantile: 0.00742387474272, 95% quantile: 0.0229862030163
The seasonality of IBM returns is 59 days.
So use this instead of 170 days in decomposition analysis
Expand Down

0 comments on commit 9fae568

Please sign in to comment.