Skip to content

Commit

Permalink
Fix for #33
Browse files Browse the repository at this point in the history
* Add date format string to fluxnet_config file
* add date format option to pd.to_datetime function following #33 change
  • Loading branch information
JohnVolk committed Apr 1, 2024
1 parent 8a9dffc commit d188216
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/Basic_usage/fluxnet_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ station_longitude = -99.42
station_elevation = 611
anemometer_height = 3
missing_data_value = -9999
date_parser = %Y%m%d

[DATA]
datestring_col = TIMESTAMP
Expand Down
12 changes: 9 additions & 3 deletions fluxdataqaqc/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,11 @@ def df(self):

if 'date_parser' in dict(self.config.items('METADATA')):
date_parse_str = self.config.get('METADATA','date_parser')
date_parser = lambda x: datetime.strptime(x, date_parse_str)
kwargs['date_parser'] = date_parser
#date_parser = lambda x: datetime.strptime(x, date_parse_str)
#kwargs['date_parser'] = date_parser
else:
date_parse_str = None

if 'load_all_vars' in dict(self.config.items('METADATA')):
# if this option is listed (with any value) read all columns into df
cols = self.header
Expand All @@ -1124,7 +1127,10 @@ def df(self):
usecols = cols,
**kwargs
)
df[variables.get('date')] = pd.to_datetime(df[variables.get('date')])

df[variables.get('date')] = pd.to_datetime(
df[variables.get('date')], format=date_parse_str
)

if 'missing_data_value' in dict(self.config.items('METADATA')):
# force na_val because sometimes with read_excel it doesn't work...
Expand Down

0 comments on commit d188216

Please sign in to comment.