paulhoule / gastrodon Goto Github PK
View Code? Open in Web Editor NEWVisualize RDF data in Jupyter with Pandas
License: MIT License
Visualize RDF data in Jupyter with Pandas
License: MIT License
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)`
After playing around a bit with gastrodon, I think I have bumped into some problems regarding column types. To reproduce:
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/"
)
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'
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)
I believe that they are coming from _normalize_column_type
:
pd.datetime
is not considered, so when trying to do int(x)
where x
is a pd.datetime
, the above error appears.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
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 ?
Just wanted so thank you for providing this software. It really made someone happy today!
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?
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
I'm stuck using python 3.7. Because GenericMeta is no longer included in typing the import of gastrodon fails. I found a workaround here mkdocstrings/mkdocstrings#2 but I'm not sure if it will work in 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.