How can I define types in a bookmark

Looking at the Types section of https://riskscape.org.nz/docs/reference/bookmarks.html suggests that types can be defined on a per column basis for CSV bookmarks. With the example below how would I cast P50 to float and Year to int?

data.csv

year,p50
2020,0.07
2030,0.12
2040,0.18
2050,0.27
2060,0.36
2070,0.47
2080,0.61
2090,0.77
2100,0.94
2110,1.13
2120,1.34
2130,1.56
2140,1.8
2150,2.06

project.ini

[bookmark data]
location = data.csv
format = csv
#set-attribute.p50 = floating(p50)
#set-attribute.year = integer(year)

Kia ora,

You can use the type bookmark parameter to define the type that the underlying CSV data has. To do this you would define a type that represents the CSV data, and then use that type ID in the bookmark. E.g.

[type my_csv_data]
type.p50 = floating
type.year = integer

[bookmark example_one]
location = data.csv
type = my_csv_data

You can also define types in-line in the bookmark, like this:

[bookmark example_two]
location = data.csv
format = csv
type = struct(p50: floating, year: integer)

A couple final things to note when a type is specified for the bookmark:

  • Only the attributes specified in the type will be available in the pipeline. Any additional attributes in the CSV file will just be ignored.
  • Use map-attribute.NAME instead of set-attribute.NAME if you need to apply any other conversions to the data (besides the change in type)

Hope that helps.

Tim