rrcf icon indicating copy to clipboard operation
rrcf copied to clipboard

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

Open shaye059 opened this issue 3 years ago • 0 comments

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

shaye059 avatar Mar 01 '21 15:03 shaye059