Skip to content

Commit fd790e9

Browse files
author
Kirsi-Marja Zitting
committed
Fix Crespo issues with modern Pandas versions
The pd.date_range() argument "closed" was deprecated in Pandas 1.4 with "inclusive" as the preferred replacement. See pandas-dev/pandas#40245. The expanding() argument "center" was deprecated in Pandas 1.1 as "non-sensical" with no replacement. See pandas-dev/pandas#20647. As discussed in that issue, I believe the use of center=True is a bug in the Crespo implementation, and removing it is the right thing to do. Both of these deprecated arguments were removed in Pandas 2.0, so this change is needed to make Crespo work with recent Pandas versions. To ensure no breakage because of this change, I'm adding a pandas>=1.4.0 dependency version constraint to ensure the presence of the "inclusive" argument to pd.date_range().
1 parent cce641b commit fd790e9

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

pyActigraphy/sleep/scoring_base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _padded_data(data, value, periods, frequency):
6565
end=data.index[0],
6666
periods=periods,
6767
freq=date_offset,
68-
closed='left'
68+
inclusive='left'
6969
),
7070
dtype=data.dtype
7171
)
@@ -75,7 +75,7 @@ def _padded_data(data, value, periods, frequency):
7575
start=data.index[-1],
7676
periods=periods,
7777
freq=date_offset,
78-
closed='right'
78+
inclusive='right'
7979
),
8080
dtype=data.dtype
8181
)
@@ -1384,12 +1384,10 @@ def Crespo(
13841384
# symmetrical anymore. In the regions (start, start+alpha/2,
13851385
# the median needs to be calculate by hand.
13861386
# The range is start, start+alpha as the window is centered.
1387-
median_start = x_sp.iloc[0:L_w].expanding(
1388-
center=True
1389-
).median()
1387+
median_start = x_sp.iloc[0:L_w].expanding().median()
13901388
median_end = x_sp.iloc[-L_w-1:-1].sort_index(
13911389
ascending=False
1392-
).expanding(center=True).median()[::-1]
1390+
).expanding().median()[::-1]
13931391

13941392
# replace values in the original x_fa series with the new values
13951393
# within the range (start, start+alpha/2) only.

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ def find_version(*file_paths):
106106
# For an analysis of "install_requires" vs pip's requirements files see:
107107
# https://packaging.python.org/en/latest/requirements.html
108108
install_requires=[
109-
'joblib', 'lmfit', 'pandas', 'plotly', 'numba', 'numpy', 'pyexcel',
110-
'pyexcel-ods3', 'pyexcel-xlsx', 'scipy', 'spm1d', 'statsmodels>=0.10',
111-
'stochastic>=0.6.0', 'accelerometer>=6.2.2'
109+
'joblib', 'lmfit', 'pandas>=1.4.0', 'plotly', 'numba', 'numpy',
110+
'pyexcel', 'pyexcel-ods3', 'pyexcel-xlsx', 'scipy', 'spm1d',
111+
'statsmodels>=0.10', 'stochastic>=0.6.0', 'accelerometer>=6.2.2'
112112
], # Optional
113113

114114
# Data files included in your packages that need to be installed.

0 commit comments

Comments
 (0)