From 0f113abc55ad77e11f8d86b3b71656a68e7a9aab Mon Sep 17 00:00:00 2001 From: Eugene Morozov Date: Sun, 4 Apr 2021 13:14:17 +0100 Subject: [PATCH] Fixes URL regex, updates nosetests set up, bumps up the version for release. --- docs/source/conf.py | 4 ++-- rdfpandas/graph.py | 4 ++-- setup.py | 2 +- tests/__init__.py | 1 + tests/test_graph.py | 11 ++++++++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index b59c0a5..33b02e7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -24,9 +24,9 @@ author = 'Eugene Morozov' # The short X.Y version -version = 'v1.1.0' +version = 'v1.1.1' # The full version, including alpha/beta/rc tags -release = 'v1.1.0' +release = 'v1.1.1' # -- General configuration --------------------------------------------------- diff --git a/rdfpandas/graph.py b/rdfpandas/graph.py index f730c35..bc9936b 100644 --- a/rdfpandas/graph.py +++ b/rdfpandas/graph.py @@ -39,8 +39,8 @@ def to_graph(df: pd.DataFrame, namespace_manager: NamespaceManager = None) -> Gr for (index, series) in df.iterrows(): for (column, value) in series.iteritems(): - match = re.search('([\w?:/.]*)(\{(\w*)\})?(\[(\d*)\])?(\(([\w?:/.]*)\))?(@(\w*))?', column) - + # Matching unreserved, gen-delims and sub-delims with exception of "(", ")", "@", "[" and "]" from RFC 3986 + match = re.search('([\w\-._~:/?#!$&\'*+,;=]*)(\{(\w*)\})?(\[(\d*)\])?(\(([\w?:/.]*)\))?(@(\w*))?', column) if pd.notna(value) and pd.notnull(value): s = _get_identifier(prefixes, index) p = _get_identifier(prefixes, match.group(1)) diff --git a/setup.py b/setup.py index acb15af..48dccfe 100755 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name = 'rdfpandas', - version = '1.1.0', + version = '1.1.1', description = 'RDF support for Pandas', long_description = readme, author = 'Eugene Morozov', diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..6b8a359 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1 @@ +from .test_graph import ConversionTestCase \ No newline at end of file diff --git a/tests/test_graph.py b/tests/test_graph.py index 2f7d681..3dc18de 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -177,10 +177,12 @@ def test_should_convert_data_frame_to_graph_uriref(self): ds1 = pd.Series(data=['https://google.com'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_) ds2 = pd.Series(data=['skos:broader'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_) + ds3 = pd.Series(data=['skos:Concept'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_) df = pd.DataFrame({ 'http://github.com/cadmiumkitty/rdfpandas/uri{URIRef}': ds1, - 'http://github.com/cadmiumkitty/rdfpandas/curie{URIRef}': ds2 + 'http://github.com/cadmiumkitty/rdfpandas/curie{URIRef}': ds2, + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type{URIRef}': ds3 }) g_expected = Graph() @@ -191,6 +193,9 @@ def test_should_convert_data_frame_to_graph_uriref(self): g_expected.add((URIRef('http://github.com/cadmiumkitty/rdfpandas/one'), URIRef('http://github.com/cadmiumkitty/rdfpandas/curie'), URIRef('skos:broader'))) + g_expected.add((URIRef('http://github.com/cadmiumkitty/rdfpandas/one'), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef('skos:Concept'))) g_result = rdfpandas.to_graph(df) @@ -333,7 +338,7 @@ def test_should_roundtrip_csv_to_graph_to_csv(self): """Should roundtrip DF -> Graph -> DF """ - df = pd.read_csv('./csv/test.csv', index_col = '@id', keep_default_na = True) + df = pd.read_csv('./tests/csv/test.csv', index_col = '@id', keep_default_na = True) namespace_manager = NamespaceManager(Graph()) namespace_manager.bind('skos', SKOS) namespace_manager.bind('rdfpandas', Namespace('http://github.com/cadmiumkitty/rdfpandas/')) @@ -348,7 +353,7 @@ def test_should_roundtrip_graph_to_csv_to_graph(self): """ g = rdflib.Graph() - g.parse('./rdf/test.ttl', format = 'ttl') + g.parse('./tests/rdf/test.ttl', format = 'ttl') df = rdfpandas.to_dataframe(g) print(df.T) g_result = rdfpandas.to_graph(df, g.namespace_manager)