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

Issue with DataFrame - TypeError: '(slice(None, None, None), 24)' is an invalid key #87

Open
shaye059 opened this issue Mar 1, 2021 · 0 comments

Comments

@shaye059
Copy link

shaye059 commented Mar 1, 2021

I've tried building a tree from a pandas DataFrame using the following line:
tree = rrcf.RCTree(data_anom.sample(1000, random_state=111))

But it results in a TypeError. It works when I convert it to a NumPy array
tree = rrcf.RCTree(data_anom.sample(1000, random_state=111).to_numpy())
so is this just a matter of DataFrames not being supported or is there something in my DataFrame causing the issue?

Full error output:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-57-af57d97a258a> in <module>
----> 1 tree = rrcf.RCTree(data_anom.sample(1000, random_state=111))

~\anaconda3\envs\squarefeetenv\lib\site-packages\rrcf\rrcf.py in __init__(self, X, index_labels, precision, random_state)
    104             # Create RRC Tree
    105             S = np.ones(n, dtype=np.bool)
--> 106             self._mktree(X, S, N, I, parent=self)
    107             # Remove parent of root
    108             self.root.u = None

~\anaconda3\envs\squarefeetenv\lib\site-packages\rrcf\rrcf.py in _mktree(self, X, S, N, I, parent, side, depth)
    170         depth += 1
    171         # Create a cut according to definition 1
--> 172         S1, S2, branch = self._cut(X, S, parent=parent, side=side)
    173         # If S1 does not contain an isolated point...
    174         if S1.sum() > 1:

~\anaconda3\envs\squarefeetenv\lib\site-packages\rrcf\rrcf.py in _cut(self, X, S, parent, side)
    156         p = self.rng.uniform(xmin[q], xmax[q])
    157         # Determine subset of points to left
--> 158         S1 = (X[:, q] <= p) & (S)
    159         # Determine subset of points to right
    160         S2 = (~S1) & (S)

~\AppData\Roaming\Python\Python38\site-packages\pandas\core\frame.py in __getitem__(self, key)
   2904             if self.columns.nlevels > 1:
   2905                 return self._getitem_multilevel(key)
-> 2906             indexer = self.columns.get_loc(key)
   2907             if is_integer(indexer):
   2908                 indexer = [indexer]

~\AppData\Roaming\Python\Python38\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), 24)' is an invalid key
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

1 participant