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
// Look at the most recent row. Note the 'Date' property
92
-
// is of type 'DateOnly' (on .NET 6+) or 'DateTime' (on older targets)
92
+
// is of type 'DateTime' by default. Set PreferDateOnly = true
93
+
// to use 'DateOnly' on .NET 6+
93
94
// and 'Open' has a type 'decimal'
94
95
letfirstRow= msft.Rows |> Seq.head
95
96
letlastDate= firstRow.Date
@@ -108,9 +109,9 @@ collection of rows. We iterate over the rows using a `for` loop. As you can see
108
109
to the columns in the CSV file.
109
110
110
111
As you can see, the type provider also infers types of individual rows. The `Date`
111
-
property is inferred to be a `DateOnly` on .NET 6 and later (because the values in the sample
112
-
file are date-only strings without a time component), or `DateTime` on older targets. HLOC
113
-
prices are inferred as `decimal`.
112
+
property is inferred as `DateTime` by default. When you set `PreferDateOnly = true`
113
+
on .NET 6 and later, date-only strings (without a time component) are inferred as `DateOnly`.
114
+
HLOC prices are inferred as `decimal`.
114
115
115
116
## Using units of measure
116
117
@@ -271,10 +272,9 @@ it by specifying the `InferRows` static parameter of `CsvProvider`. If you speci
271
272
Columns with only `0`, `1`, `Yes`, `No`, `True`, or `False` will be set to `bool`. Columns with numerical values
272
273
will be set to either `int`, `int64`, `decimal`, or `float`, in that order of preference.
273
274
274
-
On .NET 6 and later, columns whose values are all date-only strings (without a time component, e.g. `2023-01-15`)
275
-
are automatically inferred as `DateOnly`. If a column mixes `DateOnly` and `DateTime` values, it is unified to `DateTime`.
276
-
Note that `TimeOnly` is **not** auto-inferred because it is ambiguous with `TimeSpan`; use an explicit schema annotation
277
-
(see the list of valid types below) to get a `TimeOnly` column.
275
+
On .NET 6 and later, when you set `PreferDateOnly = true`, columns whose values are all date-only strings (without a time component, e.g. `2023-01-15`)
276
+
are inferred as `DateOnly`. Time-only strings are inferred as `TimeOnly`. If a column mixes `DateOnly` and `DateTime` values, it is unified to `DateTime`.
277
+
By default (`PreferDateOnly = false`), all date values are inferred as `DateTime` for backward compatibility.
278
278
279
279
If a value is missing in any row, by default the CSV type provider will infer a nullable (for `int`, `int64`, and `DateOnly`) or an optional
280
280
(for `bool`, `DateTime`, `DateTimeOffset`, and `Guid`). When a `decimal` would be inferred but there are missing values, we will infer a
@@ -388,19 +388,20 @@ You can even mix and match the two syntaxes like this `Schema="int64,DidSurvive,
388
388
389
389
### DateOnly and TimeOnly (on .NET 6+)
390
390
391
-
On .NET 6 and later, date-only strings are automatically inferred as `DateOnly`. For example, a column
392
-
like `EventDate` containing values such as `2023-06-01` will be given the type `DateOnly`.
391
+
On .NET 6 and later, when you set `PreferDateOnly = true`, date-only strings are inferred as `DateOnly`
392
+
and time-only strings as `TimeOnly`. For example, a column like `EventDate` containing values such as
393
+
`2023-06-01` will be given the type `DateOnly`. By default (`PreferDateOnly = false`), dates are
394
+
inferred as `DateTime` for backward compatibility.
393
395
394
396
You can also explicitly request a `DateOnly` or `TimeOnly` column using schema annotations:
395
397
396
398
[lang=text]
397
-
EventDate,Duration (timeonly?)
399
+
EventDate (dateonly),Duration (timeonly?)
398
400
2023-06-01,08:30:00
399
401
2023-06-02,
400
402
401
-
In the example above, `EventDate` is auto-inferred as `DateOnly` and `Duration` is explicitly
402
-
annotated as `timeonly?` (a nullable `TimeOnly`). Note that `TimeOnly` is never auto-inferred
403
-
(to avoid confusion with `TimeSpan`), so the schema annotation is required to get a `TimeOnly` column.
403
+
In the example above, `EventDate` is explicitly annotated as `dateonly` and `Duration` is explicitly
"""<summary>Typed representation of a CSV file.</summary>
@@ -255,7 +257,8 @@ type public CsvProvider(cfg: TypeProviderConfig) as this =
255
257
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and to ISO-8859-1 the for HTTP requests, unless <c>charset</c> is specified in the <c>Content-Type</c> response header.</param>
256
258
<param name='ResolutionFolder'>A directory that is used when resolving relative file references (at design time and in hosted execution).</param>
257
259
<param name='EmbeddedResource'>When specified, the type provider first attempts to load the sample from the specified resource
258
-
(e.g. 'MyCompany.MyAssembly, resource_name.csv'). This is useful when exposing types generated by the type provider.</param>"""
260
+
(e.g. 'MyCompany.MyAssembly, resource_name.csv'). This is useful when exposing types generated by the type provider.</param>
261
+
<param name='PreferDateOnly'>When true on .NET 6+, date-only strings are inferred as DateOnly and time-only strings as TimeOnly. Defaults to false for backward compatibility.</param>"""
259
262
260
263
do csvProvTy.AddXmlDoc helpText
261
264
do csvProvTy.DefineStaticParameters(parameters, buildTypes)
"""<summary>Typed representation of an HTML file.</summary>
@@ -112,6 +115,7 @@ type public HtmlProvider(cfg: TypeProviderConfig) as this =
112
115
<param name='ResolutionFolder'>A directory that is used when resolving relative file references (at design time and in hosted execution).</param>
113
116
<param name='EmbeddedResource'>When specified, the type provider first attempts to load the sample from the specified resource
114
117
(e.g. 'MyCompany.MyAssembly, resource_name.html'). This is useful when exposing types generated by the type provider.</param>
118
+
<param name='PreferDateOnly'>When true on .NET 6+, date-only strings are inferred as DateOnly and time-only strings as TimeOnly. Defaults to false for backward compatibility.</param>
"""<summary>Typed representation of a JSON document.</summary>
@@ -185,7 +187,8 @@ type public JsonProvider(cfg: TypeProviderConfig) as this =
185
187
| ValuesAndInlineSchemasHints -> Types of values are inferred from both values and inline schemas. Inline schemas are special string values that can define a type and/or unit of measure. Supported syntax: typeof<type> or typeof{type} or typeof<type<measure>> or typeof{type{measure}}. Valid measures are the default SI units, and valid types are <c>int</c>, <c>int64</c>, <c>bool</c>, <c>float</c>, <c>decimal</c>, <c>date</c>, <c>datetimeoffset</c>, <c>timespan</c>, <c>guid</c> and <c>string</c>.
186
188
| ValuesAndInlineSchemasOverrides -> Same as ValuesAndInlineSchemasHints, but value inferred types are ignored when an inline schema is present.
187
189
</param>
188
-
<param name='Schema'>Location of a JSON Schema file or a string containing a JSON Schema document. When specified, Sample and SampleIsList must not be used.</param>"""
190
+
<param name='Schema'>Location of a JSON Schema file or a string containing a JSON Schema document. When specified, Sample and SampleIsList must not be used.</param>
191
+
<param name='PreferDateOnly'>When true on .NET 6+, date-only strings (e.g. "2023-01-15") are inferred as DateOnly and time-only strings as TimeOnly. Defaults to false for backward compatibility.</param>"""
189
192
190
193
do jsonProvTy.AddXmlDoc helpText
191
194
do jsonProvTy.DefineStaticParameters(parameters, buildTypes)
"""<summary>Typed representation of a XML file.</summary>
@@ -216,7 +218,8 @@ type public XmlProvider(cfg: TypeProviderConfig) as this =
216
218
| ValuesAndInlineSchemasHints -> Types of values are inferred from both values and inline schemas. Inline schemas are special string values that can define a type and/or unit of measure. Supported syntax: typeof<type> or typeof{type} or typeof<type<measure>> or typeof{type{measure}}. Valid measures are the default SI units, and valid types are <c>int</c>, <c>int64</c>, <c>bool</c>, <c>float</c>, <c>decimal</c>, <c>date</c>, <c>datetimeoffset</c>, <c>timespan</c>, <c>guid</c> and <c>string</c>.
217
219
| ValuesAndInlineSchemasOverrides -> Same as ValuesAndInlineSchemasHints, but value inferred types are ignored when an inline schema is present.
218
220
Note inline schemas are not used from Xsd documents.
219
-
</param>"""
221
+
</param>
222
+
<param name='PreferDateOnly'>When true on .NET 6+, date-only strings are inferred as DateOnly and time-only strings as TimeOnly. Defaults to false for backward compatibility.</param>"""
0 commit comments