Skip to content

Commit

Permalink
Fix csv.py parser mappings (#5602)
Browse files Browse the repository at this point in the history
Fixes #5601
  • Loading branch information
devinrsmith authored Jun 11, 2024
1 parent 29ce5ee commit 2e5f72c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions py/server/deephaven/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def read(
dht.byte: _JParsers.BYTE,
dht.char: _JParsers.CHAR,
dht.short: _JParsers.SHORT,
dht.int64: _JParsers.INT,
dht.int32: _JParsers.INT,
dht.long: _JParsers.LONG,
dht.float64: _JParsers.FLOAT_FAST,
dht.float32: _JParsers.FLOAT_FAST,
dht.double: _JParsers.DOUBLE,
dht.string: _JParsers.STRING,
dht.Instant: _JParsers.DATETIME,
Expand Down
2 changes: 2 additions & 0 deletions py/server/tests/data/primitive_types.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bool,Byte,Char,Short,Int,Long,Float,Double
true,42,a,42,42,42,42.42,42.42
26 changes: 25 additions & 1 deletion py/server/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import unittest

from deephaven import dtypes, DHError
from deephaven import read_csv, write_csv
from deephaven import read_csv, write_csv, new_table
from deephaven.column import bool_col, byte_col, char_col, short_col, int_col, long_col, float_col, double_col
from tests.testbase import BaseTestCase


Expand Down Expand Up @@ -66,6 +67,29 @@ def test_read_header_row(self):
with self.assertRaises(DHError):
t1 = read_csv("tests/data/small_sample.csv", headless=True, header_row=2)

def test_primitive_types(self):
actual = read_csv("tests/data/primitive_types.csv", {
'Bool': dtypes.bool_,
'Byte': dtypes.byte,
'Char': dtypes.char,
'Short': dtypes.short,
'Int': dtypes.int32,
'Long': dtypes.long,
'Float': dtypes.float32,
'Double': dtypes.double,
})
expected = new_table([
bool_col('Bool', [True]),
byte_col('Byte', [42]),
char_col('Char', [ord('a')]),
short_col('Short', [42]),
int_col('Int', [42]),
long_col('Long', [42]),
float_col('Float', [42.42]),
double_col('Double', [42.42])
])
self.assert_table_equals(actual, expected)


if __name__ == '__main__':
unittest.main()

0 comments on commit 2e5f72c

Please sign in to comment.