GithubHelp home page GithubHelp logo

paulhoule / gastrodon Goto Github PK

View Code? Open in Web Editor NEW
131.0 131.0 15.0 2.66 MB

Visualize RDF data in Jupyter with Pandas

License: MIT License

Python 4.74% Jupyter Notebook 93.05% HTML 2.17% Batchfile 0.04%
jupyter pandas rdf rdflib semantic-web sparql

gastrodon's People

Contributors

jhadjar avatar paulhoule avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gastrodon's Issues

Unable to import

On a clean restart:
import gastrodon
produces
Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Program Files\JetBrains\PyCharm Community Edition with Anaconda plugin 2020.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "C:\Users\andyt\anaconda3\envs\Property\lib\site-packages\gastrodon\__init__.py", line 13, in <module> from typing import Dict,GenericMeta,Match ImportError: cannot import name 'GenericMeta' from 'typing' (C:\Users\andyt\anaconda3\envs\Property\lib\typing.py)

running the same in Jupyter gives a little more info:
`ImportError Traceback (most recent call last)
in
----> 1 import gastrodon

~\anaconda3\lib\site-packages\gastrodon_init_.py in
11 from types import FunctionType,LambdaType,GeneratorType,CoroutineType,FrameType,CodeType,MethodType
12 from types import BuiltinFunctionType,BuiltinMethodType,DynamicClassAttribute,ModuleType,AsyncGeneratorType
---> 13 from typing import Dict,GenericMeta,Match
14 from urllib.error import HTTPError
15 from urllib.parse import urlparse

ImportError: cannot import name 'GenericMeta' from 'typing' (C:\Users\andyt\anaconda3\lib\typing.py)`

Problems with column types

After playing around a bit with gastrodon, I think I have bumped into some problems regarding column types. To reproduce:

Preliminaries

from gastrodon import RemoteEndpoint, inline
import pandas as pd

prefixes = inline("""
    @prefix : <http://dbpedia.org/resource/> .
    @prefix dbp: <http://dbpedia.org/ontology/> .
    @prefix pr: <http://dbpedia.org/property/> .
    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
""").graph
endpoint = RemoteEndpoint(
    "http://dbpedia.org/sparql/"
    ,default_graph="http://dbpedia.org"
    ,prefixes=prefixes
    ,base_uri="http://dbpedia.org/resource/"
)

Error with dates

endpoint.select("""
SELECT DISTINCT ?personName ?bDay
WHERE {
    ?person a dbp:Person .
    ?person foaf:name ?nombrePersona .
    ?person dbp:birthDate ?bDay .
    }
    LIMIT 10
""")

Output:

Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
  File "/opt/conda/lib/python3.6/site-packages/gastrodon/__init__.py", line 502, in select
    frame=self._dataframe(result)
  File "/opt/conda/lib/python3.6/site-packages/gastrodon/__init__.py", line 397, in _dataframe
    column[key] = self._normalize_column_type(column[key])
  File "/opt/conda/lib/python3.6/site-packages/gastrodon/__init__.py", line 376, in _normalize_column_type
    return [None if x==None else int(x) for x in column]
  File "/opt/conda/lib/python3.6/site-packages/gastrodon/__init__.py", line 376, in <listcomp>
    return [None if x==None else int(x) for x in column]
TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.date'

Issue (casting floats)

endpoint.select("""
SELECT DISTINCT ?starName ?mass
WHERE {
    ?star a dbp:Star .
    ?star foaf:name ?starName .
    ?star pr:mass ?mass
} LIMIT 1
""")

Output:

    starName  mass
0  61 Cygni     0

Expected output:

    starName  mass
0  61 Cygni   0.63

(see this)

Possible cause

I believe that they are coming from _normalize_column_type:

  1. pd.datetime is not considered, so when trying to do int(x) where x is a pd.datetime, the above error appears.
  2. If all elements in the column are float type, they are silently casted into int, as shown in the issue above.

My question now is: is it really necessary to normalize the columns?
pandas is usually smart enough to accommodate column types and cast if needed.
If I skip the _normalize_column_type() in the code, in the previous issue with the stars example, the mass is not casted to int, and if needed to cast to str, it does:

endpoint.select("""
SELECT DISTINCT ?starName ?mass
WHERE {
    ?star a dbp:Star .
    ?star foaf:name ?starName .
    ?star pr:mass ?mass
} LIMIT 100
""").head()

_.mass.dtype

Output:

      starName          mass
0     61 Cygni          0.63
1     61 Cygni           0.7
2  70 Virginis          1.12
3  70 Virginis  >7.49 ± 0.61
4      Albireo           3.2

dtype('O')

Python 3.6.6
gastrodon 0.9.3
pandas 0.23.4

syntax error on debian 9 with Python v 3.5.3

in jupyter notebook, got the below error when doing

import pandas as pd
import io
import numpy as np
from urllib.request import urlopen
import json
from math import *
from platform import python_version
print("Python v "+python_version())
from gastrodon import RemoteEndpoint,QName,ttl,URIRef,inline
from matplotlib import pyplot

<<
Traceback (most recent call last):

File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 9, in
from gastrodon import RemoteEndpoint,QName,ttl,URIRef,inline

File "/usr/local/lib/python3.5/dist-packages/gastrodon/init.py", line 136
kwargs:Dict={}
^
SyntaxError: invalid syntax

Any hints ?

Thank you!

Just wanted so thank you for providing this software. It really made someone happy today!

Credentials for remote endpoint

I see in the API documentation that the remote endpoint function can take basic credentials as user name and password. If the endpoint is controlled by individual or group access rights, then you wouldn't want to save the credentials in a shared notebook, however. How can the credentials be passed into Gastrodon from an external source?

ImportError: cannot import name 'l_' from 'sphinx.locale'

Running python -m unittest or coverage run -m unittest discover both raise an ImportError exception:

ImportError: Failed to import test module: gastrodon.domain
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/unittest/loader.py", line 470, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/local/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/jugurtha/workspace/python/gastrodon/gastrodon/domain/__init__.py", line 11, in <module>
    from sphinx.locale import l_, _
ImportError: cannot import name 'l_' from 'sphinx.locale' (/home/jugurtha/workspace/python/gastrodon/venv/lib/python3.7/site-packages/sphinx/locale/__init__.py)

According to this commit sphinx-doc/sphinx@8d653a4, the l_() function was integrated into _().

Recommended action:

Change the line:

    from sphinx.locale import l_, _

to

    from sphinx.locale import _

Running python -m unittest executes with the following results

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Note: The exception mentioned in #9 also was raised, and the proposed changes in mkdocstrings/mkdocstrings#2 were added not to have that error. These are also the changes proposed in #5

[Question] Python ORM into Gastrodon

1- Very very cool project ! Thank you !
I am newbie in Notebooks, how hard/easy is it to integrate

SuRF[link] with Gastrodon? this way no need to write SPARQL manually?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.