Skip to content

Commit

Permalink
Address FutureWarnings from pandas 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Aug 30, 2023
1 parent ce6807a commit 52c4328
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions genno/core/attrseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def bfill(self, dim: Hashable, limit: Optional[int] = None):
# if needed use _maybe_groupby()
return self._replace(
self.unstack(dim)
.fillna(method="bfill", axis=1, limit=limit)
.bfill(axis=1, limit=limit)
.stack()
.reorder_levels(self.dims),
)
Expand Down Expand Up @@ -271,7 +271,7 @@ def ffill(self, dim: Hashable, limit: Optional[int] = None):
# if needed use _maybe_groupby()
return self._replace(
self.unstack(dim)
.fillna(method="ffill", axis=1, limit=limit)
.ffill(axis=1, limit=limit)
.stack()
.reorder_levels(self.dims),
)
Expand Down
5 changes: 5 additions & 0 deletions genno/tests/compat/test_pyam.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
# Skip this entire file if pyam is not installed
pyam = pytest.importorskip("pyam", reason="pyam-iamc not installed")

# Warning emitted by pandas ≥ 2.1.0 with pyam 1.9.0
pytestmark = pytest.mark.filterwarnings(
"ignore:.*unique with argument that is not.*:FutureWarning:pyam.core"
)


@pytest.fixture(scope="session")
def scenario():
Expand Down
7 changes: 7 additions & 0 deletions genno/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from inspect import Parameter, signature
from typing import Callable, Iterable, Mapping, MutableMapping, Tuple, Type, Union

import numpy as np
import pandas as pd
import pint
from dask.core import literal
Expand Down Expand Up @@ -95,6 +96,12 @@ def parse_units(data: Iterable, registry=None) -> pint.Unit:
"""
registry = registry or pint.get_application_registry()

# Ensure a type that is accepted by pd.unique()
if isinstance(data, str):
data = np.array([data])
elif not isinstance(data, (np.ndarray, pd.Index, pd.Series)):
data = np.array(data)

unit = pd.unique(data)

if len(unit) > 1:
Expand Down

0 comments on commit 52c4328

Please sign in to comment.