-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Strange behaviour of delim_whitespace
in pd.read_table
#36381
Comments
delim_whitespace=True does not work pandas-dev/pandas#36381
sep is defaulted to , |
@jreback |
@jreback this issue should be re-opened. The issue is that Lines 694 to 705 in 8f6ec1e
vs Lines 603 to 615 in 8f6ec1e
import pandas as pd
with open('/tmp/test.dat', 'w') as fout:
for j in range(5):
fout.write(f'{j} {j*2} {j**2}\n')
pd.read_table('/tmp/test.dat', delim_whitespace=True) This probably has to be done with a proper sentinel object? |
duplicate of #35958 and fixed by https://github.com/pandas-dev/pandas/pull/36560/files |
So we want to override the default of a keyword argument from another function. If I understand it correctly we have to carry two meanings with our sentinel object:
One possibility is: class Optional:
def __init__(self, val):
self.val = val
def __bool__(self):
return False
def __repr__(self):
return f'Optional "{self.val}"'
def read_csv(sep=Optional(','), delimiter=None, delim_whitespace=False):
if sum(bool(x) for x in (sep, delimiter, delim_whitespace)) > 1:
raise ValueError(
"Specified a delimiter with two of {sep, delimiter, or delim_whitespace}"
"while only one or zero allowed.")
if any([sep, delimiter]):
delimiter = delimiter if delimiter else sep
elif delim_whitespace:
delimiter = '\S+'
else:
delimiter = sep.val
return delimiter, delim_whitespace
def read_table(sep=Optional('\t'), delimiter=None, delim_whitespace=False):
return read_csv(**locals()) I would be interested in fixing, but I guess the decision on which sentinel object to choose is an important API decision, which should be done by you. |
@tacaswell
will not throw an error, although it should if I read the documentation correctly? |
we use lib.no_default as a sentinel |
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
Problem description
Expected Output
Parsed dataframe.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2a7d332
python : 3.6.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.12.14-lp151.28.67-default
Version : #1 SMP Fri Sep 4 15:23:21 UTC 2020 (2c5a14f)
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.2
numpy : 1.17.3
pytz : 2018.5
dateutil : 2.7.3
pip : 19.3.1
setuptools : 40.5.0
Cython : 0.27.3
pytest : None
hypothesis : None
sphinx : 1.7.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.0.0
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.4.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 2.0.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.2.0
sqlalchemy : 1.2.14
tables : None
tabulate : 0.8.5
xarray : None
xlrd : None
xlwt : None
numba : 0.48.0
The text was updated successfully, but these errors were encountered: