Skip to content

slicing with multiple timestamps #1587

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

Closed
jgarcke opened this issue Jul 9, 2012 · 1 comment
Closed

slicing with multiple timestamps #1587

jgarcke opened this issue Jul 9, 2012 · 1 comment
Labels
Milestone

Comments

@jgarcke
Copy link

jgarcke commented Jul 9, 2012

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') 
    
@ghost ghost assigned changhiskhan Jul 13, 2012
changhiskhan pushed a commit that referenced this issue Jul 13, 2012
@changhiskhan
Copy link
Contributor

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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants