Skip to content

Commit

Permalink
Upgrades to Pandas 2.2.0/NumPy 2.0 and resolves deprecation of np.uni…
Browse files Browse the repository at this point in the history
…code_ in NumPy 2.0
  • Loading branch information
cadmiumkitty committed Sep 20, 2024
1 parent 4d439a7 commit 039eb16
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 48 deletions.
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
# -- Project information -----------------------------------------------------

project = 'rdfpandas'
copyright = '2023, Eugene Morozov'
copyright = '2024, Eugene Morozov'
author = 'Eugene Morozov'

# The short X.Y version
version = 'v1.1.6'
version = 'v1.1.7'
# The full version, including alpha/beta/rc tags
release = 'v1.1.6'
release = 'v1.1.7'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ DataFrame to Graph conversion.

For more details and the source code see https://github.com/cadmiumkitty/rdfpandas/

We run Semantic Web London meetup https://www.meetup.com/semantic-web-london/

Indices and tables
==================

Expand Down
2 changes: 1 addition & 1 deletion rdfpandas/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def to_dataframe(g: Graph) -> pd.DataFrame:
p_objects.append(_get_str_for_uriref(g.namespace_manager, o))
s_index = s_index + 1
last_seen_subject = s
series[series_name] = pd.Series(data = p_objects, index = p_subjects, dtype = np.unicode_)
series[series_name] = pd.Series(data = p_objects, index = p_subjects, dtype = np.str_)

return pd.DataFrame(series)

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
nose
pynose
sphinx
sphinx_rtd_theme
pandas>=2.0.0
pandas>=2.2.2
rdflib>=6.3.2
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

setup(
name = 'rdfpandas',
version = '1.1.6',
version = '1.1.7',
description = 'RDF support for Pandas',
long_description = readme,
author = 'Eugene Morozov',
author_email = '[email protected]',
url = 'https://github.com/cadmiumkitty/rdfpandas',
license = 'MIT',
packages = find_packages(exclude = ('tests', 'docs')),
install_requires = ['pandas>=2.0.0', 'rdflib>=6.3.2']
install_requires = ['pandas>=2.2.2', 'rdflib>=6.3.2']
)

76 changes: 38 additions & 38 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def test_should_convert_empty_data_frame_to_empty_graph(self):
g_expected = Graph()
g_result = rdfpandas.to_graph(df)

self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True)
self.assertEqual(rdflib.compare.isomorphic(g_expected, g_result), True)

def test_should_convert_data_frame_to_graph_no_instance(self):
"""Should apply default types.
"""

ds01 = pd.Series(data = ['Bytes'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)

ds02 = pd.Series(data = ['String'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds02 = pd.Series(data = ['String'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)

ds03 = pd.Series(data = [0], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.int64)
ds04 = pd.Series(data = [-9223372036854775808], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.int64)
Expand All @@ -48,8 +48,8 @@ def test_should_convert_data_frame_to_graph_no_instance(self):
ds11 = pd.Series(data = [True], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.bool_)
ds12 = pd.Series(data = [False], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.bool_)

ds13 = pd.Series(data = ['https://google.com'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds14 = pd.Series(data = ['skos:broader'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds13 = pd.Series(data = ['https://google.com'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds14 = pd.Series(data = ['skos:broader'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)

df = pd.DataFrame({
'http://github.com/cadmiumkitty/rdfpandas/stringu': ds01,
Expand Down Expand Up @@ -120,18 +120,18 @@ def test_should_convert_data_frame_to_graph_no_instance(self):

g_result = rdfpandas.to_graph(df)

self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True)
self.assertEqual(rdflib.compare.isomorphic(g_expected, g_result), True)

def test_should_convert_data_frame_to_graph_literal(self):
"""Should create triples based on Literal instance type, datatype and
language provided.
"""

ds01 = pd.Series(data = ['String'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds02 = pd.Series(data = ['String with type only'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds03 = pd.Series(data = ['String with language only in Nepali'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds04 = pd.Series(data = ['String In English 1'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds05 = pd.Series(data = ['String In English 2'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds01 = pd.Series(data = ['String'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds02 = pd.Series(data = ['String with type only'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds03 = pd.Series(data = ['String with language only in Nepali'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds04 = pd.Series(data = ['String In English 1'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds05 = pd.Series(data = ['String In English 2'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)

df = pd.DataFrame({
'http://github.com/cadmiumkitty/rdfpandas/string{Literal}': ds01,
Expand Down Expand Up @@ -161,16 +161,16 @@ def test_should_convert_data_frame_to_graph_literal(self):

g_result = rdfpandas.to_graph(df)

self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True)
self.assertEqual(rdflib.compare.isomorphic(g_expected, g_result), True)

def test_should_convert_data_frame_to_graph_uriref(self):
"""Should create triples based on URIRef instance type.
"""

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_)
ds4 = pd.Series(data=['unknown:unknown'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds1 = pd.Series(data=['https://google.com'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds2 = pd.Series(data=['skos:broader'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds3 = pd.Series(data=['skos:Concept'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds4 = pd.Series(data=['unknown:unknown'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)

df = pd.DataFrame({
'http://github.com/cadmiumkitty/rdfpandas/uri{URIRef}': ds1,
Expand All @@ -196,14 +196,14 @@ def test_should_convert_data_frame_to_graph_uriref(self):

g_result = rdfpandas.to_graph(df)

self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True)
self.assertEqual(rdflib.compare.isomorphic(g_expected, g_result), True)

def test_should_convert_data_frame_to_graph_uriref_curie(self):
"""Should create triples based on several compliant CURIES.
"""

ds1 = pd.Series(data=['prefix:suffix'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds2 = pd.Series(data=['preffix-._1.:suffix-._1'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds1 = pd.Series(data=['prefix:suffix'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds2 = pd.Series(data=['preffix-._1.:suffix-._1'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)

df = pd.DataFrame({
'http://github.com/cadmiumkitty/rdfpandas/curie1{URIRef}': ds1,
Expand All @@ -221,13 +221,13 @@ def test_should_convert_data_frame_to_graph_uriref_curie(self):

g_result = rdfpandas.to_graph(df)

self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True)
self.assertEqual(rdflib.compare.isomorphic(g_expected, g_result), True)

def test_should_convert_data_frame_to_graph_bnode(self):
"""Should create triples based on BNode instance type.
"""

ds1 = pd.Series(data=['ub1bL39C14'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds1 = pd.Series(data=['ub1bL39C14'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)

df = pd.DataFrame({
'http://github.com/cadmiumkitty/rdfpandas/bnode{BNode}': ds1,
Expand All @@ -241,7 +241,7 @@ def test_should_convert_data_frame_to_graph_bnode(self):

g_result = rdfpandas.to_graph(df)

self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True)
self.assertEqual(rdflib.compare.isomorphic(g_expected, g_result), True)


def test_should_convert_empty_graph_to_empty_data_frame(self):
Expand All @@ -251,7 +251,7 @@ def test_should_convert_empty_graph_to_empty_data_frame(self):
g = Graph()
df_result = rdfpandas.to_dataframe(g)

self.assertEquals(df_result.empty, True)
self.assertEqual(df_result.empty, True)


def test_should_convert_graph_to_data_frame(self):
Expand Down Expand Up @@ -319,20 +319,20 @@ def test_should_convert_graph_to_data_frame(self):
URIRef('http://github.com/cadmiumkitty/rdfpandas/string'),
Literal('String in English 1 (2)', lang = 'en')))

ds01 = pd.Series(data = ['String 1'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds02 = pd.Series(data = ['String 2'], index = ['http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.unicode_)
ds03 = pd.Series(data = ['String with type 1 (1)', 'String with type 1 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one', 'http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.unicode_)
ds04 = pd.Series(data = ['String with type 2 (1)', 'String with type 2 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one', 'http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.unicode_)
ds05 = pd.Series(data = ['String in Nepali 1 (1)', 'String in Nepali 1 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one', 'http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.unicode_)
ds06 = pd.Series(data = ['String in Nepali 2 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.unicode_)
ds07 = pd.Series(data = ['String in English 1 (1)', 'String in English 1 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one', 'http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.unicode_)
ds08 = pd.Series(data = ['String in English 2 (1)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds09 = pd.Series(data = ['String in Russian 1 (1)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds10 = pd.Series(data = ['10'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds11 = pd.Series(data = ['10.0'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds12 = pd.Series(data = ['https://google.com'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds13 = pd.Series(data = ['skos:broader'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds14 = pd.Series(data = ['12345'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
ds01 = pd.Series(data = ['String 1'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds02 = pd.Series(data = ['String 2'], index = ['http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.str_)
ds03 = pd.Series(data = ['String with type 1 (1)', 'String with type 1 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one', 'http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.str_)
ds04 = pd.Series(data = ['String with type 2 (1)', 'String with type 2 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one', 'http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.str_)
ds05 = pd.Series(data = ['String in Nepali 1 (1)', 'String in Nepali 1 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one', 'http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.str_)
ds06 = pd.Series(data = ['String in Nepali 2 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.str_)
ds07 = pd.Series(data = ['String in English 1 (1)', 'String in English 1 (2)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one', 'http://github.com/cadmiumkitty/rdfpandas/two'], dtype = np.str_)
ds08 = pd.Series(data = ['String in English 2 (1)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds09 = pd.Series(data = ['String in Russian 1 (1)'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds10 = pd.Series(data = ['10'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds11 = pd.Series(data = ['10.0'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds12 = pd.Series(data = ['https://google.com'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds13 = pd.Series(data = ['skos:broader'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)
ds14 = pd.Series(data = ['12345'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.str_)

df_expected = pd.DataFrame({
'http://github.com/cadmiumkitty/rdfpandas/string{Literal}': ds01,
Expand Down Expand Up @@ -367,7 +367,7 @@ def test_should_roundtrip_csv_to_graph_to_csv(self):
g = rdfpandas.to_graph(df, namespace_manager)
df_result = rdfpandas.to_dataframe(g)

pd.testing.assert_frame_equal(df.astype(np.unicode_), df_result.astype(np.unicode_), check_like = True, check_names = False)
pd.testing.assert_frame_equal(df.astype(np.str_), df_result.astype(np.str_), check_like = True, check_names = False)


def test_should_roundtrip_graph_to_csv_to_graph(self):
Expand All @@ -378,7 +378,7 @@ def test_should_roundtrip_graph_to_csv_to_graph(self):
g.parse('./tests/rdf/test.ttl', format = 'ttl')
df = rdfpandas.to_dataframe(g)
g_result = rdfpandas.to_graph(df, g.namespace_manager)
self.assertEquals(rdflib.compare.isomorphic(g, g_result), True)
self.assertEqual(rdflib.compare.isomorphic(g, g_result), True)


if __name__ == '__main__':
Expand Down

0 comments on commit 039eb16

Please sign in to comment.