Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Eomys/SciDataTool
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-t committed Mar 26, 2021
2 parents 72ce758 + f90ff6a commit 4a19277
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 253 deletions.
24 changes: 22 additions & 2 deletions SciDataTool/Classes/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ def __eq__(self, other):
return False
return True

def compare(self, other, name="self"):
"""Compare two objects and return list of differences"""

if type(other) != type(self):
return ["type(" + name + ")"]
diff_list = list()
if other._symbol != self._symbol:
diff_list.append(name + ".symbol")
if other._name != self._name:
diff_list.append(name + ".name")
if other._unit != self._unit:
diff_list.append(name + ".unit")
if other._normalizations != self._normalizations:
diff_list.append(name + ".normalizations")
return diff_list

def __sizeof__(self):
"""Return the size in memory of the object (including all subobject)"""

Expand All @@ -108,8 +124,12 @@ def __sizeof__(self):
S += getsizeof(value) + getsizeof(key)
return S

def as_dict(self):
"""Convert this object in a json seriable dict (can be use in __init__)"""
def as_dict(self, **kwargs):
"""
Convert this object in a json serializable dict (can be use in __init__).
Optional keyword input parameter is for internal use only
and may prevent json serializability.
"""

Data_dict = dict()
Data_dict["symbol"] = self.symbol
Expand Down
27 changes: 24 additions & 3 deletions SciDataTool/Classes/Data1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ def __eq__(self, other):
return False
return True

def compare(self, other, name="self"):
"""Compare two objects and return list of differences"""

if type(other) != type(self):
return ["type(" + name + ")"]
diff_list = list()

# Check the properties inherited from Data
diff_list.extend(super(Data1D, self).compare(other, name=name))
if not array_equal(other.values, self.values):
diff_list.append(name + ".values")
if other._is_components != self._is_components:
diff_list.append(name + ".is_components")
if other._symmetries != self._symmetries:
diff_list.append(name + ".symmetries")
return diff_list

def __sizeof__(self):
"""Return the size in memory of the object (including all subobject)"""

Expand All @@ -205,11 +222,15 @@ def __sizeof__(self):
S += getsizeof(value) + getsizeof(key)
return S

def as_dict(self):
"""Convert this object in a json seriable dict (can be use in __init__)"""
def as_dict(self, **kwargs):
"""
Convert this object in a json serializable dict (can be use in __init__).
Optional keyword input parameter is for internal use only
and may prevent json serializability.
"""

# Get the properties inherited from Data
Data1D_dict = super(Data1D, self).as_dict()
Data1D_dict = super(Data1D, self).as_dict(**kwargs)
if self.values is None:
Data1D_dict["values"] = None
else:
Expand Down
21 changes: 18 additions & 3 deletions SciDataTool/Classes/DataFreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ def __eq__(self, other):
return False
return True

def compare(self, other, name="self"):
"""Compare two objects and return list of differences"""

if type(other) != type(self):
return ["type(" + name + ")"]
diff_list = list()

# Check the properties inherited from DataND
diff_list.extend(super(DataFreq, self).compare(other, name=name))
return diff_list

def __sizeof__(self):
"""Return the size in memory of the object (including all subobject)"""

Expand All @@ -132,11 +143,15 @@ def __sizeof__(self):
S += super(DataFreq, self).__sizeof__()
return S

def as_dict(self):
"""Convert this object in a json seriable dict (can be use in __init__)"""
def as_dict(self, **kwargs):
"""
Convert this object in a json serializable dict (can be use in __init__).
Optional keyword input parameter is for internal use only
and may prevent json serializability.
"""

# Get the properties inherited from DataND
DataFreq_dict = super(DataFreq, self).as_dict()
DataFreq_dict = super(DataFreq, self).as_dict(**kwargs)
# The class name is added to the dict for deserialisation purpose
# Overwrite the mother class name
DataFreq_dict["__class__"] = "DataFreq"
Expand Down
35 changes: 32 additions & 3 deletions SciDataTool/Classes/DataLinspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,31 @@ def __eq__(self, other):
return False
return True

def compare(self, other, name="self"):
"""Compare two objects and return list of differences"""

if type(other) != type(self):
return ["type(" + name + ")"]
diff_list = list()

# Check the properties inherited from Data
diff_list.extend(super(DataLinspace, self).compare(other, name=name))
if other._initial != self._initial:
diff_list.append(name + ".initial")
if other._final != self._final:
diff_list.append(name + ".final")
if other._step != self._step:
diff_list.append(name + ".step")
if other._number != self._number:
diff_list.append(name + ".number")
if other._include_endpoint != self._include_endpoint:
diff_list.append(name + ".include_endpoint")
if other._is_components != self._is_components:
diff_list.append(name + ".is_components")
if other._symmetries != self._symmetries:
diff_list.append(name + ".symmetries")
return diff_list

def __sizeof__(self):
"""Return the size in memory of the object (including all subobject)"""

Expand All @@ -237,11 +262,15 @@ def __sizeof__(self):
S += getsizeof(value) + getsizeof(key)
return S

def as_dict(self):
"""Convert this object in a json seriable dict (can be use in __init__)"""
def as_dict(self, **kwargs):
"""
Convert this object in a json serializable dict (can be use in __init__).
Optional keyword input parameter is for internal use only
and may prevent json serializability.
"""

# Get the properties inherited from Data
DataLinspace_dict = super(DataLinspace, self).as_dict()
DataLinspace_dict = super(DataLinspace, self).as_dict(**kwargs)
DataLinspace_dict["initial"] = self.initial
DataLinspace_dict["final"] = self.final
DataLinspace_dict["step"] = self.step
Expand Down
Loading

0 comments on commit 4a19277

Please sign in to comment.