-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: formating integers datetimes using sql GH17855 #17882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
0498dd1
385ad78
e3a438b
26454e7
102ab25
5b56686
987f588
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ | |
"TextCol" TEXT, | ||
"DateCol" TEXT, | ||
"IntDateCol" INTEGER, | ||
"IntDateOnlyCol" INTEGER, | ||
"FloatCol" REAL, | ||
"IntCol" INTEGER, | ||
"BoolCol" INTEGER, | ||
|
@@ -98,6 +99,7 @@ | |
`TextCol` TEXT, | ||
`DateCol` DATETIME, | ||
`IntDateCol` INTEGER, | ||
"IntDateOnlyCol" INTEGER, | ||
`FloatCol` DOUBLE, | ||
`IntCol` INTEGER, | ||
`BoolCol` BOOLEAN, | ||
|
@@ -109,6 +111,7 @@ | |
"DateCol" TIMESTAMP, | ||
"DateColWithTz" TIMESTAMP WITH TIME ZONE, | ||
"IntDateCol" INTEGER, | ||
"IntDateOnlyCol" INTEGER, | ||
"FloatCol" DOUBLE PRECISION, | ||
"IntCol" INTEGER, | ||
"BoolCol" BOOLEAN, | ||
|
@@ -120,31 +123,33 @@ | |
'sqlite': { | ||
'query': """ | ||
INSERT INTO types_test_data | ||
VALUES(?, ?, ?, ?, ?, ?, ?, ?) | ||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?) | ||
""", | ||
'fields': ( | ||
'TextCol', 'DateCol', 'IntDateCol', 'FloatCol', | ||
'IntCol', 'BoolCol', 'IntColWithNull', 'BoolColWithNull' | ||
'TextCol', 'DateCol', 'IntDateCol', 'IntDateOnlyCol', | ||
'FloatCol', 'IntCol', 'BoolCol', 'IntColWithNull', | ||
'BoolColWithNull' | ||
) | ||
}, | ||
'mysql': { | ||
'query': """ | ||
INSERT INTO types_test_data | ||
VALUES("%s", %s, %s, %s, %s, %s, %s, %s) | ||
VALUES("%s", %s, %s, %s, %s, %s, %s, %s, %s) | ||
""", | ||
'fields': ( | ||
'TextCol', 'DateCol', 'IntDateCol', 'FloatCol', | ||
'IntCol', 'BoolCol', 'IntColWithNull', 'BoolColWithNull' | ||
'TextCol', 'DateCol', 'IntDateCol', 'IntDateOnlyCol', | ||
'FloatCol', 'IntCol', 'BoolCol', 'IntColWithNull', | ||
'BoolColWithNull' | ||
) | ||
}, | ||
'postgresql': { | ||
'query': """ | ||
INSERT INTO types_test_data | ||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s) | ||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) | ||
""", | ||
'fields': ( | ||
'TextCol', 'DateCol', 'DateColWithTz', | ||
'IntDateCol', 'FloatCol', | ||
'IntDateCol', 'IntDateOnlyCol', 'FloatCol', | ||
'IntCol', 'BoolCol', 'IntColWithNull', 'BoolColWithNull' | ||
) | ||
}, | ||
|
@@ -313,13 +318,13 @@ def _load_raw_sql(self): | |
self.drop_table('types_test_data') | ||
self._get_exec().execute(SQL_STRINGS['create_test_types'][self.flavor]) | ||
ins = SQL_STRINGS['insert_test_types'][self.flavor] | ||
|
||
data = [ | ||
{ | ||
'TextCol': 'first', | ||
'DateCol': '2000-01-03 00:00:00', | ||
'DateColWithTz': '2000-01-01 00:00:00-08:00', | ||
'IntDateCol': 535852800, | ||
'IntDateOnlyCol': 20101010, | ||
'FloatCol': 10.10, | ||
'IntCol': 1, | ||
'BoolCol': False, | ||
|
@@ -331,6 +336,7 @@ def _load_raw_sql(self): | |
'DateCol': '2000-01-04 00:00:00', | ||
'DateColWithTz': '2000-06-01 00:00:00-07:00', | ||
'IntDateCol': 1356998400, | ||
'IntDateOnlyCol': 20101212, | ||
'FloatCol': 10.10, | ||
'IntCol': 1, | ||
'BoolCol': False, | ||
|
@@ -610,20 +616,42 @@ def test_date_parsing(self): | |
df = sql.read_sql_query("SELECT * FROM types_test_data", self.conn, | ||
parse_dates=['DateCol']) | ||
assert issubclass(df.DateCol.dtype.type, np.datetime64) | ||
assert df.DateCol.tolist() == [ | ||
pd.Timestamp(2000, 1, 3, 0, 0, 0), | ||
pd.Timestamp(2000, 1, 4, 0, 0, 0) | ||
] | ||
|
||
df = sql.read_sql_query("SELECT * FROM types_test_data", self.conn, | ||
parse_dates={'DateCol': '%Y-%m-%d %H:%M:%S'}) | ||
assert issubclass(df.DateCol.dtype.type, np.datetime64) | ||
assert df.DateCol.tolist() == [ | ||
pd.Timestamp(2000, 1, 3, 0, 0, 0), | ||
pd.Timestamp(2000, 1, 4, 0, 0, 0) | ||
] | ||
|
||
df = sql.read_sql_query("SELECT * FROM types_test_data", self.conn, | ||
parse_dates=['IntDateCol']) | ||
|
||
assert issubclass(df.IntDateCol.dtype.type, np.datetime64) | ||
assert df.IntDateCol.tolist() == [ | ||
pd.Timestamp(1986, 12, 25, 0, 0, 0), | ||
pd.Timestamp(2013, 1, 1, 0, 0, 0) | ||
] | ||
|
||
df = sql.read_sql_query("SELECT * FROM types_test_data", self.conn, | ||
parse_dates={'IntDateCol': 's'}) | ||
|
||
assert issubclass(df.IntDateCol.dtype.type, np.datetime64) | ||
assert df.IntDateCol.tolist() == [ | ||
pd.Timestamp(1986, 12, 25, 0, 0, 0), | ||
pd.Timestamp(2013, 1, 1, 0, 0, 0) | ||
] | ||
|
||
df = sql.read_sql_query("SELECT * FROM types_test_data", self.conn, | ||
parse_dates={'IntDateOnlyCol': '%Y%m%d'}) | ||
assert issubclass(df.IntDateOnlyCol.dtype.type, np.datetime64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback I included a test. I also noticed that the existing tests are not enough. It might be that the parsing returns a Would you agree there's a problem with the tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, those are indeed not very thorough. Do you want to add such a similar check to the others as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jorisvandenbossche Within this same PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that would be good yes (because as you said, with your changes you could actually silently 'break' them now) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jorisvandenbossche I have included more explicit tests. |
||
assert df.IntDateOnlyCol.tolist() == [ | ||
pd.Timestamp('2010-10-10'), | ||
pd.Timestamp('2010-12-12') | ||
] | ||
|
||
def test_date_and_index(self): | ||
# Test case where same column appears in parse_date and index_col | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are using a different quoting here, that's probably the reason for the failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll fix it.