forked from Unidata/MetPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandas.py
22 lines (18 loc) · 826 Bytes
/
pandas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Copyright (c) 2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Provide accessors to enhance interoperability between Pandas and MetPy."""
import functools
import pandas as pd
__all__ = []
def preprocess_pandas(func):
"""Decorate a function to convert all data series arguments to `np.ndarray`."""
@functools.wraps(func)
def wrapper(*args, **kwargs):
# not using hasattr(a, values) because it picks up dict.values()
# and this is more explicitly handling pandas
args = tuple(a.values if isinstance(a, pd.Series) else a for a in args)
kwargs = {name: (v.values if isinstance(v, pd.Series) else v)
for name, v in kwargs.items()}
return func(*args, **kwargs)
return wrapper