Comments (13)
I agree this should be added. I think generating a constructor which loads the sample data (or loads the file specified as a static parameter) would be the best approach. Then you could write:
let csv = new CsvProvider<"file.csv">()
without even defining a new type.
from fsharp.data.
If you (or someone else) wants to add this, then please also update the samples (samples/*.fsx
) because they could be nicely simplified if we had this feature.
from fsharp.data.
That constructor aproach works fine for CSV, but for JSON and XML it doesn't apply. But instead we can make the parameter of the Load/Parse methods optional, so we that when we don't pass it, it reuses the sample. I'll submit a patch soon
from fsharp.data.
Nice work!
The fact that it now uses different style for CSV than for JSON/XML is a bit unfortunate. What is the reason why using the constructor approach does not work for these two?
Also, I noticed the JSON provider tries to guess whether the string is a JSON using:
if firstChar = '{' || firstChar = '[' then
In principle, I think that true
is also valid JSON. It might not be a problem (often) but if we want to do something more clever than just trying to load the file, it would probably be easier to check if the string is a well-formed URL or path.
from fsharp.data.
I think we should aim to have the following interface for all the tree options:
- static
Parase
method to parse a string input - static
Load
method to parse a file or URL - constructor to parse or load the input according to static parameters
If the constructor takes a string, then it is not clear what is that supposed to mean (it is not too bad, because there is probably a tool tip, but I think having a clear API is better).
from fsharp.data.
While the Parse and Load methods of CSV return an instance of CsvFile, on XML/JSON the return type is an instance of a root under the domain types, so we can't just use the constructor.
We have Load and Parse methods for all, and while for CSV we have the constructor, for XML/JSON, the Load or Parse method (according to if we provided a file or inline data) can be called without parameters, so effectivly the static parameters become the default runtime parameters.
I'd also like to make the 3 providers as similar as possible, but they are very different, CSV is a matrix, JSON/XML are trees, so there's more stuff that's probably going to become different between XML/JSON and CSV, like the write api, for example
from fsharp.data.
About the guessing in the json provider, I'll fix that, I did it to avoid having a lot of exceptions being thrown while debugging, but unlike the xml is not 100% reliable so it needs to have a fallback
from fsharp.data.
Actually, the code is already right, if there's { or [, it knows for sure is not a filename, otherwise it still tries both
from fsharp.data.
Ah, I see.
Okay, let's leave it like this for now, but I would like to avoid this mismatch somehow (but it definitely needs more thinking than I thought :-)).
from fsharp.data.
Just consider this a first draft, we'll probably still change the api a couple of times until we're happy.
I think all the providers still need a lot of work until they mature, every time I try them on real data I find another thing I want to change :)
from fsharp.data.
Sure, I'm just thinking aloud here :-) Thanks for all the hard work on improving the providers as well as on the portable version, you've made some excellent progress here!
from fsharp.data.
While porting the FSharpx unit tests, I come to the conclusion that .Load() and .Parse() to get the default data is weird, trying something else
from fsharp.data.
Are you ok with the current .GetSample() solution for Xml and Json?
from fsharp.data.
Related Issues (20)
- The design-time type 'FSharp.Data.Runtime.StructuralInference+InferenceMode' utilized by a type provider was not found HOT 8
- Support DateOnly and TimeOnly types HOT 2
- FSharp.Data.Core.Tests.CSharp.csproj: [NU1504] Duplicate 'PackageReference' items found. HOT 2
- s HOT 1
- JsonProvider - writable properties? HOT 1
- When closing VS 2022, the FSharp.Data.DesignTime stays on lock that prevents closing the editor. HOT 1
- Why are the core features (`CommonRuntime` folder) implemented in the Http project? HOT 6
- Question: an F# type provider backed by ML.NET for AI/learning HOT 1
- A way forward with the JsonProvider HOT 17
- Requesting a new beta package published to nuget.org HOT 3
- FSharp.Data.Runtime.Utilities is not published HOT 2
- Preserving linefeed style HOT 3
- A new FSharp.Data.JsonSaveOptions value needed HOT 3
- XmlProvider generates types based on name attribute in XSD schema rather than the type attribute HOT 5
- support empty space separator HOT 1
- update pictures in docs with #r nuget reference (no .dll ref)
- Update FSharp.Core from 5 to 6 or 7, to get less memory usage and better performance HOT 4
- System.Text.Json for JsonProvider? HOT 1
- Memory Limitations in XmlProvider HOT 10
- FS3033: Multiple definition of element error.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsharp.data.