88
88
"TextCol" TEXT,
89
89
"DateCol" TEXT,
90
90
"IntDateCol" INTEGER,
91
+ "IntDateOnlyCol" INTEGER,
91
92
"FloatCol" REAL,
92
93
"IntCol" INTEGER,
93
94
"BoolCol" INTEGER,
98
99
`TextCol` TEXT,
99
100
`DateCol` DATETIME,
100
101
`IntDateCol` INTEGER,
102
+ `IntDateOnlyCol` INTEGER,
101
103
`FloatCol` DOUBLE,
102
104
`IntCol` INTEGER,
103
105
`BoolCol` BOOLEAN,
109
111
"DateCol" TIMESTAMP,
110
112
"DateColWithTz" TIMESTAMP WITH TIME ZONE,
111
113
"IntDateCol" INTEGER,
114
+ "IntDateOnlyCol" INTEGER,
112
115
"FloatCol" DOUBLE PRECISION,
113
116
"IntCol" INTEGER,
114
117
"BoolCol" BOOLEAN,
120
123
'sqlite' : {
121
124
'query' : """
122
125
INSERT INTO types_test_data
123
- VALUES(?, ?, ?, ?, ?, ?, ?, ?)
126
+ VALUES(?, ?, ?, ?, ?, ?, ?, ?, ? )
124
127
""" ,
125
128
'fields' : (
126
- 'TextCol' , 'DateCol' , 'IntDateCol' , 'FloatCol' ,
127
- 'IntCol' , 'BoolCol' , 'IntColWithNull' , 'BoolColWithNull'
129
+ 'TextCol' , 'DateCol' , 'IntDateCol' , 'IntDateOnlyCol' ,
130
+ 'FloatCol' , 'IntCol' , 'BoolCol' , 'IntColWithNull' ,
131
+ 'BoolColWithNull'
128
132
)
129
133
},
130
134
'mysql' : {
131
135
'query' : """
132
136
INSERT INTO types_test_data
133
- VALUES("%s", %s, %s, %s, %s, %s, %s, %s)
137
+ VALUES("%s", %s, %s, %s, %s, %s, %s, %s, %s )
134
138
""" ,
135
139
'fields' : (
136
- 'TextCol' , 'DateCol' , 'IntDateCol' , 'FloatCol' ,
137
- 'IntCol' , 'BoolCol' , 'IntColWithNull' , 'BoolColWithNull'
140
+ 'TextCol' , 'DateCol' , 'IntDateCol' , 'IntDateOnlyCol' ,
141
+ 'FloatCol' , 'IntCol' , 'BoolCol' , 'IntColWithNull' ,
142
+ 'BoolColWithNull'
138
143
)
139
144
},
140
145
'postgresql' : {
141
146
'query' : """
142
147
INSERT INTO types_test_data
143
- VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)
148
+ VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s )
144
149
""" ,
145
150
'fields' : (
146
151
'TextCol' , 'DateCol' , 'DateColWithTz' ,
147
- 'IntDateCol' , 'FloatCol' ,
152
+ 'IntDateCol' , 'IntDateOnlyCol' , ' FloatCol' ,
148
153
'IntCol' , 'BoolCol' , 'IntColWithNull' , 'BoolColWithNull'
149
154
)
150
155
},
@@ -313,13 +318,13 @@ def _load_raw_sql(self):
313
318
self .drop_table ('types_test_data' )
314
319
self ._get_exec ().execute (SQL_STRINGS ['create_test_types' ][self .flavor ])
315
320
ins = SQL_STRINGS ['insert_test_types' ][self .flavor ]
316
-
317
321
data = [
318
322
{
319
323
'TextCol' : 'first' ,
320
324
'DateCol' : '2000-01-03 00:00:00' ,
321
325
'DateColWithTz' : '2000-01-01 00:00:00-08:00' ,
322
326
'IntDateCol' : 535852800 ,
327
+ 'IntDateOnlyCol' : 20101010 ,
323
328
'FloatCol' : 10.10 ,
324
329
'IntCol' : 1 ,
325
330
'BoolCol' : False ,
@@ -331,6 +336,7 @@ def _load_raw_sql(self):
331
336
'DateCol' : '2000-01-04 00:00:00' ,
332
337
'DateColWithTz' : '2000-06-01 00:00:00-07:00' ,
333
338
'IntDateCol' : 1356998400 ,
339
+ 'IntDateOnlyCol' : 20101212 ,
334
340
'FloatCol' : 10.10 ,
335
341
'IntCol' : 1 ,
336
342
'BoolCol' : False ,
@@ -610,20 +616,42 @@ def test_date_parsing(self):
610
616
df = sql .read_sql_query ("SELECT * FROM types_test_data" , self .conn ,
611
617
parse_dates = ['DateCol' ])
612
618
assert issubclass (df .DateCol .dtype .type , np .datetime64 )
619
+ assert df .DateCol .tolist () == [
620
+ pd .Timestamp (2000 , 1 , 3 , 0 , 0 , 0 ),
621
+ pd .Timestamp (2000 , 1 , 4 , 0 , 0 , 0 )
622
+ ]
613
623
614
624
df = sql .read_sql_query ("SELECT * FROM types_test_data" , self .conn ,
615
625
parse_dates = {'DateCol' : '%Y-%m-%d %H:%M:%S' })
616
626
assert issubclass (df .DateCol .dtype .type , np .datetime64 )
627
+ assert df .DateCol .tolist () == [
628
+ pd .Timestamp (2000 , 1 , 3 , 0 , 0 , 0 ),
629
+ pd .Timestamp (2000 , 1 , 4 , 0 , 0 , 0 )
630
+ ]
617
631
618
632
df = sql .read_sql_query ("SELECT * FROM types_test_data" , self .conn ,
619
633
parse_dates = ['IntDateCol' ])
620
-
621
634
assert issubclass (df .IntDateCol .dtype .type , np .datetime64 )
635
+ assert df .IntDateCol .tolist () == [
636
+ pd .Timestamp (1986 , 12 , 25 , 0 , 0 , 0 ),
637
+ pd .Timestamp (2013 , 1 , 1 , 0 , 0 , 0 )
638
+ ]
622
639
623
640
df = sql .read_sql_query ("SELECT * FROM types_test_data" , self .conn ,
624
641
parse_dates = {'IntDateCol' : 's' })
625
-
626
642
assert issubclass (df .IntDateCol .dtype .type , np .datetime64 )
643
+ assert df .IntDateCol .tolist () == [
644
+ pd .Timestamp (1986 , 12 , 25 , 0 , 0 , 0 ),
645
+ pd .Timestamp (2013 , 1 , 1 , 0 , 0 , 0 )
646
+ ]
647
+
648
+ df = sql .read_sql_query ("SELECT * FROM types_test_data" , self .conn ,
649
+ parse_dates = {'IntDateOnlyCol' : '%Y%m%d' })
650
+ assert issubclass (df .IntDateOnlyCol .dtype .type , np .datetime64 )
651
+ assert df .IntDateOnlyCol .tolist () == [
652
+ pd .Timestamp ('2010-10-10' ),
653
+ pd .Timestamp ('2010-12-12' )
654
+ ]
627
655
628
656
def test_date_and_index (self ):
629
657
# Test case where same column appears in parse_date and index_col
0 commit comments