diff --git a/.github/workflows/test-pip.yml b/.github/workflows/test-pip.yml index 1426fc23..f3bc979e 100644 --- a/.github/workflows/test-pip.yml +++ b/.github/workflows/test-pip.yml @@ -14,8 +14,8 @@ jobs: display_name: "2020" deps: "numpy==1.19.* scipy==1.5.* matplotlib==3.3.* pandas==1.1.* tables==3.6.* scikit-learn==0.24.* numba==0.53.* llvmlite==0.36.*" - python: "3.10" - display_name: "2021" - deps: "numpy==1.22.* scipy==1.7.* matplotlib==3.5.* pandas==1.3.* tables==3.7.* scikit-learn==1.0.* numba==0.55.* llvmlite==0.38.*" + display_name: "2021ish" + deps: "numpy==1.22.* scipy==1.7.* matplotlib==3.5.* pandas==1.4.* tables==3.7.* scikit-learn==1.0.* numba==0.55.* llvmlite==0.38.*" - python: "3.11" display_name: "2022" deps: "numpy==1.24.* scipy==1.9.* matplotlib==3.6.* pandas==2.0.* tables==3.8.* scikit-learn==1.1.* numba==0.57.* llvmlite==0.40.*" @@ -39,7 +39,7 @@ jobs: python-version: ${{ matrix.python }} - name: Install HDF5 library - run: sudo apt-get install libhdf5-dev + run: sudo apt-get update && sudo apt-get install -y libhdf5-dev - name: Install python dependencies shell: bash diff --git a/trackpy/plots.py b/trackpy/plots.py index 685e0aa5..828542d4 100644 --- a/trackpy/plots.py +++ b/trackpy/plots.py @@ -6,6 +6,7 @@ import logging import numpy as np +from .utils import pandas_map try: from pims import plot_to_frame, plots_to_frame, normalize @@ -640,7 +641,7 @@ def subpx_bias(f, pos_columns=None): pos_columns = ['x', 'y', 'z'] else: pos_columns = ['x', 'y'] - axlist = f[pos_columns].applymap(lambda x: x % 1).hist() + axlist = pandas_map(f[pos_columns], lambda x: x % 1).hist() return axlist @make_axes diff --git a/trackpy/utils.py b/trackpy/utils.py index bbe1525e..e53baef4 100644 --- a/trackpy/utils.py +++ b/trackpy/utils.py @@ -24,6 +24,12 @@ is_pandas_since_023 = True +try: + is_pandas_since_210 = (LooseVersion(pd.__version__) >= + LooseVersion('2.1.0')) +except ValueError: # Probably a development version + is_pandas_since_210 = True + try: is_pandas_since_220 = (LooseVersion(pd.__version__) >= LooseVersion('2.2.0')) @@ -308,6 +314,14 @@ def _pandas_concat_post_023(*args, **kwargs): pandas_concat = pd.concat +def pandas_map(df, func): + """Apply func element-wise to a DataFrame (compat for pandas < 2.1).""" + if is_pandas_since_210: + return df.map(func) + else: + return df.applymap(func) + + def guess_pos_columns(f): """ Guess the position columns from a given feature DataFrame """ if 'z' in f: