Skip to content
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

ttest() TypeError: object of type 'int' has no len() #227

Closed
Tracked by #236
benpla opened this issue Jan 24, 2022 · 4 comments
Closed
Tracked by #236

ttest() TypeError: object of type 'int' has no len() #227

benpla opened this issue Jan 24, 2022 · 4 comments
Assignees
Labels
bug 💥 Something isn't working URGENT ⚠️ To fix ASAP

Comments

@benpla
Copy link

benpla commented Jan 24, 2022

The first sample code fails with:

Code:

from pingouin import ttest
x = [5.5, 2.4, 6.8, 9.6, 4.2]
ttest(x, 4).round(2)

Every try for ttest farls with the same wessage.
Avova works as expected.
I enter code as simple as possible, but I can not understand the error message.

I uninstalled pingouin using conda remove pingouin.
Then installation with pip. Same result.
I installed an older version (conda install -c conda-forge/label/cf202003 pingouin).
Same result.

What can be the reason for this?

Here is my output:

(py39v1) bp@bplattemac ~ % python
Python 3.9.7 (default, Sep 16 2021, 08:50:36) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pingouin import ttest
>>> x = [5.5, 2.4, 6.8, 9.6, 4.2]
>>> ttest(x, 4).round(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bp/opt/anaconda3/envs/py39v1/lib/python3.9/site-packages/pingouin/parametric.py", line 309, in ttest
    stats = pd.DataFrame.from_records(stats, columns=col_order, index=['T-test'])
  File "/Users/bp/opt/anaconda3/envs/py39v1/lib/python3.9/site-packages/pandas/core/frame.py", line 2215, in from_records
    arrays, arr_columns, result_index = maybe_reorder(
  File "/Users/bp/opt/anaconda3/envs/py39v1/lib/python3.9/site-packages/pandas/core/frame.py", line 2165, in maybe_reorder
    length = len(arrays[0])
TypeError: object of type 'int' has no len()
>>> 
@Pofozaur
Copy link

same issue here

>>> import numpy as np
>>> import pingouin as pg
>>> np.random.seed(123)
>>> mean, cov, n = [4, 5], [(1, .6), (.6, 1)], 30
>>> x, y = np.random.multivariate_normal(mean, cov, n).T
>>> pg.ttest(x, y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kamil/test/venv/lib/python3.8/site-packages/pingouin/parametric.py", line 309, in ttest
    stats = pd.DataFrame.from_records(stats, columns=col_order, index=['T-test'])
  File "/home/kamil/test/venv/lib/python3.8/site-packages/pandas/core/frame.py", line 2215, in from_records
    arrays, arr_columns, result_index = maybe_reorder(
  File "/home/kamil/test/venv/lib/python3.8/site-packages/pandas/core/frame.py", line 2165, in maybe_reorder
    length = len(arrays[0])
TypeError: object of type 'int' has no len()
>>>
Python 3.8.10

Package            Version  
------------------ ---------
certifi            2021.10.8
charset-normalizer 2.0.10   
cycler             0.11.0   
fonttools          4.28.5   
idna               3.3      
joblib             1.1.0    
kiwisolver         1.3.2    
littleutils        0.2.2    
matplotlib         3.5.1    
numpy              1.22.1   
outdated           0.2.1    
packaging          21.3     
pandas             1.4.0    
pandas-flavor      0.2.0    
patsy              0.5.2    
Pillow             9.0.0    
pingouin           0.5.0    
pip                20.0.2   
pkg-resources      0.0.0    
pyparsing          3.0.7    
python-dateutil    2.8.2    
pytz               2021.3   
requests           2.27.1   
scikit-learn       1.0.2    
scipy              1.7.3    
seaborn            0.11.2   
setuptools         44.0.0   
six                1.16.0   
statsmodels        0.13.1   
tabulate           0.8.9    
threadpoolctl      3.0.0    
urllib3            1.26.8   
xarray             0.20.2

@Pofozaur
Copy link

it's looks like issue with numpy or pandas

@benpla if you want quickfix for this problem, install numpy==1.21.5 and pandas==1.3.5 before installing pingouin

@benpla
Copy link
Author

benpla commented Jan 25, 2022

@Pofozaur : Your suggestion did the trick!

First remove packages:

conda remove pingouin, numpy, pandas

Which Versions are installable?

conda search --override-channels --channel conda-forge numpy
conda search --override-channels --channel conda-forge pandas

On conda-forge channel the suggested versions are available.
Now install:

conda install -c conda-forge numpy=1.21.5
conda install -c conda-forge pandas=1.3.5
conda install -c conda-forge pingouin

Run python with test().... and voila: it works!
Thanks!

@raphaelvallat raphaelvallat added the bug 💥 Something isn't working label Jan 25, 2022
@raphaelvallat raphaelvallat self-assigned this Jan 25, 2022
@raphaelvallat
Copy link
Owner

Hi,

Thanks for opening the issue. The error is related to the latest release of Pandas (1.4.0), which leads to an error here:

stats = pd.DataFrame.from_records(stats, columns=col_order, index=['T-test'])

A simple fix is to replace the above line with:

stats = pd.DataFrame(stats, columns=col_order, index=['T-test'])  # works with pandas 1.4.0

I'll implement this in the next release of Pingouin. In the meantime, a quick fix is to revert to pandas 1.3.5:

pip install pandas==1.3.5

Thanks,
Raphael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 💥 Something isn't working URGENT ⚠️ To fix ASAP
Projects
None yet
Development

No branches or pull requests

3 participants