0

Pandas version: 0.20.1

I have some intervals

>print(periods)
IntervalIndex([(1459486800000000000, 1459490400000000000], (1459503000000000000, 1459506600000000000], (1459521000000000000, 1459524600000000000], (1459540800000000000, 1459544400000000000], (1459573200000000000, 1459576800000000000] ... (1475164800000000000, 1475168400000000000], (1475215860000000000, 1475219460000000000], (1475219460000000000, 1475223060000000000], (1475229660000000000, 1475233260000000000], (1475240400000000000, 1475244000000000000]]
              closed='right',
              dtype='interval[int64]')

I also have a df with a Start

print(df.head(3)['Start'].astype(np.int64))

1    1463725423954004000
2    1463725440994005000
5    1463732892934001000

I would like to use pd.cut on these periods. I have tried

 df['val'] = pd.cut(df['Start'].astype(np.int64), bins=periods)

But it get the following
    //python2.7/site-packages/pandas/core/indexes/interval.pyc in get_loc(self, key, method)
    705                 return self._engine.get_loc_interval(left, right)
    706             else:
--> 707                 return self._engine.get_loc(key)
    708 
    709     def get_value(self, series, key):

pandas/_libs/intervaltree.pxi in pandas._libs.interval.IntervalTree.get_loc (pandas/_libs/interval.c:9756)()

KeyError: 1463725423954004000

I can't figure out why I get this, after reading documentation

00__00__00
  • 4,834
  • 9
  • 41
  • 89
  • Please post a reproducible example; see [How to make good reproducible pandas examples](https://stackoverflow.com/a/20159305/3339965) – root Nov 28 '18 at 18:05
  • Also try upgrading to the latest version of pandas; 0.20.1 is quite old, and `IntervalIndex` is quite new (first released in 0.20.0), so many bug fixes and improvements have been made since. – root Nov 28 '18 at 18:08
  • why is this not reproducible? – 00__00__00 Nov 28 '18 at 19:17
  • The exact content of `periods` is unknown; note the "..." in the string representation. None of the intervals shown contain the value for which you're getting the `KeyError`. All of the data you provide needs to be copy/pasteable in their entirety. – root Nov 28 '18 at 19:22
  • ok will do, please do not downote – 00__00__00 Nov 28 '18 at 19:32
  • we can close it if you know it is a version bug – 00__00__00 Nov 28 '18 at 19:33
  • No worries! I'm not sure if it's a known bug that's been fixed, or an unknown bug that hasn't been reported yet. – root Nov 28 '18 at 19:40

0 Answers0