grasp
grasp copied to clipboard
Support for data type in CSV class.
Currently, CSV class object doesn't care about the DataType of incoming/outgoing data. This can create inconvenience for some users. For eg. if I have a numerical CSV file, the CSV._load() function still loads all data in unicode string format.
This patch allows users to send Datatype also, when they are initiating a CSV object. In case no datatype is given, datatype defaults to unicode/u.
Some other modifications are also possible in CSV class.
- Currently, if some CSV object holds some fixed sized rows and user wishes to append some more rows, then there is no check to ensure that the size of newly added row will be same as before. For eg.
>>> data = CSV("test.csv")
>>> data
[[u's', u'y', u's']]
>>> data.append([1,2])
>>> data
[[u's', u'y', u's'], [1, 2]]
As you can see, sizes are bot proper, as well as datatypes mismatch.
- There is special importance given to headers(they exist in some CSV files). We can try to modify code to incorporate header information. For eg.
PassengerID,Survived
892,0
893,0