@@ -56,7 +56,8 @@ def _header2comment(header):
56
56
return comment
57
57
58
58
59
- def _csvhead (nrow , ncol , comment , source_file , author = None ):
59
+ def _csvhead (nrow , ncol , comment , source_file , author = None , \
60
+ add_sys_comments = True ):
60
61
""" Produces a nice header for csv files """
61
62
62
63
# Generate the comments dict
@@ -85,13 +86,6 @@ def _csvhead(nrow, ncol, comment, source_file, author=None):
85
86
head .append (f'# nrow : { nrow } ' )
86
87
head .append (f'# ncol : { ncol } ' )
87
88
88
- for key in sorted (comments ):
89
- head .append (f'# { key } : { comments [key ]} ' )
90
-
91
- now = datetime .now ()
92
- head .append ('# time_generated : ' + \
93
- datetime .strftime (now , '%Y-%m-%d %H:%M:%S' ))
94
-
95
89
# seek author
96
90
if author is None :
97
91
try :
@@ -101,20 +95,29 @@ def _csvhead(nrow, ncol, comment, source_file, author=None):
101
95
102
96
head .append ('# author : ' + author )
103
97
104
- # seek source file
105
- head .append (f'# source_file : { source_file } ' )
98
+ # Add comments
99
+ for key in sorted (comments ):
100
+ head .append (f'# { key } : { comments [key ]} ' )
101
+
102
+ now = datetime .now ()
103
+ head .append ('# time_generated : ' + \
104
+ datetime .strftime (now , '%Y-%m-%d %H:%M:%S' ))
105
+
106
+ if add_sys_comments :
107
+ # seek source file
108
+ head .append (f'# source_file : { source_file } ' )
106
109
107
- # Python config
108
- head .append (f'# work_dir : { os .getcwd ()} ' )
109
- head .append (f'# python_environment { os .name } ' )
110
- version = sys .version .replace ("\n " , " " )
111
- head .append (f'# python_version : { version } ' )
112
- head .append (f'# pandas_version : { pd .__version__ } ' )
113
- head .append (f'# numpy_version : { np .__version__ } ' )
110
+ # Python config
111
+ head .append (f'# work_dir : { os .getcwd ()} ' )
112
+ head .append (f'# python_environment { os .name } ' )
113
+ version = sys .version .replace ("\n " , " " )
114
+ head .append (f'# python_version : { version } ' )
115
+ head .append (f'# pandas_version : { pd .__version__ } ' )
116
+ head .append (f'# numpy_version : { np .__version__ } ' )
114
117
115
- if HAS_DISTUTILS :
116
- head .append ('# python_inc : ' + get_python_inc ())
117
- head .append ('# python_lib : ' + get_python_lib ())
118
+ if HAS_DISTUTILS :
119
+ head .append ('# python_inc : ' + get_python_inc ())
120
+ head .append ('# python_lib : ' + get_python_lib ())
118
121
119
122
head .append ('# --------------------------------------------------' )
120
123
@@ -177,6 +180,7 @@ def write_csv(data, filename, comment,\
177
180
compress = True ,\
178
181
float_format = '%0.5f' ,\
179
182
archive = None ,\
183
+ add_sys_comments = True , \
180
184
** kwargs ):
181
185
''' write a pandas dataframe to csv with comments in header
182
186
@@ -221,7 +225,8 @@ def write_csv(data, filename, comment,\
221
225
head = _csvhead (data .shape [0 ], data .shape [1 ],\
222
226
comment ,\
223
227
source_file = source_file ,\
224
- author = author )
228
+ author = author , \
229
+ add_sys_comments = add_sys_comments )
225
230
226
231
# Check source_file exists
227
232
if not os .path .exists (source_file ):
0 commit comments