You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
The hard coded file path in test/test_api.py::TestAPI::test_open_mf_dataset is unsafe. I added a test file to test/meshfiles/ugrid/outCSne30/outCSne30_test2.nc from Paul, and it failed.
Details
The test test/test_api.py::TestAPI::test_open_mf_dataset is failing after I added test/meshfiles/ugrid/outCSne30/outCSne30_test2.nc.
I think the reason is because of this hardcoded file path incorrectly matching outCSne30_test2.nc.
Yeah this should really be a list of paths since that file path will assume any paths that match the outCSne30_ prefix with a .nc ending. We should have it point to the two data files as seen below.
Even though explicitly listing the file names to be opened with open_mfdatasets can be an alternative solution, I don't think giving file name patterns as in here is the actual reason of the problem.
That is common practice to have multiple data files from the same workflow in the same folder, e.g. separate files for different time stamps in a time-series analysis or separate files for different variables in a big simulation. That said, if we think all of the files under the test/meshfiles/ugrid/outCSne30/ directory are somehow related to each other in such a way, let us keep storing them there; otherwise, we need to consider oving some of them into a different folder. If the former, then I'd expect a code something like this should still work:
dsfiles_mf_ne30 = str( current_path) + "/meshfiles/ugrid/outCSne30/outCSne30_*.nc"
uxds_mf_ne30 = ux.open_mfdataset(self.gridfile_ne30, self.dsfiles_mf_ne30, , concat_dim="Time", combine="nested") # Use the actual dimension variable to be concatenated over those files
Thank you for your input! I will move the test files needed for zonal-mean testing (test/meshfiles/ugrid/outCSne30_zonal_test/outCSne30_test2.nc and test/meshfiles/ugrid/outCSne30_zonal_test/outCSne30_test2.nc) to a new folder: test/meshfiles/ugrid/outCSne30_zonal_test.
Does this sound like a good solution for the zonal-mean PR failing the API test?
Before that, please determine if those newer zonal test files are very close in format/content with the original outCSne30_var2.nc and outCSne30_vortex.nc files. If that's the case, I'd instead suggest that you do the following code change in the failing tests, and it should work:
dsfiles_mf_ne30 = str( current_path) + "/meshfiles/ugrid/outCSne30/outCSne30_*.nc"
uxds_mf_ne30 = ux.open_mfdataset(self.gridfile_ne30, self.dsfiles_mf_ne30, , concat_dim="Time", combine="nested") # Use the actual dimension variable to be concatenated over those files
If that's not the case though, then your suggestion looks good.
Before that, please determine if those newer zonal test files are very close in format/content with the original outCSne30_var2.nc and outCSne30_vortex.nc files. If that's the case, I'd instead suggest that you do the following code change in the failing tests, and it should work:
dsfiles_mf_ne30 = str( current_path) + "/meshfiles/ugrid/outCSne30/outCSne30_*.nc"
uxds_mf_ne30 = ux.open_mfdataset(self.gridfile_ne30, self.dsfiles_mf_ne30, , concat_dim="Time", combine="nested") # Use the actual dimension variable to be concatenated over those files
If that's not the case though, then your suggestion looks good.
Thank you for your suggestion. I believe the zonal test files are in close format with the original test files. I have updated the test_open_mf_dataset as you recommended.
The new uxds_mf_ne30.uxgrid._ds.data_vars has one more dimension edge_node_connectivity:
Therefore, I also modified the test constants in test/constants.py. Could you please verify if the new test parameters look good? The modifications are in the zonal-mean branch.
If this solution to the test_api.py bug is acceptable, then PR#785 is also ready for review. :)
Activity
philipc2 commentedon Jul 23, 2024
Yeah this should really be a list of paths since that file path will assume any paths that match the
outCSne30_prefix with a.ncending. We should have it point to the two data files as seen below.erogluorhan commentedon Jul 23, 2024
Even though explicitly listing the file names to be opened with
open_mfdatasetscan be an alternative solution, I don't think giving file name patterns as in here is the actual reason of the problem.That is common practice to have multiple data files from the same workflow in the same folder, e.g. separate files for different time stamps in a time-series analysis or separate files for different variables in a big simulation. That said, if we think all of the files under the
test/meshfiles/ugrid/outCSne30/directory are somehow related to each other in such a way, let us keep storing them there; otherwise, we need to consider oving some of them into a different folder. If the former, then I'd expect a code something like this should still work:amberchen122 commentedon Jul 26, 2024
Thank you for your input! I will move the test files needed for zonal-mean testing (
test/meshfiles/ugrid/outCSne30_zonal_test/outCSne30_test2.ncandtest/meshfiles/ugrid/outCSne30_zonal_test/outCSne30_test2.nc) to a new folder:test/meshfiles/ugrid/outCSne30_zonal_test.Does this sound like a good solution for the zonal-mean PR failing the API test?
erogluorhan commentedon Jul 26, 2024
Before that, please determine if those newer zonal test files are very close in format/content with the original
outCSne30_var2.ncandoutCSne30_vortex.ncfiles. If that's the case, I'd instead suggest that you do the following code change in the failing tests, and it should work:If that's not the case though, then your suggestion looks good.
amberchen122 commentedon Jul 30, 2024
Thank you for your suggestion. I believe the zonal test files are in close format with the original test files. I have updated the
test_open_mf_datasetas you recommended.The new
uxds_mf_ne30.uxgrid._ds.data_varshas one more dimensionedge_node_connectivity:test/test_api.py uxds_mf_ne30.uxgrid._ds.data_vars:
grid_topology int32 4B -2147483647
face_node_connectivity (n_face, n_max_face_nodes) int64 173kB 0 8 ... 6 298
node_lon (n_node) float64 43kB -45.0 45.0 ... 138.0 135.0
node_lat (n_node) float64 43kB ...
edge_node_connectivity (n_edge, two) int64 173kB 0 8 0 ... 5400 5400 5401
Therefore, I also modified the test constants in
test/constants.py. Could you please verify if the new test parameters look good? The modifications are in the zonal-mean branch.If this solution to the
test_api.pybug is acceptable, then PR#785 is also ready for review. :)erogluorhan commentedon Jul 30, 2024
Yes, this looks like a good solution to me; thanks a lot! Hey @philipc2 , do you agree with me that this will be a better solution forward?
philipc2 commentedon Mar 18, 2025
@rajeeja
Can you check if this is fixed?
rajeeja commentedon Mar 24, 2025
fixed, no hardcoded paths.