From b81220f26ca566cd1f131cc7f17c826320a96076 Mon Sep 17 00:00:00 2001 From: John Chase Date: Mon, 17 Dec 2018 09:05:00 -0800 Subject: [PATCH] MAINT: Makes compatible with latest pandas (#112) * MAINT: Makes compatible with latest pandas Fixes #111 Pandas changed the reduce functionality http://pandas.pydata.org/pandas-docs/stable/whatsnew.html?highlight=rolling_mean#changes-to-make-output-of-dataframe-apply-consistent the new api is backwards incompatible with >0.23.4. The changes in this pull request work with both versions of pandas. There may be a better way to achive this, though I think it is preferable to keep sourcetracker compatible with the recent versions of pandas * Added the replace flag back in * Added the replace flag back in * updated changelog --- ChangeLog.md | 1 + sourcetracker/_sourcetracker.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 38fa81a..235e225 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,7 @@ ## 2.0.1-dev (changes since 2.0.1 go here) + * Updated subsample function to be compatible with new version of pandas * A unified API for sourcetracking with Gibbs sampling, including leave-one-out cross-validation, has been created and is accessible as ``sourcetracker.gibbs``. diff --git a/sourcetracker/_sourcetracker.py b/sourcetracker/_sourcetracker.py index ed73ff3..894faee 100644 --- a/sourcetracker/_sourcetracker.py +++ b/sourcetracker/_sourcetracker.py @@ -231,8 +231,10 @@ def subsample_dataframe(df, depth, replace=False): pd.DataFrame Subsampled dataframe. ''' - f = partial(subsample_counts, n=depth, replace=replace) - return df.apply(f, axis=1, reduce=False, raw=False) + def subsample(x): + return pd.Series(subsample_counts(x.values, n=depth, replace=replace), + index=x.index) + return df.apply(subsample, axis=1) def generate_environment_assignments(n, num_sources):