From b026b4e08b7147ee7e71ff5622f13913cdcaa99d Mon Sep 17 00:00:00 2001 From: Rich Atkinson Date: Tue, 9 Jun 2020 19:01:31 +1000 Subject: [PATCH] Fix for pandas 1.0 (#124) * as_matrix was depricated then removed. to_numpy() works in this situation * updated travis to include pandas 1.0.x, python 3.7 numpy 1.18 and scipy 1.4.x - kept a python 2.7 with the last supported versions of pydata. * versions compatible with conda for travis * old scipy and numpy * old scipy and numpy * old scipy and numpy * old scipy and numpy * old scipy and numpy * old scipy and numpy * who uses 3.5 anyway * Fix for pandas 1.0 * as_matrix was deprecated then removed. to_numpy() works in this situation * updated travis to include pandas 1.0.x, python 3.7 numpy 1.18 and scipy 1.4.x * kept a python 2.7 build with the last supported versions of pydata. * versions compatible with conda for travis * try except branch to support old pandas as required by zipline * as_matrix() not to_matrix() - thanks again Travis. Co-authored-by: Rich Atkinson --- .travis.yml | 14 +++++++------- empyrical/stats.py | 8 +++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index e04c8bd..714ed45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,17 +4,17 @@ sudo: false matrix: include: - python: 2.7 - env: PANDAS_VERSION=0.18.1 NUMPY_VERSION=1.11.1 SCIPY_VERSION=0.17.1 LIBGFORTRAN_VERSION=3.0 - - python: 2.7 - env: PANDAS_VERSION=0.19.2 NUMPY_VERSION=1.12.1 SCIPY_VERSION=0.19.0 LIBGFORTRAN_VERSION=3.0 + env: PANDAS_VERSION=0.24.2 NUMPY_VERSION=1.12.1 SCIPY_VERSION=1.2.1 LIBGFORTRAN_VERSION=3.0 - python: 2.7 env: PANDAS_VERSION=0.20.1 NUMPY_VERSION=1.12.1 SCIPY_VERSION=0.19.0 LIBGFORTRAN_VERSION=3.0 - - python: 3.5 - env: PANDAS_VERSION=0.18.1 NUMPY_VERSION=1.11.1 SCIPY_VERSION=0.17.1 LIBGFORTRAN_VERSION=3.0 - - python: 3.5 - env: PANDAS_VERSION=0.19.2 NUMPY_VERSION=1.12.1 SCIPY_VERSION=0.19.0 LIBGFORTRAN_VERSION=3.0 + - python: 3.6 + env: PANDAS_VERSION=1.0.4 NUMPY_VERSION=1.18.4 SCIPY_VERSION=1.4.1 LIBGFORTRAN_VERSION=3.0 - python: 3.6 env: PANDAS_VERSION=0.20.1 NUMPY_VERSION=1.12.1 SCIPY_VERSION=0.19.0 LIBGFORTRAN_VERSION=3.0 + - python: 3.6 + env: PANDAS_VERSION=1.0.4 NUMPY_VERSION=1.18.4 SCIPY_VERSION=1.4.1 LIBGFORTRAN_VERSION=3.0 + - python: 3.7 + env: PANDAS_VERSION=1.0.4 NUMPY_VERSION=1.18.4 SCIPY_VERSION=1.4.1 LIBGFORTRAN_VERSION=3.0 before_install: # We do this conditionally because it saves us some downloading if the diff --git a/empyrical/stats.py b/empyrical/stats.py index 2713edf..45e7d69 100644 --- a/empyrical/stats.py +++ b/empyrical/stats.py @@ -1747,7 +1747,13 @@ def gpd_risk_estimates_aligned(returns, var_p=0.01): DEFAULT_THRESHOLD = 0.2 MINIMUM_THRESHOLD = 0.000000001 - returns_array = pd.Series(returns).as_matrix() + + try: + returns_array = pd.Series(returns).to_numpy() + except AttributeError: + # while zipline requires support for pandas < 0.25 + returns_array = pd.Series(returns).as_matrix() + flipped_returns = -1 * returns_array losses = flipped_returns[flipped_returns > 0] threshold = DEFAULT_THRESHOLD