OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_readcsv Namespace Reference

Functions

def test_init
 
def test_santander
 
def test_usecols_csv
 
def test_time_parsing
 
def test_csv_fillna
 
def test_null_col
 

Variables

tuple root
 
 engine = None
 

Function Documentation

def test_readcsv.test_csv_fillna ( )

Definition at line 100 of file test_readcsv.py.

101 def test_csv_fillna():
102  target = {
103  'CRIM': [0.00632],
104  'ZN': [18.0],
105  'INDUS': [2.31],
106  'CHAS': [0.0],
107  'NOX': [0.538],
108  'RM': [6.575],
109  'AGE': [65.2],
110  'DIS': [4.09],
111  'RAD': [1.0],
112  'TAX': [296.0],
113  'PTRATIO': [15.3],
114  'B': [396.9],
115  'LSTAT': [4.98],
116  'PRICE': [24.0]
117  }
118  fp = io.BytesIO(
119  b',CRIM,ZN,INDUS,CHAS,NOX,RM,AGE,DIS,RAD,TAX,PTRATIO,B,LSTAT,PRICE\n'
120  b'0,0.00632,18.0,2.31,0.0,0.538,6.575,65.2,4.09,1.0,296.0,15.3,396.9,4.98,24.0\n'
121  )
122  fp.seek(0)
123  table = csv.read_csv(fp)
124  assert table
125  engine.importArrowTable("csv_fillna", table)
126  assert bool(engine.closed) == False
127  cursor = engine.executeDML("select CRIM,ZN,INDUS,CHAS,NOX,RM,AGE,DIS,RAD,TAX,PTRATIO,B,LSTAT,PRICE from csv_fillna")
128  assert cursor
129  batch = cursor.getArrowRecordBatch()
130  assert batch
131  assert batch.to_pydict() == target
def test_readcsv.test_init ( )

Definition at line 17 of file test_readcsv.py.

17 
18 def test_init():
19  global engine
20  engine = dbe.PyDbEngine(
21  enable_union=1,
22  enable_columnar_output=1,
23  enable_lazy_fetch=0,
24  null_div_by_zero=1,
25  )
26  assert bool(engine.closed) == False
def test_readcsv.test_null_col ( )

Definition at line 132 of file test_readcsv.py.

133 def test_null_col():
134  target = {'a': [1, 2, 3], 'b': [1, 2, 3], 'c': [None, None, None]}
135  fp = io.BytesIO(b'a,b,c\n1,1,\n2,2,\n3,3,\n')
136  fp.seek(0)
137  table = csv.read_csv(
138  fp,
139  convert_options=csv.ConvertOptions(
140  column_types={
141  'a': pa.int32(),
142  'b': pa.int64(),
143  'c': pa.int64(),
144  }
145  )
146  )
147  assert table
148  engine.importArrowTable("test_null_col", table)
149  assert bool(engine.closed) == False
150  cursor = engine.executeDML("select * from test_null_col")
151  assert cursor
152  batch = cursor.getArrowRecordBatch()
153  assert batch
154  assert batch.to_pydict() == target
155 
def test_readcsv.test_santander ( )

Definition at line 29 of file test_readcsv.py.

29 
30 def test_santander():
31  table = csv.read_csv(root + "/santander_top1000.csv")
32  assert table
33  engine.importArrowTable("santander", table)
34  assert bool(engine.closed) == False
35  r = engine.executeDML("select * from santander")
36  assert r
37  assert r.colCount() == 202
38  assert r.rowCount() == 999
def test_santander
Definition: test_readcsv.py:29
def test_readcsv.test_time_parsing ( )

Definition at line 72 of file test_readcsv.py.

72 
73 def test_time_parsing():
74  target = {
75  'timestamp': [datetime.datetime(2010, 4, 1, 0, 0), datetime.datetime(2010, 4, 1, 0, 30), datetime.datetime(2010, 4, 1, 1, 0)],
76  'symbol': ['USD/JPY', 'USD/JPY', 'USD/JPY'],
77  'high': [93.526, 93.475, 93.421],
78  'low': [93.361, 93.352, 93.326],
79  'open': [93.518, 93.385, 93.391],
80  'close': [93.382, 93.391, 93.384],
81  'spread': [0.005, 0.006, 0.006],
82  'volume': [3049, 2251, 1577]
83  }
84  fp = io.BytesIO(
85  b'timestamp,symbol,high,low,open,close,spread,volume\n'
86  b'2010-04-01 00:00:00,USD/JPY,93.52600,93.36100,93.51800,93.38200,0.00500,3049\n'
87  b'2010-04-01 00:30:00,USD/JPY,93.47500,93.35200,93.38500,93.39100,0.00600,2251\n'
88  b'2010-04-01 01:00:00,USD/JPY,93.42100,93.32600,93.39100,93.38400,0.00600,1577\n'
89  )
90  fp.seek(0)
91  table = csv.read_csv(fp)
92  assert table
93  engine.importArrowTable("time_parsing", table)
94  assert bool(engine.closed) == False
95  cursor = engine.executeDML("select * from time_parsing")
96  assert cursor
97  batch = cursor.getArrowRecordBatch()
98  assert batch
99  assert batch.to_pydict() == target
def test_time_parsing
Definition: test_readcsv.py:72
def test_readcsv.test_usecols_csv ( )

Definition at line 39 of file test_readcsv.py.

39 
40 def test_usecols_csv():
41  target = {
42  'a': [1, 2, 3, 4, 5, 6],
43  'b': [2, 3, 4, 5, 6, 7],
44  'c': [3, 4, 5, 6, 7, 8],
45  'd': [4, 5, 6, 7, 8, 9],
46  'e': ['5', '6', '7', '8', '9', '0']
47  }
48  fp = io.BytesIO(
49  b'a,b,c,d,e\n1,2,3,4,5\n2,3,4,5,6\n3,4,5,6,7\n4,5,6,7,8\n5,6,7,8,9\n6,7,8,9,0'
50  )
51  fp.seek(0)
52  table = csv.read_csv(
53  fp,
54  convert_options=csv.ConvertOptions(
55  column_types={
56  'a': pa.int32(),
57  'b': pa.int64(),
58  'c': pa.int64(),
59  'd': pa.int64(),
60  'e': pa.string(),
61  }
62  )
63  )
64  assert table
65  engine.importArrowTable("usecols", table)
66  assert bool(engine.closed) == False
67  cursor = engine.executeDML("select * from usecols")
68  assert cursor
69  batch = cursor.getArrowRecordBatch()
70  assert batch
71  assert batch.to_pydict() == target
def test_usecols_csv
Definition: test_readcsv.py:39

Variable Documentation

test_readcsv.engine = None

Definition at line 27 of file test_readcsv.py.

tuple test_readcsv.root
Initial value:
1 = os.path.join(
2  os.path.dirname(
3  os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
4  "Tests/Import/datafiles"
5 )

Definition at line 11 of file test_readcsv.py.