9505-PNNL / wmpy_power

BSD 2-Clause "Simplified" License
1 stars 1 forks source link

Numpy AttributeError #2

Closed ijbd closed 4 weeks ago

ijbd commented 1 month ago

OS / Windows 11 Python / 3.11.5 wmpy-power / 1.0.1 numpy / 2.1.1

I was able to complete the installation steps, but I receive the following output from running the first cell in tutorial.ipynb:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 6
      4 import matplotlib.pyplot as plt
      5 import psutil
----> 6 from wmpy_power import Model
      7 from wmpy_power.utilities import download_data

File ~\Desktop\professional\joss\wmpy_power\env\Lib\site-packages\wmpy_power\__init__.py:2
      1 __version__ = "1.0.1"
----> 2 from .model import Model

File ~\Desktop\professional\joss\wmpy_power\env\Lib\site-packages\wmpy_power\model.py:30
     26     from yaml import Loader
     28 import warnings
---> 30 class Model:
     32     config_defaults = dict(
     33         output_path=Path("."),
     34         output_type="parquet",
   (...)
     65         parallel_tasks=cpu_count(logical=False),
     66     )
     68     def __init__(
     69         self,
     70         configuration_file: Union[str, Path] = None,
   (...)
    110         parallel_tasks: int = None,
    111     ):

File ~\Desktop\professional\joss\wmpy_power\env\Lib\site-packages\wmpy_power\model.py:744, in Model()
    730         kge = np.sqrt(
    731             ((np.corrcoef(observed_generation, monthly_generation)[0, 1] - 1) ** 2)
    732             + (((np.std(monthly_generation) / np.std(observed_generation)) - 1) ** 2)
    733             + (((np.mean(monthly_generation) / np.mean(observed_generation)) - 1) ** 2)
    734         )
    736     return kge
    738 @staticmethod
    739 def get_generation(
    740     calibration_parameters_path: str,
    741     reservoir_parameters_path: str,
    742     flow_and_storage_path: str,
    743     run_name: str,
--> 744     start_year: int = -np.Inf,
    745     end_year: int = np.Inf,
    746     write_output: bool = True,
    747     output_csv: bool = True,
    748     output_path: str = '.',
    749     parallel_tasks: int = cpu_count(logical=False),
    750 ) -> pd.DataFrame:
    751     """
    752     Calculates the monthly generation by plant based on the provided parameters and flows
    753     :param calibration_parameters_path: glob to parquet or csv files containing the calibration parameters
   (...)
    762     :param parallel_tasks: number of tasks to run in parallel
    763     """
    764     # load calibration params

File ~\Desktop\professional\joss\wmpy_power\env\Lib\site-packages\numpy\__init__.py:414, in __getattr__(attr)
    411     raise AttributeError(__former_attrs__[attr], name=None)
    413 if attr in __expired_attributes__:
--> 414     raise AttributeError(
    415         f"`np.{attr}` was removed in the NumPy 2.0 release. "
    416         f"{__expired_attributes__[attr]}",
    417         name=None
    418     )
    420 if attr == "chararray":
    421     warnings.warn(
    422         "`np.chararray` is deprecated and will be removed from "
    423         "the main namespace in the future. Use an array with a string "
    424         "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

AttributeError: `np.Inf` was removed in the NumPy 2.0 release. Use `np.inf` instead.
ijbd commented 1 month ago

I made the code modifications, but I'm unable to open a pull request (git push is giving me a permission denied error). Do you know if any repository settings need to be changed?

ijbd commented 1 month ago

openjournals/joss-reviews#7225

thurber commented 1 month ago

Hi @ijbd, thanks for reviewing and for the feedback! numpy v2 wasn't around yet when we were writing this, so there may be other things that break with it. If that ends up being the case, may be best to manually install numpy v1.26.4 into the environment (and i can update the dependency to reflect that).

I think you should be able to fork the repo into your account, push to that, and open a PR from there. But I'm also happy to make the code changes as needed. Heads up that I'm traveling for the next week or so and may be slow to respond, but will do my best to keep you unblocked from your review!

ijbd commented 1 month ago

Thanks, @thurber! I am squeezing in time after work, so I apologize for the inconsistent review pace. I opened a PR that ran successfully with the unit tests provided. Is that enough to conclude that numpy 2.0 will be compatible with the rest of the code?

thurber commented 1 month ago

I believe so, thanks for doing that!

ijbd commented 4 weeks ago

Resolved with #3