Skip to content
Snippets Groups Projects
Verified Commit 39c9e3e7 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'dev' into f-spss-value-label-name

parents d5a7889a 18bb9618
No related branches found
No related tags found
1 merge request!226spss value label name
Pipeline #64838 passed
...@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### ### Fixed ###
- Handling of Pandas/Numpy Integers in Identifiable class
### Security ### ### Security ###
### Documentation ### ### Documentation ###
......
...@@ -23,6 +23,7 @@ from __future__ import annotations ...@@ -23,6 +23,7 @@ from __future__ import annotations
import json import json
import logging import logging
import numpy as np
from datetime import datetime from datetime import datetime
from hashlib import sha256 from hashlib import sha256
from typing import Optional, Union from typing import Optional, Union
...@@ -97,10 +98,10 @@ class Identifiable(): ...@@ -97,10 +98,10 @@ class Identifiable():
elif isinstance(value, list): elif isinstance(value, list):
return "[" + ", ".join([Identifiable._value_representation(el) for el in value]) + "]" return "[" + ", ".join([Identifiable._value_representation(el) for el in value]) + "]"
elif (isinstance(value, str) or isinstance(value, int) or isinstance(value, float) elif (isinstance(value, str) or isinstance(value, int) or isinstance(value, float)
or isinstance(value, datetime)): or isinstance(value, datetime) or np.issubdtype(type(value), np.number)):
return str(value) return str(value)
else: else:
raise ValueError(f"Unknown datatype of the value: {value}") raise ValueError(f"Unknown datatype of the value: {value} with type {type(value)}.")
@staticmethod @staticmethod
def _create_hashable_string(identifiable: Identifiable) -> str: def _create_hashable_string(identifiable: Identifiable) -> str:
......
...@@ -25,6 +25,7 @@ test identifiable module ...@@ -25,6 +25,7 @@ test identifiable module
""" """
import linkahead as db import linkahead as db
import numpy as np
import pytest import pytest
from caoscrawler.identifiable import Identifiable from caoscrawler.identifiable import Identifiable
...@@ -86,3 +87,13 @@ def test_equality(): ...@@ -86,3 +87,13 @@ def test_equality():
record_id=12, properties={"a": 0}) == Identifiable(properties={"a": 0}) record_id=12, properties={"a": 0}) == Identifiable(properties={"a": 0})
assert Identifiable(properties={"a": 0}) == Identifiable(properties={"a": 0}) assert Identifiable(properties={"a": 0}) == Identifiable(properties={"a": 0})
assert Identifiable(properties={"a": 0}) != Identifiable(properties={"a": 1}) assert Identifiable(properties={"a": 0}) != Identifiable(properties={"a": 1})
def test_numpy_int():
val_int = int(123)
val_64 = np.int64(123)
id_int = Identifiable(name="A", record_type="B", properties={'a': val_int})
id_64 = Identifiable(name="A", record_type="B", properties={'a': val_64})
assert id_int.get_representation() == id_64.get_representation()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment