-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
HOTFIX: 2D .CSV Function and missing set_get_value_opt call #478
Changes from all commits
54c30f8
0b2eb80
8abe6af
2ee958a
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 |
---|---|---|
|
@@ -229,15 +229,6 @@ def source_function(_): | |
|
||
# Finally set data source as source | ||
self.source = source | ||
# Update extrapolation method | ||
if self.__extrapolation__ is None: | ||
self.set_extrapolation() | ||
# Set default interpolation for point source if it hasn't | ||
if self.__interpolation__ is None: | ||
self.set_interpolation() | ||
else: | ||
# Updates interpolation coefficients | ||
self.set_interpolation(self.__interpolation__) | ||
# Do things if function is multivariate | ||
else: | ||
self.x_array = source[:, 0] | ||
|
@@ -251,6 +242,15 @@ def source_function(_): | |
|
||
# Finally set data source as source | ||
self.source = source | ||
# Update extrapolation method | ||
if self.__extrapolation__ is None: | ||
self.set_extrapolation() | ||
# Set default interpolation for point source if it hasn't | ||
if self.__interpolation__ is None: | ||
self.set_interpolation() | ||
else: | ||
# Updates interpolation coefficients | ||
self.set_interpolation(self.__interpolation__) | ||
return self | ||
|
||
@cached_property | ||
|
@@ -329,7 +329,7 @@ def set_extrapolation(self, method="constant"): | |
def set_get_value_opt(self): | ||
"""Crates a method that evaluates interpolations rather quickly | ||
when compared to other options available, such as just calling | ||
the object instance or calling ``Function.get_value directly``. See | ||
the object instance or calling ``Function.get_value`` directly. See | ||
``Function.get_value_opt`` for documentation. | ||
|
||
Returns | ||
|
@@ -2785,7 +2785,8 @@ def _check_user_input( | |
dimensions of inputs and outputs. If the outputs list has more than | ||
one element. | ||
TypeError | ||
If the source is not a list, np.ndarray, or Function object. | ||
If the source is not a list, np.ndarray, Function object, str or | ||
Path. | ||
Warning | ||
If inputs or outputs do not match for a Function source, or if | ||
defaults are used for inputs, interpolation,and extrapolation for a | ||
|
@@ -2825,10 +2826,16 @@ def _check_user_input( | |
|
||
# check source for data type | ||
# if list or ndarray, check for dimensions, interpolation and extrapolation | ||
if isinstance(source, (list, np.ndarray)): | ||
# this will also trigger an error if the source is not a list of | ||
# numbers or if the array is not homogeneous | ||
source = np.array(source, dtype=np.float64) | ||
if isinstance(source, (list, np.ndarray, str, Path)): | ||
# Deal with csv or txt | ||
if isinstance(source, (str, Path)): | ||
# Convert to numpy array | ||
source = np.loadtxt(source, delimiter=",", dtype=float) | ||
|
||
Comment on lines
+2829
to
+2834
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 understand that this is necessary in order to check the validity of the inputs/outputs, but it is quite strange to read the csv here, throw away the result, and read it again in 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 say that loading it twice is really not a good idea. It can be a huge problem if the CSV file is large and takes a while to read. Furthermore, I would not recommend changing this in this hotfix PR. It doesn't exactly fix a bug. 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.
Yep, it is pretty strange, but the whole And if the source is anything besides Also What I am getting at is that all the user's inputs arguments should not be checked inside the same function, but rather in the calls of the
This 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. Indeed, in retrospect, it is a bit odd to perform the same operations multiple times in check inputs and while setting the source. I approved the PR, since I don't think changes to the check method is in the scope of a hotfix. The PR fixes the issue with This would decouple responsabilities a fair bit and could be implemented in various ways, maybe with |
||
else: | ||
# this will also trigger an error if the source is not a list of | ||
# numbers or if the array is not homogeneous | ||
source = np.array(source, dtype=np.float64) | ||
|
||
# check dimensions | ||
source_dim = source.shape[1] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
0.0, 0.0, 0.000 | ||
0.0, 0.1, 0.000 | ||
0.0, 0.2, 0.000 | ||
0.0, 0.3, 0.000 | ||
0.0, 0.4, 0.000 | ||
0.0, 0.5, 0.000 | ||
0.0, 0.6, 0.000 | ||
0.0, 0.7, 0.000 | ||
0.0, 0.8, 0.000 | ||
0.0, 0.9, 0.000 | ||
0.0, 1.0, 0.000 | ||
0.0, 1.1, 0.000 | ||
0.1, 0.0, 0.000 | ||
0.2, 0.0, 0.000 | ||
0.3, 0.0, 0.000 | ||
0.4, 0.0, 0.000 | ||
0.5, 0.0, 0.000 | ||
0.6, 0.0, 0.000 | ||
0.7, 0.0, 0.000 | ||
0.8, 0.0, 0.000 | ||
0.9, 0.0, 0.000 | ||
1.0, 0.0, 0.000 | ||
1.1, 0.0, 0.000 | ||
0.1, 0.1, 0.000 | ||
0.1, 0.2, 0.000 | ||
0.1, 0.3, 0.045 | ||
0.1, 0.4, 0.022 | ||
0.1, 0.5, 0.026 | ||
0.1, 0.6, 0.076 | ||
0.1, 0.7, 0.051 | ||
0.1, 0.8, 0.058 | ||
0.1, 0.9, 0.022 | ||
0.1, 1.0, 0.000 | ||
0.1, 1.1, 0.000 | ||
0.2, 0.1, 0.022 | ||
0.2, 0.2, 0.062 | ||
0.2, 0.3, 0.093 | ||
0.2, 0.4, 0.076 | ||
0.2, 0.5, 0.070 | ||
0.2, 0.6, 0.129 | ||
0.2, 0.7, 0.102 | ||
0.2, 0.8, 0.115 | ||
0.2, 0.9, 0.084 | ||
0.2, 1.0, 0.018 | ||
0.2, 1.1, 0.000 | ||
0.3, 0.1, 0.056 | ||
0.3, 0.2, 0.106 | ||
0.3, 0.3, 0.147 | ||
0.3, 0.4, 0.139 | ||
0.3, 0.5, 0.139 | ||
0.3, 0.6, 0.183 | ||
0.3, 0.7, 0.169 | ||
0.3, 0.8, 0.183 | ||
0.3, 0.9, 0.149 | ||
0.3, 1.0, 0.093 | ||
0.3, 1.1, 0.070 | ||
0.4, 0.1, 0.120 | ||
0.4, 0.2, 0.169 | ||
0.4, 0.3, 0.214 | ||
0.4, 0.4, 0.195 | ||
0.4, 0.5, 0.214 | ||
0.4, 0.6, 0.262 | ||
0.4, 0.7, 0.253 | ||
0.4, 0.8, 0.271 | ||
0.4, 0.9, 0.253 | ||
0.4, 1.0, 0.192 | ||
0.4, 1.1, 0.164 | ||
0.5, 0.1, 0.217 | ||
0.5, 0.2, 0.217 | ||
0.5, 0.3, 0.275 | ||
0.5, 0.4, 0.257 | ||
0.5, 0.5, 0.284 | ||
0.5, 0.6, 0.349 | ||
0.5, 0.7, 0.340 | ||
0.5, 0.8, 0.360 | ||
0.5, 0.9, 0.340 | ||
0.5, 1.0, 0.288 | ||
0.5, 1.1, 0.253 | ||
0.6, 0.1, 0.245 | ||
0.6, 0.2, 0.288 | ||
0.6, 0.3, 0.382 | ||
0.6, 0.4, 0.360 | ||
0.6, 0.5, 0.382 | ||
0.6, 0.6, 0.457 | ||
0.6, 0.7, 0.445 | ||
0.6, 0.8, 0.447 | ||
0.6, 0.9, 0.434 | ||
0.6, 1.0, 0.403 | ||
0.6, 1.1, 0.360 | ||
0.7, 0.1, 0.320 | ||
0.7, 0.2, 0.392 | ||
0.7, 0.3, 0.487 | ||
0.7, 0.4, 0.476 | ||
0.7, 0.5, 0.476 | ||
0.7, 0.6, 0.564 | ||
0.7, 0.7, 0.527 | ||
0.7, 0.8, 0.531 | ||
0.7, 0.9, 0.527 | ||
0.7, 1.0, 0.520 | ||
0.7, 1.1, 0.487 | ||
0.8, 0.1, 0.426 | ||
0.8, 0.2, 0.507 | ||
0.8, 0.3, 0.568 | ||
0.8, 0.4, 0.538 | ||
0.8, 0.5, 0.538 | ||
0.8, 0.6, 0.617 | ||
0.8, 0.7, 0.613 | ||
0.8, 0.8, 0.624 | ||
0.8, 0.9, 0.613 | ||
0.8, 1.0, 0.520 | ||
0.8, 1.1, 0.591 | ||
0.9, 0.1, 0.507 | ||
0.9, 0.2, 0.568 | ||
0.9, 0.3, 0.613 | ||
0.9, 0.4, 0.600 | ||
0.9, 0.5, 0.609 | ||
0.9, 0.6, 0.684 | ||
0.9, 0.7, 0.684 | ||
0.9, 0.8, 0.702 | ||
0.9, 0.9, 0.708 | ||
0.9, 1.0, 0.624 | ||
0.9, 1.1, 0.674 | ||
1.0, 0.1, 0.937 | ||
1.0, 0.2, 0.937 | ||
1.0, 0.3, 0.937 | ||
1.0, 0.4, 0.887 | ||
1.0, 0.5, 0.803 | ||
1.0, 0.6, 0.930 | ||
1.0, 0.7, 0.887 | ||
1.0, 0.8, 0.921 | ||
1.0, 0.9, 0.815 | ||
1.0, 1.0, 0.844 | ||
1.0, 1.1, 0.803 |
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.
I believe a
try-except
withFileNotFound
would be beneficial here, just because it is a good practice. But again, this is also done inset_source
.