Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

slicing with multiple timestamps #1587

Closed
jgarcke opened this Issue · 1 comment

2 participants

Jochen Chang She
Jochen

I have a problem for time series with multiple time stamps.
This is the data file:
06/01/04 10:11:46 1.2735 1.2737
06/01/04 10:11:47 1.2735 1.2737
06/01/04 10:11:48 1.2736 1.2738
06/01/04 10:11:50 1.2736 1.2738
06/01/04 10:11:50 1.2735 1.2737

raw_data = read_csv('bug_data',header=None, parse_dates=[[0,1]], sep=' ', index_col=0, dayfirst=True)
oldest=raw_data.index[-1]

then:
raw_data[:oldest]
fails with TypeError: unsupported operand type(s) for +: 'slice' and 'int'
as does
raw_data.ix[:oldest]

raw_data[oldest:]
does work, whereas
raw_data.ix[oldest:]
fails with IndexError: invalid slice

Cutting out the last entry things work again, e.g.
raw_data[:-1].ix[oldest:]
raw_data[:-1].ix[:oldest]
or
raw_data[:-1][oldest:]
raw_data[:-1][:oldest]

a (or the ?) get_slice-routines return a slice in these cases.

get_loc gives back a slice when there are non-unique indexes, not sure if
that routine(s) should be fixed or slice_locs

my workaround (?) is catching this in slice_loc but I guess the get_loc's should be fixed instead
--- /home/jgarcke/Prog/Packages/pandas-git/pandas/core/index.py

2012-06-26 14:10:12.107724998 +0200
+++ index.py 2012-06-26 16:47:19.917653332 +0200
@@ -1039,7 +1039,11 @@
beg_slice = 0
else:
try:

  • beg_slice = self.get_loc(start)
  • if isinstance(self.get_loc(start), slice):
  • beg_slice = self.get_loc(start).start
  • else:
  • beg_slice = self.get_loc(start) except KeyError: if self.is_monotonic: beg_slice = self.searchsorted(start, side='left') @@ -1050,7 +1054,11 @@ end_slice = len(self) else: try:
  • end_slice = self.get_loc(end) + 1
  • if isinstance(self.get_loc(end), slice):
  • end_slice = self.get_loc(end).stop + 1
  • else:
  • end_slice = self.get_loc(end) + 1 except KeyError: if self.is_monotonic: end_slice = self.searchsorted(end, side='right')
Chang She changhiskhan was assigned
Chang She changhiskhan referenced this issue from a commit
Chang She BUG: slicing with dups #1587 e2633d4
Chang She
Collaborator

get_loc needs to be able to return non-integer values for dups. I changed slice_loc so it checks whether get_loc returns a slice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.