-
Notifications
You must be signed in to change notification settings - Fork 42
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
a bug of ValueError happened when using TableOne(data) #62
Comments
hi @Yuyoo, thanks for highlighting this issue. Please could you provide code to reproduce the problem? In Python 3, the following code returns the expected "duplicate columns" error for me: # load sample data into a pandas dataframe
url="https://raw.githubusercontent.com/tompollard/tableone/master/data/pn2012_demo.csv"
data=pd.read_csv(url)
# create duplicate columns
data = data.rename(index=str, columns={"MechVent": "Height", "Weight": "Height",
"SysABP":"Age", "ICU":"Age"})
# create table
overall_table = TableOne(data) raises the expected error:
Your suggested fix returns an error: columns = data.columns.get_values()
data[columns].columns.get_duplicates().values.size
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-18-adf1753aef69> in <module>()
----> 1 data[columns].columns.get_duplicates().values.size
AttributeError: 'list' object has no attribute 'values' |
The bug happened as: |
Okay, got it, thanks @Yuyoo. I now get this error after upgrading to pandas '0.23.0' (from '0.22.0'). |
Yeah, it will update pandas defaultly when pip install --upgrade tableone. I didnt get the error when i use the old version of tableone. |
Yeah, bad timing because we just published a paper about the package! We'll get the issues fixed as soon as possible. This particular bug is fixed with:
We'll work on the other issues shortly. Thanks again for raising this :) |
Haha, its no problem, everything will be ok. You have done a good job, its convenient for us to do research. Best wish to you! |
The following line also raises an error in Pandas 0.2.3: grouped_data = pd.crosstab(data[self._groupby],data[v])
ValueError: Duplicated level name: "death",
assigned to level 1, is already used for level 0. The error is raised when the Odd, because it looks like this was fixed as a bug in Pandas at some point in the past: |
Fixed in version 0.5.7. Thanks again :) |
Hi,Tom and Alistair. Long time no see since Datathon in BeiJing in 2017. How have you been doing?
I found a bug in tableone.py in the lastest version 0.5.6.
Because of the difference of condition judgment in py2/py3, there is a bug in tableone.py in line 96. The bug can cause the error when using TableOne(data).
In line 96, "data[columns].columns.get_duplicates()" returns "Index([], dtype='object')". In py3, Index([], dtype='object') could not be solved as False, and would throw a ValueError: The truth value of a Index is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). I have test it in py2, and it works well.
I suggest that we can fix it by change "data[columns].columns.get_duplicates()" to "data[columns].columns.get_duplicates().values.size", or you can solved it in other way.
The text was updated successfully, but these errors were encountered: