IndexError in Python 3.2

Issue #104 resolved
Pavel Vondřička created an issue

An error occurring when the function "cqi_list_subcorpora(...)" from the "rcqp" library returns an empty list (vector). The error does not occur if there is a non-empty result.

Python 3.2.3 (default, Sep 10 2012, 18:14:40) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpy2.robjects as R
>>> R.r.library('rcqp')
Loading required package: plyr
The environment variable CORPUS_REGISTRY is not defined.
Using default registry '/usr/local/share/cwb/registry'.
See ?cqp_registry for more info on how to set the registry.
<StrVector - Python:0x7f2edb2f51b8 / R:0x1616c08>
['rcqp', 'plyr', 'stats', ..., 'data..., 'meth..., 'base']
>>> R.r.cqi_list_subcorpora('MYCORPUS')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/vectors.py", line 303, in __repr__
    self.__repr_content__()
  File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/vectors.py", line 292, in __repr_content__
    ', '.join((p_str(x, max_width = int(52 / l)) for x in self[ : 8])) +\
  File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/vectors.py", line 217, in __getitem__
    res = super(Vector, self).__getitem__(i)
IndexError: The slice's length can't be < 0.
>>> sclist = R.r.cqi_list_subcorpora('MYCORPUS')
>>> len(sclist)
0
>>> sclist
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/vectors.py", line 303, in __repr__
    self.__repr_content__()
  File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/vectors.py", line 292, in __repr_content__
    ', '.join((p_str(x, max_width = int(52 / l)) for x in self[ : 8])) +\
  File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/vectors.py", line 217, in __getitem__
    res = super(Vector, self).__getitem__(i)
IndexError: The slice's length can't be < 0.

Comments (7)

  1. Pavel Vondřička reporter

    Actually, I can reproduce the problem simply by calling: R.r('empty <- vector()')

  2. Laurent Gautier

    The report refers to rpy2-2.2.3. The latest in the 2.2.x series is 2.2.7. I tested on the almost-here release 2.3.0 (currently 2.3.0alpha1) and it is working fine here.

    Python 3.3.0 (default, Oct  1 2012, 15:24:18) 
    [GCC 4.6.3] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from rpy2.robjects import r
    >>> x = r('empty <- vector()')
    >>> import rpy2
    >>> rpy2.__version__
    '2.3.0alpha1'
    
  3. Pavel Vondřička reporter

    Reproduce easilly even in Python 3.3:

    Python 3.3.0 (default, Sep 29 2012, 17:14:58) 
    [GCC 4.7.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import rpy2
    >>> rpy2.__version__
    '2.3.0alpha1'
    >>> from rpy2.robjects import r
    >>> r('vector()')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.3/dist-packages/rpy2/robjects/vectors.py", line 307, in __repr__
        self.__repr_content__()
      File "/usr/local/lib/python3.3/dist-packages/rpy2/robjects/vectors.py", line 296, in __repr_content__
        ', '.join((p_str(x, max_width = 52 / l) for x in self[ : 8])) +\
      File "/usr/local/lib/python3.3/dist-packages/rpy2/robjects/vectors.py", line 221, in __getitem__
        res = super(Vector, self).__getitem__(i)
    IndexError: The slice's length can't be < 0.
    
  4. Log in to comment