From Excel Sheets to Deedle Data Frame
Deedle provides a CSV Type Provider out of the box, but I do not take a solution based on file format transformation into account for Excel files on a Windows platform. It seemed straight forward to me to enhance the example code of the Sample Pack and FSSnip to get this task done. Two sub-problems turned out to raise concerns:
- transfer the data from the Excel object into a F# data structure that could be coerced to a Deedle data frame,
- manage the life cycle of the Excel object properly while avoiding boilerplate code as much as possible.
The member function are implemented via external helper function which I chose not to include in the class. The first version 'getFrameWithStringHeader', which is a straightforward adaption of the FSSnip code example, is disapointingly slow because of the per-cell access mode. An improved version 'getFrameWithHeader' graps the Excel range in one piece. The complete source code is published on Github. The code would need further cleanup, but I think it reveals the interesting points properly.
I purposely coerced the Excel data in a semi-generic Frame of type 'int * 'a', where the column selector type is derived from the Excel input, but the row selector type is fixed. I do not think that this is a major restriction as, for example, time series data will most likely keep the time information in a separate series instead of using the time points as row indices.
The Excel workbook class handles errors in terms of returning 'None'. Exceptions in dealing with Excel and the Excel file are purposely captured. I think, I found the same idea on Scott Wlaschin's blog FSharpForFunAndProfit, which is a good read anyway. The Excel resource management works well as far as I can tell.
Porting Functional Code from Clojure to F#
It is a nice experience that porting code functional code from Clojure to F# does not raise specific pain. It is also interesting to learn by example where the difference between dynamically typed and strong typed strikes. I really appreciate the tool support by the compiler and debugger as a reward for the enforced type discipline which reduces the hammock and REPL time quite bit for me. You may want to look yourself at the code comparison here.