GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Slicing a Python list converted from Java fails · Issue #24 · scijava/scyjava

Slicing a Python list converted from Java fails #24

New issue
Copy link
New issue
Copy link
Open
#94
Open
Slicing a Python list converted from Java fails#24
#94
Copy link

Description

@ctrueden
ctrueden
opened on Feb 5, 2021
Issue body actions
>>> jl = ArrayList([1, 3, 5, 7, 9])
>>> jl.toString()
'[1, 3, 5, 7, 9]'
>>> pl = scyjava.to_python(jl)
>>> type(pl)
<class 'scyjava.JavaList'>
>>> print(pl)
[1, 3, 5, 7, 9]
>>> pl[:]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/curtis/miniconda3/envs/i2k-2020-pyimagej/lib/python3.8/site-packages/scyjava/__init__.py", line 330, in __getitem__
    return to_python(self.jobj.get(key), gentle=True)
TypeError: No matching overloads found for java.util.ArrayList.get(slice), options are:
	public java.lang.Object java.util.ArrayList.get(int)

Activity

  1. imagejan commented on Feb 19, 2021

    @imagejan
    imagejan
    on Feb 19, 2021
    Member
    More actions

    Interestingly, the following both work:

    >>> jl[:]
    <java object 'java.util.ArrayList.SubList'>
    >>> print(jl[:])
    [1, 3, 5, 7, 9]
    >>> nl = list(pl)
    >>> nl[:]
    [1, 3, 5, 7, 9]
    Reacted by Curtis Rueden
  2. imagejan commented on Feb 19, 2021

    @imagejan
    imagejan
    on Feb 19, 2021
    Member
    More actions

    Probably would require copying the slice logic from here:

    https://github.com/jpype-project/jpype/blob/8a32c42373ca10e0aa587d5fab0065dab52f94c6/jpype/_jcollection.py#L89-L96

    @ctrueden what's the reason we still have JavaCollection, JavaList etc. in scyjava? Is there additional functionality to what JPype brings?

  3. ctrueden commented on Feb 19, 2021

    @ctrueden
    ctrueden
    on Feb 19, 2021
    MemberAuthor
    More actions

    what's the reason we still have JavaCollection, JavaList etc. in scyjava? Is there additional functionality to what JPype brings?

    Lack of testing, and maintenance of the status quo. I'd be happy to get rid of them if we beef up unit tests to prove that JPype is strictly better. Or if we find advantages to keeping them, perhaps they could be slimmed down to extend some JPype data structures where feasible.

    Reacted by Jan Eglinger
  4. Thrameos commented on Feb 19, 2021

    @Thrameos
    Thrameos
    on Feb 19, 2021
    More actions

    JPype collections should be fully supporting of Python collections API or at least as much as it is possible using Java's available functions. You can add additional functionality through customizers like the ones in _jcollection.

    For example, if you wish to add a toPython() method to String[] which returns a "list of str" just define the function in a class and add the JImplementationFor decorator so it monkey patches it in. I don't generally add anything beyond the minimum to satisfy the Python contracts, but jpype does support multiple user installed customizer to any Java type so long as there are no implementation conflicts. In some projects I have "jdouble[]" overloaded with math operations.

    Reacted by Jan Eglinger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.