Skip to content

Fix id_neighbours serializing as np.int64 instead of plain int in CSV output#156

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-id-neighbours-integer-type
Draft

Fix id_neighbours serializing as np.int64 instead of plain int in CSV output#156
Copilot wants to merge 2 commits intomainfrom
copilot/fix-id-neighbours-integer-type

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 10, 2026

graph.neighbors() (scikit-image RAG / networkx) yields np.int64 values, which were stored directly into id_neighbours. When serialized to CSV, this produced unreadable output like [np.int64(31), np.int64(552), ...] instead of [31, 552, ...].

Changes

  • src/epitools/analysis/cell_statistics.py — In _calculate_graph_statistics(), convert each neighbour ID to a plain Python int at collection time; also simplifies the conditional append with a ternary:

    # Before
    id_neighbours.append(list(graph.neighbors(index)))
    
    # After
    new_id_neighbours = [int(n) for n in graph.neighbors(index)]
    id_neighbours.append(new_id_neighbours if new_id_neighbours else None)
  • tests/test_cell_statistics.py — Adds test_id_neighbours_contains_plain_ints to assert type(n) is int for every value in every id_neighbours list, guarding against regressions from future scikit-image/networkx version changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>id neighbours showing integer tpe</issue_title>
<issue_description>Describe the bug
the cell stats in epitools works but now there is some text appended to the neighbours, I think this issue comes from regionprops as I have encountered it before in some versions/envs

label                                      id_neighbours  frame
15       49  [np.int64(31), np.int64(552), np.int64(209), n...      0
21       73  [np.int64(246), np.int64(212), np.int64(61), n...      0

** What we need **
We need a csv file with plain numbers</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix id neighbours showing integer type in CSV Fix id_neighbours serializing as np.int64 instead of plain int in CSV output Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id neighbours showing integer tpe

2 participants