You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PythonParser produces an invalid result when using a combination of options. It does not convert the comma correctly when the options 'usecols' and 'decimal' are used. The C engine does produce a correct result.
bashtage
changed the title
BUG: PythonParser does not convert decimals when usecols and parse_date are specified as well
BUG: PythonParser does respect decimal separator usecols and parse_date are specified as well
Aug 24, 2020
Decimal is not ignored, otherwise the example below should not work.
Either 'engine', 'usecols', 'parse_dates' can be commented out, and both Series dtypes will be float64.
Very strange behaviour..
importpandasaspdimportiodata=io.StringIO('"dump","-9,1","-9,1",20101010')
python_engine=pd.read_csv(
data,
engine="python", # Comment out and both are float64names= ['col', 'col1', 'col2', 'col3'],
usecols= ['col1', 'col2', 'col3'], # Comment out and both are float64parse_dates= ["col3"], # Comment out and both are float64decimal=",",
)
print(python_engine['col1'].dtype) # float64print(python_engine['col2'].dtype) # object
bashtage
changed the title
BUG: PythonParser does respect decimal separator usecols and parse_date are specified as well
BUG: PythonParser does not use decimal separator when usecols and parse_date are specified
Aug 24, 2020
When decimal="," then "9.1" should be a string (object) while "9,1" should be a float. In the testing I did above, it seemed like "9.1" was being converted to float even when decimal=",".
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Repl: https://repl.it/repls/TiredLightcyanNetworking#main.py
Problem description
The PythonParser produces an invalid result when using a combination of options. It does not convert the comma correctly when the options 'usecols' and 'decimal' are used. The C engine does produce a correct result.
It seems that this check is wrong, the columns are shifted:
https://github.com/pandas-dev/pandas/blob/v1.1.1/pandas/io/parsers.py#L3089
The columns specified in that list are adjusted for the 'usecols' option (so shifted by 1 in the example), while the read line still has all columns.
Expected Output
Expect that decimals are correctly converted for all columns. However, the python engine does not when there are columns specified for date parsing.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : f2ca0a2
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-1019-gcp
Version : #19-Ubuntu SMP Tue Jun 23 15:46:40 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.1
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.0
sqlalchemy : 1.3.17
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: