You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across this problem when trying to work around #17.
Given a data file with a column 'date', which contains an integer (a unix timestamp), and
a dataclass with a field of date which is of type datetime.datetime. Since there isn't a way to convert that in dataclass_csv today, I munged the dataclass a bit, made date an init=False field, introduced an InitVar of unix_ts, and used post_init to convert the unix timestamp to a datetime field like so:
This works exactly as expected: the init signature is looking for unix_ts instead of date, date gets set with the value of unix_ts, all my consumers of the dataclass object don't have to change.
... until I try to load the data from dataclass_csv, at any rate.
reader = DataclassReader(inp, SomeData)
reader.map('date').to('unix_ts')
for record in reader:
...
This generates the standard 'hey, you're telling me to map onto a datetime field, and didn't tell me how to convert:
AttributeError: Unable to parse the datetime string value. Date format not specified. To specify a date format for all datetime fields in the class, use the @dateformat decorator. To define a date format specifically for this field, change its definition to: `date: datetime = field(metadata={'dateformat': <date_format>})`
Okay, fine, I figure I'll open an issue (here it is!), and I'll rename the date field on my dataclass to something else. Then I run into #9 because despite having init=False, it's still trying to build it into the construction of my class.
So, between #9 and #17, I'm actually stuck at the moment, but while working both of those out, I encountered this issue and thought I'd raise it.
The text was updated successfully, but these errors were encountered:
I came across this problem when trying to work around #17.
Given a data file with a column 'date', which contains an integer (a unix timestamp), and
a dataclass with a field of
date
which is of type datetime.datetime. Since there isn't a way to convert that in dataclass_csv today, I munged the dataclass a bit, madedate
aninit=False
field, introduced an InitVar ofunix_ts
, and used post_init to convert the unix timestamp to a datetime field like so:This works exactly as expected: the init signature is looking for unix_ts instead of date, date gets set with the value of unix_ts, all my consumers of the dataclass object don't have to change.
... until I try to load the data from dataclass_csv, at any rate.
This generates the standard 'hey, you're telling me to map onto a datetime field, and didn't tell me how to convert:
Okay, fine, I figure I'll open an issue (here it is!), and I'll rename the
date
field on my dataclass to something else. Then I run into #9 because despite having init=False, it's still trying to build it into the construction of my class.So, between #9 and #17, I'm actually stuck at the moment, but while working both of those out, I encountered this issue and thought I'd raise it.
The text was updated successfully, but these errors were encountered: