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

KeyError: 'columns' #59

Closed
leichtle opened this issue May 5, 2020 · 4 comments
Closed

KeyError: 'columns' #59

leichtle opened this issue May 5, 2020 · 4 comments

Comments

@leichtle
Copy link

leichtle commented May 5, 2020

Dear Eshin Jolly,
Running pymer4 on OS X with python 3.8.2, pandas 1.0.3, and rpy2 3.3.2 as well as R 4.0.0, lme4_1.1-23, and lmerTest_3.1-2, I can execute the linear modeling example without error:

# Import the linear regression model class
from pymer4.models import Lm

# Initialize model using 2 predictors and sample data
model = Lm('DV ~ IV1 + IV2', data=df)

# Fit it
print(model.fit())

However, the multilevel model throws an error:

# Import the lmm model class
from pymer4.models import Lmer

# Initialize model instance using 1 predictor with random intercepts and slopes
model = Lmer('DV ~ IV2 + (IV2|Group)', data=df)

# Fit it
print(model.fit())

This is the error message:

KeyError                                  Traceback (most recent call last)
~/python/lib/python3.8/site-packages/numpy/core/records.py in __getattribute__(self, attr)
    463         try:
--> 464             res = fielddict[attr][:2]
    465         except (TypeError, KeyError):

KeyError: 'columns'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
~/python/lib/python3.8/site-packages/pymer4/models/Lmer.py in fit(self, conf_int, n_boot, factors, permute, ordered, summarize, verbose, REML, rank, rank_group, rank_exclude_cols, no_warnings, control, old_optimizer)
    403         try:
--> 404             self._get_ngrps()
    405         except AttributeError:

~/python/lib/python3.8/site-packages/pymer4/models/Lmer.py in _get_ngrps(self)
    228         res = get_ngrps(self.model_obj)
--> 229         if len(res.columns) != 1:
    230             raise Exception("Appears there's been another rpy2 or lme4 api change.")

~/python/lib/python3.8/site-packages/numpy/core/records.py in __getattribute__(self, attr)
    465         except (TypeError, KeyError):
--> 466             raise AttributeError("recarray has no attribute %s" % attr)
    467         obj = self.getfield(*res)

AttributeError: recarray has no attribute columns

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-30-59a6b50189ce> in <module>
      6 
      7 # Fit it
----> 8 print(model.fit())

~/python/lib/python3.8/site-packages/pymer4/models/Lmer.py in fit(self, conf_int, n_boot, factors, permute, ordered, summarize, verbose, REML, rank, rank_group, rank_exclude_cols, no_warnings, control, old_optimizer)
    404             self._get_ngrps()
    405         except AttributeError:
--> 406             raise Exception(
    407                 "You appear to have an old version of rpy2, upgrade to >3.0"
    408             )

Exception: You appear to have an old version of rpy2, upgrade to >3.0

Seems to me like a rpy2 version issue, maybe something for an updated pymer4 version.
Kind regards, Alex

@ejolly
Copy link
Owner

ejolly commented May 6, 2020

Yea sorry there are some compatibility issues with recent versions of rpy2 and pandas noted in #58 and #57. I haven't gotten a chance to work through them yet, but in the mean time you can trying using rpy2==3.2.4 and see if that works for you.

I also haven't tested this on the latest version of R so I can't guarantee it'll work on R >= 4.0

@ejolly
Copy link
Owner

ejolly commented May 6, 2020

@leichtle You can also try installing from the compatibility_fixes branch to see if that solves this particular issue. I think it should, but it may generate other ones since it's a WIP.

pip install git+https://github.com/ejolly/pymer4.git@compatibility_fixes

@ejolly
Copy link
Owner

ejolly commented Jun 24, 2020

Bug fixes

@ejolly
Copy link
Owner

ejolly commented Jun 24, 2020

Should not be an issue on upcoming releases, but add a slightly more informative error message

@ejolly ejolly closed this as completed Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants