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

Unpin numpy #258

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
os: [ubuntu-latest]
env:
OS: ${{ matrix.os }}
PYTHON: "3.11"
PYTHON: "3.12"

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12

- name: Install fmu-ensemble and test dependencies
run: |
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/fmu-ensemble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
numpy-version: ["numpy<2", "numpy>=2"]
exclude:
- python-version: "3.8"
numpy-version: "numpy>=2"
- python-version: "3.9"
numpy-version: "numpy>=2"
- python-version: "3.10"
numpy-version: "numpy<2"
- python-version: "3.12"
numpy-version: "numpy<2"

steps:
- name: 📖 Checkout commit locally
Expand All @@ -42,8 +52,14 @@ jobs:

- name: 📦 Install test dependencies
run: |
pip install res2df ecl2df
pip install res2df
pip install .[tests,docs]
pip install "${{ matrix.numpy-version }}"

- name: Install ecl2df
if: matrix.numpy-version == 'numpy<2'
run: |
pip install ecl2df

- name: 🧾 List all installed packages
run: pip freeze
Expand Down
10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: no-commit-to-branch
args: ['--branch', 'master']
Expand All @@ -13,14 +13,10 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
rev: v0.6.4
hooks:
- id: ruff
args: [ --extend-select, I, --fix ]

- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
- id: ruff-format

exclude: "tests/data/testensemble-reek001"
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

"""The setup script."""

from setuptools import find_packages, setup

with open("README.rst") as readme_file:
Expand All @@ -12,12 +13,12 @@

REQUIREMENTS = [
"resdata>=4.0.0",
"numpy<2",
"numpy",
"pandas",
"pyyaml>=5.1",
]

SETUP_REQUIREMENTS = ["setuptools>=28", "setuptools_scm"]
SETUP_REQUIREMENTS = ["setuptools>=65", "setuptools_scm"]

with open("test_requirements.txt") as f:
test_requirements = f.read().splitlines()
Expand Down Expand Up @@ -54,6 +55,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
test_suite="tests",
tests_require=test_requirements,
Expand Down
3 changes: 1 addition & 2 deletions src/fmu/ensemble/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,14 @@ def load_status(self):
status.fillna("", inplace=True)

errorjobs = status[errorcolumns[0]] != ""

# Merge any error strings:
error_string = (
status.loc[errorjobs, errorcolumns]
.astype(str)
.apply(" ".join, axis=1)
.apply(str.strip)
)
status["errorstring"] = np.nan
status["errorstring"] = pd.NA
status.loc[errorjobs, "errorstring"] = error_string
status.drop(errorcolumns, axis=1, inplace=True)

Expand Down
2 changes: 1 addition & 1 deletion src/fmu/ensemble/realizationcombination.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for handling linear combinations of realizations. """
"""Module for handling linear combinations of realizations."""

import fnmatch
import logging
Expand Down
9 changes: 2 additions & 7 deletions src/fmu/ensemble/virtualrealization.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,10 @@ def get_smry(self, column_keys=None, time_index="monthly"):
]
if cum_columns:
smry[cum_columns] = (
smry[cum_columns]
.interpolate(method="time")
.fillna(method="ffill")
.fillna(method="bfill")
smry[cum_columns].interpolate(method="time").ffill().bfill()
)
if noncum_columns:
smry[noncum_columns] = (
smry[noncum_columns].fillna(method="bfill").fillna(value=0)
)
smry[noncum_columns] = smry[noncum_columns].bfill().fillna(value=0)

smry.index = smry.index.set_names(["DATE"])
return smry.loc[pd.to_datetime(time_index_dt)]
Expand Down
1 change: 1 addition & 0 deletions tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

import yaml

from fmu.ensemble import EnsembleSet, ScratchEnsemble

logger = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime as dt

import pytest

from fmu.ensemble.util.dates import _fallback_date_roll, date_range

# These tests are duplicated from https://github.com/equinor/res2df/blob/master/tests/test_summary.py
Expand Down
15 changes: 9 additions & 6 deletions tests/test_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import logging
import os

import numpy
import numpy as np
import pandas as pd
import pytest
import yaml

from fmu.ensemble import ScratchEnsemble, ScratchRealization

from .test_ensembleset import symlink_iter
Expand Down Expand Up @@ -58,7 +59,7 @@ def test_reek001(tmpdir):
assert int(statusdf.loc[4, "RMS_BATCH"]["DURATION"].values[0]) == 195

# STATUS in real4 is modified to simulate that Eclipse never finished:
assert numpy.isnan(statusdf.loc[4, "ECLIPSE100_2014.2"]["DURATION"].values[0])
assert np.isnan(statusdf.loc[4, "ECLIPSE100_2014.2"]["DURATION"].values[0])

tmpdir.chdir()
statusdf.to_csv("status.csv", index=False)
Expand Down Expand Up @@ -284,13 +285,14 @@ def test_reek001_scalars():
assert "REAL" in npv
assert "npv.txt" in npv # filename is the column name
assert len(npv) == 5
assert npv.dtypes["REAL"] == int
assert npv.dtypes["npv.txt"] == object

assert npv.dtypes["REAL"] == np.int64
assert isinstance(npv.dtypes["npv.txt"], object)
# This is undesirable, can cause trouble with aggregation
# Try again:
reekensemble.load_scalar("npv.txt", force_reread=True, convert_numeric=True)
npv = reekensemble.get_df("npv.txt")
assert npv.dtypes["npv.txt"] == int or npv.dtypes["npv.txt"] == float
assert npv.dtypes["npv.txt"] in (np.int64, np.float64)
assert len(npv) == 4 # the error should now be removed

reekensemble.load_scalar("emptyscalarfile") # missing in real-4
Expand Down Expand Up @@ -542,7 +544,8 @@ def test_ensemble_ecl():
# For oil industry, p15 on FOPT should yield a larger value than p85.
# But the quantiles we get out follows the rest of the world
# so we check for the opposite.
assert df_stats["FOPT"]["p85"][-1] > df_stats["FOPT"]["p15"][-1]

assert df_stats["FOPT"]["p85"].iloc[-1] > df_stats["FOPT"]["p15"].iloc[-1]

with pytest.raises(ValueError):
reekensemble.get_smry_stats(
Expand Down
1 change: 1 addition & 0 deletions tests/test_ensemble_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
import pytest

from fmu.ensemble import ScratchEnsemble

logger = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions tests/test_ensemble_eclfail.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import numpy as np
import pandas as pd

from fmu.ensemble import ScratchEnsemble

logger = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions tests/test_ensemblecombination.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
import pytest

from fmu import ensemble

logger = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions tests/test_ensembleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pandas as pd
import pytest

from fmu.ensemble import EnsembleSet, ScratchEnsemble

try:
Expand Down
1 change: 1 addition & 0 deletions tests/test_etc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test a deprecated submodule"""

import pytest

from fmu import ensemble


Expand Down
1 change: 1 addition & 0 deletions tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pandas as pd
import pytest
import yaml

from fmu.ensemble import EnsembleSet, Observations, ScratchEnsemble, ScratchRealization

logger = logging.getLogger(__name__)
Expand Down
7 changes: 5 additions & 2 deletions tests/test_realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import pytest
import yaml
from dateutil.relativedelta import relativedelta
from fmu import ensemble
from resdata.summary import Summary

from fmu import ensemble

from .test_ensembleset import symlink_iter

try:
Expand Down Expand Up @@ -380,7 +381,9 @@ def test_volumetric_rates():
# Calculate cumulative production from the computed volumetric daily rates:
dayscum["FOPRcum"] = dayscum["FOPR"] * dayscum["DIFFDAYS"]
# Check that this sum is equal to FOPT between first and last date:
assert dayscum["FOPRcum"].sum() == pytest.approx(dcum["FOPT"][-1] - dcum["FOPT"][0])
assert dayscum["FOPRcum"].sum() == pytest.approx(
dcum["FOPT"].iloc[-1] - dcum["FOPT"].iloc[0]
)
# (here we could catch an error in case we don't support leap days)

# Monthly rates between the random dates:
Expand Down
1 change: 1 addition & 0 deletions tests/test_realizationcombination.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

import pytest

from fmu import ensemble
from fmu.ensemble import ScratchEnsemble

Expand Down
1 change: 1 addition & 0 deletions tests/test_res2df.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

import pytest

from fmu.ensemble import ScratchEnsemble, ScratchRealization

HAVE_RES2DF = True
Expand Down
1 change: 1 addition & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import pytest

from fmu.ensemble.util import flatten, parse_number, shortcut2path
from fmu.ensemble.util.dates import normalize_dates
from fmu.ensemble.util.rates import cumcolumn_to_ratecolumn
Expand Down
1 change: 1 addition & 0 deletions tests/test_virtualensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import pandas as pd
import pytest

from fmu.ensemble import ScratchEnsemble, VirtualEnsemble

try:
Expand Down
1 change: 1 addition & 0 deletions tests/test_virtualrealization.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np
import pandas as pd
import pytest

from fmu import ensemble
from fmu.ensemble.virtualrealization import smry_cumulative

Expand Down
Loading