ndexbio / ndex2-client

NDEx2 Client
BSD 3-Clause "New" or "Revised" License
6 stars 6 forks source link

Empty list attributes are treated as strings when converting networkx to NiceCXNetwork #90

Closed coleslaw481 closed 2 years ago

coleslaw481 commented 2 years ago

When using the method: ndex2.create_nice_cx_from_networkx() empty list attributes are sometimes treated as strings. This was tested with networkx version 2.5.1

import json
import ndex2
import networkx as nx

#Create a networkx graph with a boolean attribute
G = nx.Graph()
G.add_node(1, emptylist=[])
nx.get_node_attributes(G, 'emptylist')

print(json.dumps(ndex2.create_nice_cx_from_networkx(G).to_cx(), indent=2))

When run got this output:

{1: []}
Generating CX
[
  {
    "numberVerification": [
      {
        "longNumber": 281474976710655
      }
    ]
  },
  {
    "metaData": [
      {
        "name": "nodes",
        "elementCount": 1,
        "idCounter": 1,
        "version": "1.0",
        "consistencyGroup": 1,
        "properties": []
      },
      {
        "name": "nodeAttributes",
        "elementCount": 1,
        "idCounter": 1,
        "version": "1.0",
        "consistencyGroup": 1,
        "properties": []
      }
    ]
  },
  {
    "nodes": [
      {
        "@id": 1,
        "n": 1
      }
    ]
  },
  {
    "nodeAttributes": [
      {
        "po": 1,
        "n": "emptylist",
        "v": [],
        "d": "string"
      }
    ]
  },
  {
    "status": [
      {
        "error": "",
        "success": true
      }
    ]
  }
]

The data type d for the nodeAttribute should be a list_of_string and NOT an string

coleslaw481 commented 2 years ago

Fixed with commit: To github.com:ndexbio/ndex2-client.git 5c899e5..1a6873e v3.5.0 -> v3.5.0