-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Failing to parse date given as integers from a (MS)SQL query #17855
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
Comments
w/o a reproducible example you would have to debug this and see where things are going wrong.
|
Here's a reproducible example: import sqlalchemy
import pymysql
import pandas as pd
eng = sqlalchemy.create_engine('mysql+pymysql://sql2199180:kI1*yG4%@sql2.freemysqlhosting.net/sql2199180')
con = eng.connect()
pd.read_sql('select d from foo', con) # Works
pd.read_sql('select d from foo', con, parse_dates={'d': '%Y%m%d'}) # Fails
pd.read_sql('select CONVERT(d, CHAR(10)) as d from foo', con, parse_dates={'d': '%Y%m%d'}) # Works |
So this is the current code to handle the Lines 102 to 119 in c277cd7
where it explicitly checks for numeric column, and then passes I agree this is a bit inconvenient. An easy fix could also be to check whether '%' is contained in the format string, and in that case not pass it to @drorata Would you like to do a PR? |
I am missing something. Why |
@jorisvandenbossche I just tried to run the test suite (
```
../../anaconda3/envs/pandas_dev/lib/python3.6/site-packages/_pytest/config.py:342: in _getconftestmodules
return self._path2confmods[path]
E KeyError: local('/Users/username/Dropbox/dev/pandas/pandas')
During handling of the above exception, another exception occurred: During handling of the above exception, another exception occurred: During handling of the above exception, another exception occurred:
|
@drorata I suppose the test problem is solved in the meantime since you opened a PR? If not, from a quick look it seems to me you need to rebuild the pandas C-extensions locally (see http://pandas.pydata.org/pandas-docs/stable/contributing.html#making-changes) |
Code Sample
The underlaying database is MSSQL and I'm using
pymssql
to build the connectioncon
.Problem description
The column
submitted_date_id
has integers representing the dateYYYYMMDD
. The code above is expected to parse the column and populate the resulting column in the dataframe withTimestamp
objects. However, this code yields an error:The current behavior is counter intuitive and seems to assume that the date column contains stings. A work around is to cast the column in the query to
VARCHAR
, but this is cumbersome. Moreover, it adds unneeded complexity to the query.Expected Output
When providing the format of the dates to
parse_dates
, it is expected that the column will hold Timestamp objects.Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.2.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.20.3
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.3.0
Cython: None
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 6.2.0
sphinx: 1.6.4
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: