Skip to content
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

misc fixes #159

Merged
merged 2 commits into from
May 3, 2024
Merged

misc fixes #159

merged 2 commits into from
May 3, 2024

Conversation

timcera
Copy link
Contributor

@timcera timcera commented Apr 30, 2024

Fixes

  • Allow the HDF filename to be passed to main function instead of only io_manager instance. Having main only accept io_manager broke all ipython notebooks.
  • Removed "print(table)" from readUCI which I think was a debugging statement.

IPython Notebook Fixes

  • Edited some of the ipython notebooks that tried to find an element time-series with an old name, for example tried to find "SURO" instead of the new name "SURO_sum".
  • Edited some of the ipython notebooks so that filenames were case sensitive.

Deprecations

  • The append function is no longer available for DataFrames and changed to pd.concat form.
  • In pandas 3.0, to_hdf will require the "key" to be a keyword argument instead of a positional argument and made that change now to silence the deprecation message.

Format

  • Removed trailing spaces from some files.
  • Fixed not a multiple of 4 spaces indentation in at least one file.
  • Renamed files with spaces in their names, replacing spaces with "_".

Documentation

  • Additional edits to the README.rst.
  • Reshaped some docstrings into Numpy format.

Fixes
* Allow the HDF filename to be passed to main function instead
  of only io_manager instance.  Having main only accept io_manager
  broke all ipython notebooks.
* Removed "print(table)" from readUCI which I think was a
  debugging statement.
IPython Notebook Fixes
* Edited some of the ipython notebooks that tried to find an
  element time-series with an old name, for example tried to
  find "SURO" instead of the new name "SURO_sum".
* Edited some of the ipython notebooks so that filenames were
  case sensitive.
Deprecations
* The append function is no longer available for DataFrames and
  changed to pd.concat form.
* In pandas 3.0, to_hdf will require the "key" to be a keyword
  argument instead of a positional argument and made that change
  now to silence the deprecation message.
Format
* Removed trailing spaces from some files.
* Fixed not a multiple of 4 spaces indentation in at least one file.
* Renamed files with spaces in their names, replacing spaces with "_".
Documentation
* Additional edits to the README.rst.
* Reshaped some docstrings into Numpy format.
@timcera
Copy link
Contributor Author

timcera commented Apr 30, 2024

I was sitting on these changes because I couldn't find solutions to two problems. So thought to put this in a pull request for review and maybe someone will be able to figure them out.

Another reason to get this out there, is for the next two weeks or so I won't be able to work on this and I didn't want to slow progress down.

"pytest" works to test the new PWATER and IWATER tests. They both pass.

THE PROBLEMS:

  1. Right now, using python 3.10 and a "pip install ." with the code in this pull request, the "readUCI" function in tests/test05/HSP2results/CompareHSP2.ipynb will only bring in the PERLND operation. IMPLND and RCHRES are ignored. No errors. I can't figure it out.

  2. In tests/test10/HSP2results/TEST10_hsp2_compare.ipynb, when it is calculating RQUAL I get the error:

...
File [~/anaconda3/envs/hsp2_310/lib/python3.10/site-packages/HSP2/RQUAL.py:225](http://localhost:8888/home/tim/anaconda3/envs/hsp2_310/lib/python3.10/site-packages/HSP2/RQUAL.py#line=224), in rqual(io_manager, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts, monthdata)
    218 		ts['BINV'] = initm(siminfo, ui_plank, binvfg, 'MONTHLY[/BINV](http://localhost:8888/BINV)', binv_init)
    220 #---------------------------------------------------------------------
    221 # initialize & run integerated WQ simulation:
    222 #---------------------------------------------------------------------
    224 (err_oxrx, err_nutrx, err_plank, err_phcarb) \
--> 225 	= _rqual_run(siminfo_, ui, ui_oxrx, ui_nutrx, ui_plank, ui_phcarb, ts)
    227 #---------------------------------------------------------------------
    228 # compile errors & return:
    229 #---------------------------------------------------------------------
    231 (errors, ERRMSGS) = _compile_errors(NUTFG, PLKFG, PHFG, err_oxrx, err_nutrx, err_plank, err_phcarb)

SystemError: CPUDispatcher(<function _rqual_run at 0x7f67104b8ee0>) returned NULL without setting an exception

pyproject.toml Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timcera can we remove the ‘exclude’ line below since the includes are explicit? I think we can also drop the ‘where’ line too since ‘here’ is the default. Works great in my testing to be less explicit here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Now "import this" says explicit is better than implicit, just saying... 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in complete agreement with the 'import this' philosophy, that's actually why I suggested removing all the extra over-constrained instructions with an explicit include, bc it leads to confusion to have lots of dead code in our packaging. no-ops should not exist in a pyproject.toml.

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.

^this is the case against having extra params here, not for it 😅

subprocess.run(shlex.split("python3 -m build --wheel"), check=True)
sdist = f"dist/{PKG_NAME}-{version}.tar.gz"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this script run now? Sdist is still in the list below, so I’d expect it to throw. I think we should publish sdist, so I’d revert this line change and keep it in the twine iterator.

we should probably also rm all files in ‘dist’ similar to how we clear out ‘build’ too, right? If we are publishing from CI only, then this doesn’t matter, but if we are publishing from desktop then it matters a lot.

let’s make sure top level build and dist are in gitignore (I think they are) and do a full clean of those folders via this script before publishing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll remove sdist from the list. I probably keep the loop and revisit adding sdist later. I'll push a commit in a bit...

Copy link
Contributor Author

@timcera timcera Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About removing all file in "dist". I don't automatically remove with my own packages and it hasn't proven to be a problem. After a while they might stack up and I remove by hand just to clean things up. This script is really just a convenience for the couple of developers that would publish to PyPI. Probably should find another directory for it to make it less visible? That is something that I thought could wait.


from HSP2.main import main
from HSP2.mainDoE import main as mainDoE
from HSP2.utilities import versions, flowtype
from _version import __version__

__version__ = version("hsp2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL importlib judo. this is a nice solution.

@timcera
Copy link
Contributor Author

timcera commented Apr 30, 2024

I can make the shift to a "src/hsp2/..." package tonight that was talked about in #157.

@austinorr
Copy link
Contributor

I can make the shift to a "src/hsp2/..." package tonight that was talked about in #157.

We should let @PaulDudaRESPEC catch up on merging some of these PR's and/or asking you or I to rebase our already open PRs before we go ahead and change literally every file in the project.

Also @rburghol has significant WIP that we should consider helping to support integrating before making major refactoring changes.

@PaulDudaRESPEC This is where an order of operations and/or roadmap with a todo list would help, otherwise we'll end up constantly overwriting each other and working on the same things in parallel. Also, we should temporarily disable the conda github action -- it never completes.

@timcera
Copy link
Contributor Author

timcera commented Apr 30, 2024

Fine by me.

@austinorr
Copy link
Contributor

austinorr commented Apr 30, 2024

@timcera is this PR otherwise ready to merge in your opinion? If so, i'll rebase mine on this one, and @PaulDudaRESPEC can work the backlog a bit so we can all get the benefit of the improvements you've made here. Thank you!

@timcera
Copy link
Contributor Author

timcera commented May 1, 2024

Depends. Still have the two problems that I mentioned in the second comment. In terms of git repository management it might be best to get this one merged and then address those problems in a separate pull request. Up to @PaulDudaRESPEC on path forward.

@austinorr
Copy link
Contributor

@timcera i agree, let’s merge this and move on of your only issues are in the ./tests dir. tests are probably due for a refactor anyway so that they work with pytest.

@PaulDudaRESPEC looks like this is blessed by Tim and ready for review & merge into dev

@PaulDudaRESPEC
Copy link
Member

I was sitting on these changes because I couldn't find solutions to two problems. So thought to put this in a pull request for review and maybe someone will be able to figure them out.

Another reason to get this out there, is for the next two weeks or so I won't be able to work on this and I didn't want to slow progress down.

"pytest" works to test the new PWATER and IWATER tests. They both pass.

THE PROBLEMS:

  1. Right now, using python 3.10 and a "pip install ." with the code in this pull request, the "readUCI" function in tests/test05/HSP2results/CompareHSP2.ipynb will only bring in the PERLND operation. IMPLND and RCHRES are ignored. No errors. I can't figure it out.
  2. In tests/test10/HSP2results/TEST10_hsp2_compare.ipynb, when it is calculating RQUAL I get the error:
...
File [~/anaconda3/envs/hsp2_310/lib/python3.10/site-packages/HSP2/RQUAL.py:225](http://localhost:8888/home/tim/anaconda3/envs/hsp2_310/lib/python3.10/site-packages/HSP2/RQUAL.py#line=224), in rqual(io_manager, siminfo, uci, uci_oxrx, uci_nutrx, uci_plank, uci_phcarb, ts, monthdata)
    218 		ts['BINV'] = initm(siminfo, ui_plank, binvfg, 'MONTHLY[/BINV](http://localhost:8888/BINV)', binv_init)
    220 #---------------------------------------------------------------------
    221 # initialize & run integerated WQ simulation:
    222 #---------------------------------------------------------------------
    224 (err_oxrx, err_nutrx, err_plank, err_phcarb) \
--> 225 	= _rqual_run(siminfo_, ui, ui_oxrx, ui_nutrx, ui_plank, ui_phcarb, ts)
    227 #---------------------------------------------------------------------
    228 # compile errors & return:
    229 #---------------------------------------------------------------------
    231 (errors, ERRMSGS) = _compile_errors(NUTFG, PLKFG, PHFG, err_oxrx, err_nutrx, err_plank, err_phcarb)

SystemError: CPUDispatcher(<function _rqual_run at 0x7f67104b8ee0>) returned NULL without setting an exception

@timcera , I've got some helpful info to share...

With regard to problem 1, Test05 only runs PERLND, not IMPLND or RCHRES, so I don't think that is a concern.

As for problem 2, I see an issue with the recent changes to readUCI.py. At line 88 in fix_df, we've gone to using concat instead of append, but the new way of doing it with concat is not equivalent to the old append. In this case concat is adding a new column to the df, where append was adding a new row. I reproduced the error, changed it back to the old way, and the old way worked. I don't see what the appropriate fix is moving forward, but I think it will be helpful to point this out.

@PaulDudaRESPEC
Copy link
Member

I got Test10 to run to completion using this code by @timcera and it matches what I believe to be the correct output values, but not without fixing a few things down in OXRX_class.py. It seems previous versions didn't have a problem with sending undefined variable names into RQUAL if those variables were never used, but now I see it triggering an error. So I've modified OXRX_class.py and will commit my changes to develop where I explicitly declare these variables.

PaulDudaRESPEC added a commit that referenced this pull request May 1, 2024
Copy link
Contributor

@austinorr austinorr May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pin pandas<2.0 to defer refactoring all the df.append() calls. If this project installed clean as-is without pinning to <2.0, nothing can work since df.append() has been removed.

df = df.append(Series(name=name1)) # add missing ids with NaNs
if df.isna().any().any(): # replace NaNs with defaults
df = pd.concat(
[df, pd.Series(name=name1)], axis="columns"
Copy link
Contributor

@austinorr austinorr May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong axis. old append does "Append rows of other to the end of caller," which is df.concat(other, axis='rows') or just df.concat(other)

@PaulDudaRESPEC PaulDudaRESPEC merged commit dc02461 into respec:develop May 3, 2024
0 of 3 checks passed
@PaulDudaRESPEC PaulDudaRESPEC mentioned this pull request May 7, 2024
rburghol pushed a commit to HARPgroup/HSPsquared that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants