Skip to content

Commit

Permalink
[NF] is_add_value in compare
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-t committed May 4, 2022
1 parent 988cc8e commit 4a646bc
Show file tree
Hide file tree
Showing 17 changed files with 664 additions and 105 deletions.
2 changes: 1 addition & 1 deletion SciDataTool/Classes/Class_Dict.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Data": {
"constants": [
{
Expand Down
38 changes: 32 additions & 6 deletions SciDataTool/Classes/Data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File generated according to Generator/ClassesRef/Data.csv
# WARNING! All changes made in this file will be lost!
"""Method code available at https://github.com/Eomys/SciDataTool/tree/master/SciDataTool/Methods//Data
Expand All @@ -21,6 +21,7 @@
_set_normalizations = error


from numpy import isnan
from ._check import InitUnKnowClassError


Expand Down Expand Up @@ -123,7 +124,7 @@ def __eq__(self, other):
return False
return True

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

if ignore_list is None:
Expand All @@ -132,11 +133,33 @@ def compare(self, other, name="self", ignore_list=None):
return ["type(" + name + ")"]
diff_list = list()
if other._symbol != self._symbol:
diff_list.append(name + ".symbol")
if is_add_value:
val_str = (
" (self="
+ str(self._symbol)
+ ", other="
+ str(other._symbol)
+ ")"
)
diff_list.append(name + ".symbol" + val_str)
else:
diff_list.append(name + ".symbol")
if other._name != self._name:
diff_list.append(name + ".name")
if is_add_value:
val_str = (
" (self=" + str(self._name) + ", other=" + str(other._name) + ")"
)
diff_list.append(name + ".name" + val_str)
else:
diff_list.append(name + ".name")
if other._unit != self._unit:
diff_list.append(name + ".unit")
if is_add_value:
val_str = (
" (self=" + str(self._unit) + ", other=" + str(other._unit) + ")"
)
diff_list.append(name + ".unit" + val_str)
else:
diff_list.append(name + ".unit")
if (other.normalizations is None and self.normalizations is not None) or (
other.normalizations is not None and self.normalizations is None
):
Expand All @@ -149,7 +172,10 @@ def compare(self, other, name="self", ignore_list=None):
for key in self.normalizations:
diff_list.extend(
self.normalizations[key].compare(
other.normalizations[key], name=name + ".normalizations"
other.normalizations[key],
name=name + ".normalizations[" + str(key) + "]",
ignore_list=ignore_list,
is_add_value=is_add_value,
)
)
# Filter ignore differences
Expand Down
95 changes: 85 additions & 10 deletions SciDataTool/Classes/Data1D.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File generated according to Generator/ClassesRef/Data1D.csv
# WARNING! All changes made in this file will be lost!
"""Method code available at https://github.com/Eomys/SciDataTool/tree/master/SciDataTool/Methods//Data1D
Expand Down Expand Up @@ -57,6 +57,7 @@


from numpy import array, array_equal
from numpy import isnan
from ._check import InitUnKnowClassError


Expand Down Expand Up @@ -280,7 +281,7 @@ def __eq__(self, other):
return False
return True

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

if ignore_list is None:
Expand All @@ -290,23 +291,97 @@ def compare(self, other, name="self", ignore_list=None):
diff_list = list()

# Check the properties inherited from Data
diff_list.extend(super(Data1D, self).compare(other, name=name))
diff_list.extend(
super(Data1D, self).compare(
other, name=name, ignore_list=ignore_list, is_add_value=is_add_value
)
)
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 is_add_value:
val_str = (
" (self="
+ str(self._is_components)
+ ", other="
+ str(other._is_components)
+ ")"
)
diff_list.append(name + ".is_components" + val_str)
else:
diff_list.append(name + ".is_components")
if other._symmetries != self._symmetries:
diff_list.append(name + ".symmetries")
if is_add_value:
val_str = (
" (self="
+ str(self._symmetries)
+ ", other="
+ str(other._symmetries)
+ ")"
)
diff_list.append(name + ".symmetries" + val_str)
else:
diff_list.append(name + ".symmetries")
if other._is_overlay != self._is_overlay:
diff_list.append(name + ".is_overlay")
if is_add_value:
val_str = (
" (self="
+ str(self._is_overlay)
+ ", other="
+ str(other._is_overlay)
+ ")"
)
diff_list.append(name + ".is_overlay" + val_str)
else:
diff_list.append(name + ".is_overlay")
if other._delimiter != self._delimiter:
diff_list.append(name + ".delimiter")
if is_add_value:
val_str = (
" (self="
+ str(self._delimiter)
+ ", other="
+ str(other._delimiter)
+ ")"
)
diff_list.append(name + ".delimiter" + val_str)
else:
diff_list.append(name + ".delimiter")
if other._sort_indices != self._sort_indices:
diff_list.append(name + ".sort_indices")
if is_add_value:
val_str = (
" (self="
+ str(self._sort_indices)
+ ", other="
+ str(other._sort_indices)
+ ")"
)
diff_list.append(name + ".sort_indices" + val_str)
else:
diff_list.append(name + ".sort_indices")
if other._filter != self._filter:
diff_list.append(name + ".filter")
if is_add_value:
val_str = (
" (self="
+ str(self._filter)
+ ", other="
+ str(other._filter)
+ ")"
)
diff_list.append(name + ".filter" + val_str)
else:
diff_list.append(name + ".filter")
if other._char_to_rm != self._char_to_rm:
diff_list.append(name + ".char_to_rm")
if is_add_value:
val_str = (
" (self="
+ str(self._char_to_rm)
+ ", other="
+ str(other._char_to_rm)
+ ")"
)
diff_list.append(name + ".char_to_rm" + val_str)
else:
diff_list.append(name + ".char_to_rm")
# Filter ignore differences
diff_list = list(filter(lambda x: x not in ignore_list, diff_list))
return diff_list
Expand Down
39 changes: 34 additions & 5 deletions SciDataTool/Classes/DataDual.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File generated according to Generator/ClassesRef/DataDual.csv
# WARNING! All changes made in this file will be lost!
"""Method code available at https://github.com/Eomys/SciDataTool/tree/master/SciDataTool/Methods//DataDual
Expand Down Expand Up @@ -27,6 +27,7 @@


from numpy import array, array_equal
from numpy import isnan
from ._check import InitUnKnowClassError


Expand Down Expand Up @@ -176,7 +177,7 @@ def __eq__(self, other):
return False
return True

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

if ignore_list is None:
Expand All @@ -186,7 +187,11 @@ def compare(self, other, name="self", ignore_list=None):
diff_list = list()

# Check the properties inherited from DataND
diff_list.extend(super(DataDual, self).compare(other, name=name))
diff_list.extend(
super(DataDual, self).compare(
other, name=name, ignore_list=ignore_list, is_add_value=is_add_value
)
)
if (other.axes_dt is None and self.axes_dt is not None) or (
other.axes_dt is not None and self.axes_dt is None
):
Expand All @@ -199,7 +204,10 @@ def compare(self, other, name="self", ignore_list=None):
for ii in range(len(other.axes_dt)):
diff_list.extend(
self.axes_dt[ii].compare(
other.axes_dt[ii], name=name + ".axes_dt[" + str(ii) + "]"
other.axes_dt[ii],
name=name + ".axes_dt[" + str(ii) + "]",
ignore_list=ignore_list,
is_add_value=is_add_value,
)
)
if not array_equal(other.values_dt, self.values_dt):
Expand All @@ -216,7 +224,10 @@ def compare(self, other, name="self", ignore_list=None):
for ii in range(len(other.axes_df)):
diff_list.extend(
self.axes_df[ii].compare(
other.axes_df[ii], name=name + ".axes_df[" + str(ii) + "]"
other.axes_df[ii],
name=name + ".axes_df[" + str(ii) + "]",
ignore_list=ignore_list,
is_add_value=is_add_value,
)
)
if not array_equal(other.values_df, self.values_df):
Expand Down Expand Up @@ -342,6 +353,15 @@ def _set_axes_dt(self, value):
"""setter of axes_dt"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"SciDataTool.Classes", obj.get("__class__"), "axes_dt"
Expand Down Expand Up @@ -400,6 +420,15 @@ def _set_axes_df(self, value):
"""setter of axes_df"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"SciDataTool.Classes", obj.get("__class__"), "axes_df"
Expand Down
11 changes: 8 additions & 3 deletions SciDataTool/Classes/DataFreq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File generated according to Generator/ClassesRef/DataFreq.csv
# WARNING! All changes made in this file will be lost!
"""Method code available at https://github.com/Eomys/SciDataTool/tree/master/SciDataTool/Methods//DataFreq
Expand Down Expand Up @@ -37,6 +37,7 @@


from numpy import array, array_equal
from numpy import isnan
from ._check import InitUnKnowClassError


Expand Down Expand Up @@ -168,7 +169,7 @@ def __eq__(self, other):
return False
return True

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

if ignore_list is None:
Expand All @@ -178,7 +179,11 @@ def compare(self, other, name="self", ignore_list=None):
diff_list = list()

# Check the properties inherited from DataND
diff_list.extend(super(DataFreq, self).compare(other, name=name))
diff_list.extend(
super(DataFreq, self).compare(
other, name=name, ignore_list=ignore_list, is_add_value=is_add_value
)
)
# Filter ignore differences
diff_list = list(filter(lambda x: x not in ignore_list, diff_list))
return diff_list
Expand Down
Loading

0 comments on commit 4a646bc

Please sign in to comment.