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

Gumbel Copula Error #270

Open
siddharthfcb opened this issue Sep 3, 2021 · 2 comments
Open

Gumbel Copula Error #270

siddharthfcb opened this issue Sep 3, 2021 · 2 comments
Labels
bug There is an error in the code that needs to be fixed

Comments

@siddharthfcb
Copy link

Environment Details

Please indicate the following details about the environment in which you found the bug:

  • Copulas version: 0.5.1
  • Python version: 3.8.5
  • Operating System: MacOS

Error Description

Is the Gumbel copula meant to be for fitting?The following code gives an error

Steps to reproduce

from copulas.datasets import sample_bivariate_age_income
data = sample_bivariate_age_income()
data.head()
from copulas.bivariate import Gumbel
dist=Gumbel()
dist.fit(data)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-a3e24cdf02c2> in <module>
      4 from copulas.bivariate import Gumbel
      5 dist=Gumbel()
----> 6 dist.fit(data)

~/opt/anaconda3/lib/python3.8/site-packages/copulas/bivariate/base.py in fit(self, X)
    174             None
    175         """
--> 176         U, V = split_matrix(X)
    177         self.check_marginal(U)
    178         self.check_marginal(V)

~/opt/anaconda3/lib/python3.8/site-packages/copulas/bivariate/utils.py in split_matrix(X)
     13     """
     14     if len(X):
---> 15         return X[:, 0], X[:, 1]
     16 
     17     return np.array([]), np.array([])

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2900             if self.columns.nlevels > 1:
   2901                 return self._getitem_multilevel(key)
-> 2902             indexer = self.columns.get_loc(key)
   2903             if is_integer(indexer):
   2904                 indexer = [indexer]

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2893             casted_key = self._maybe_cast_indexer(key)
   2894             try:
-> 2895                 return self._engine.get_loc(casted_key)
   2896             except KeyError as err:
   2897                 raise KeyError(key) from err

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

TypeError: '(slice(None, None, None), 0)' is an invalid key
@siddharthfcb siddharthfcb added the bug There is an error in the code that needs to be fixed label Sep 3, 2021
@jmdc-mkojima
Copy link

@siddharthfcb
Hello. I've got the same problem and found an ad-hoc approach to solve it. Hope this would be helpful.

The issue seems to arise due to an invalid slice manipulation to pandas objects, i.e., X[:, 0] is not allowed when X is a pandas object. So, a quick fix is to replace the code with X.iloc[:, 0] but this is not enough because X can be a numpy object when using some other functions such as sample().

So, replacing the code in utils.py with the following could be a quick fix:
if len(X): if 'iloc' in dir(X): return X.iloc[:, 0], X.iloc[:, 1] else: return X[:, 0], X[:, 1]

@LSRathore
Copy link

@siddharthfcb Hello. I've got the same problem and found an ad-hoc approach to solve it. Hope this would be helpful.

The issue seems to arise due to an invalid slice manipulation to pandas objects, i.e., X[:, 0] is not allowed when X is a pandas object. So, a quick fix is to replace the code with X.iloc[:, 0] but this is not enough because X can be a numpy object when using some other functions such as sample().

So, replacing the code in utils.py with the following could be a quick fix: if len(X): if 'iloc' in dir(X): return X.iloc[:, 0], X.iloc[:, 1] else: return X[:, 0], X[:, 1]

It does not work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is an error in the code that needs to be fixed
Projects
None yet
Development

No branches or pull requests

3 participants