Skip to content

Commit b87a0c7

Browse files
Add example of types taking a function (#1015)
1 parent 1ade6a8 commit b87a0c7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/src/examples.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,19 @@ file = CSV.File(IOBuffer(data); types=Dict("col3" => Int))
603603
file = CSV.File(IOBuffer(data); types=[Int, Int, Int])
604604
file = CSV.File(IOBuffer(data); types=[Int, Int, Int], silencewarnings=true)
605605
file = CSV.File(IOBuffer(data); types=[Int, Int, Int], strict=true)
606+
607+
608+
# In this file we have lots of columns, and would like to specify the same type for all
609+
# columns except one which should have a different type. We can do this by providing a
610+
# function that takes the column index and column name and uses these to decide the type.
611+
data = """
612+
col1,col2,col3,col4,col5,col6,col7
613+
1,2,3,4,5,6,7
614+
0,2,3,4,5,6,7
615+
1,2,3,4,5,6,7
616+
"""
617+
file = CSV.File(IOBuffer(data); types=(i, name) -> i == 1 ? Bool : Int8)
618+
file = CSV.File(IOBuffer(data); types=(i, name) -> name == :col1 ? Bool : Int8)
606619
```
607620

608621
## [Typemap](@id typemap_example)

0 commit comments

Comments
 (0)