-
Notifications
You must be signed in to change notification settings - Fork 8
Allow float64 #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Allow float64 #88
Changes from all commits
e029c2b
29b7bc7
fe41574
c1009ec
9b535f8
02488db
682220c
a8aad80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -102,12 +102,18 @@ def compare_arrays(arr1, arr2, var_name): | |||||||||||
| return total, equal, diff | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def fill_nans_for_float32(arr): | ||||||||||||
| def replace_nan_with_sentinel(arr): | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think now it is also casting to 64bit, so I would add it to the name or at least to the doc string. |
||||||||||||
| """ | ||||||||||||
| To make sure nan values are recognised. | ||||||||||||
| """ | ||||||||||||
| if arr.dtype == np.float32 and np.isnan(arr).any(): | ||||||||||||
| if not np.issubdtype(arr.dtype, np.floating): | ||||||||||||
| return arr | ||||||||||||
|
|
||||||||||||
| arr = arr.astype(np.float64, copy=False) | ||||||||||||
|
|
||||||||||||
| if np.isnan(arr).any(): | ||||||||||||
| return np.where(np.isnan(arr), -999999, arr) | ||||||||||||
|
|
||||||||||||
| return arr | ||||||||||||
|
Comment on lines
+114
to
117
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be slightly less efficinet, but more readable.
Suggested change
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -217,18 +223,20 @@ def compare_var_and_attr_ds(ds1, ds2, nl, output, location): | |||||||||||
| if output: | ||||||||||||
| if location: | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be safer:
Suggested change
|
||||||||||||
| path_name = location | ||||||||||||
|
|
||||||||||||
| else: | ||||||||||||
| script_dir = os.path.dirname(os.path.abspath(__file__)) | ||||||||||||
| path_name = os.path.join(script_dir, "differences.csv") | ||||||||||||
| parent_dir = os.path.dirname(script_dir) | ||||||||||||
| path_name = os.path.join(parent_dir, "differences.csv") | ||||||||||||
|
Comment on lines
227
to
+230
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this functionalty out of this routine into `fof_compare``: For the pytest, the location can be set to the tmp folder. what do you think? |
||||||||||||
|
|
||||||||||||
| with open(path_name, "w", encoding="utf-8") as f: | ||||||||||||
| f.write("Differences\n") | ||||||||||||
|
|
||||||||||||
| for var in set(ds1.data_vars).union(ds2.data_vars): | ||||||||||||
| if var in ds1.data_vars and var in ds2.data_vars and var not in list_to_skip: | ||||||||||||
|
|
||||||||||||
| arr1 = fill_nans_for_float32(ds1[var].values) | ||||||||||||
| arr2 = fill_nans_for_float32(ds2[var].values) | ||||||||||||
| arr1 = replace_nan_with_sentinel(ds1[var].values) | ||||||||||||
| arr2 = replace_nan_with_sentinel(ds2[var].values) | ||||||||||||
|
|
||||||||||||
| if arr1.size == arr2.size: | ||||||||||||
| t, e, diff = compare_arrays(arr1, arr2, var) | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be now