Skip to content

Commit 761ee3a

Browse files
committed
Found problem with pandas 2.2.0, fixed, resolves #128
1 parent e26f3df commit 761ee3a

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

cvxportfolio/data.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@ def _clean(data):
306306
# print(data.isnull().sum())
307307

308308
# if low is not the lowest, set it to nan
309-
data['low'].loc[
310-
data['low'] > data[['open', 'high', 'close']].min(1)] = np.nan
309+
data.loc[data['low'] > data[['open', 'high', 'close']].min(1),
310+
'low'] = np.nan
311311

312312
# if high is not the highest, set it to nan
313-
data['high'].loc[
314-
data['high'] < data[['open', 'high', 'close']].max(1)] = np.nan
313+
data.loc[data['high'] < data[['open', 'high', 'close']].max(1),
314+
'high'] = np.nan
315315

316316
# print(data)
317317
# print(data.isnull().sum())
@@ -959,7 +959,8 @@ def _add_cash_column(self, cash_key, grace_period):
959959
# be misaligned (e.g., with tz-aware timestamps)
960960
cash_returns_per_period.name = self.cash_key
961961
original_returns_index = self.returns.index
962-
tmp = pd.concat([self.returns, cash_returns_per_period], axis=1)
962+
tmp = pd.concat(
963+
[self.returns, cash_returns_per_period], sort=True, axis=1)
963964
tmp[cash_key] = tmp[cash_key].ffill()
964965
self.returns = tmp.loc[original_returns_index]
965966

@@ -1082,9 +1083,8 @@ def _downsample(self, interval):
10821083

10831084
# we nan-out the first non-nan element of every col
10841085
for col in self.returns.columns[:-1]:
1085-
self.returns[col].loc[
1086-
(~(self.returns[col].isnull())).idxmax()
1087-
] = np.nan
1086+
self.returns.loc[
1087+
(~(self.returns[col].isnull())).idxmax(), col] = np.nan
10881088

10891089
# and we drop the first row, which is mostly NaNs anyway
10901090
self.returns = self.returns.iloc[1:]
@@ -1107,9 +1107,8 @@ def _downsample(self, interval):
11071107

11081108
# we nan-out the first non-nan element of every col
11091109
for col in self.volumes.columns:
1110-
self.volumes[col].loc[
1111-
(~(self.volumes[col].isnull())).idxmax()
1112-
] = np.nan
1110+
self.volumes.loc[
1111+
(~(self.volumes[col].isnull())).idxmax(), col] = np.nan
11131112

11141113
# and we drop the first row, which is mostly NaNs anyway
11151114
self.volumes = self.volumes.iloc[1:]
@@ -1129,9 +1128,8 @@ def _downsample(self, interval):
11291128

11301129
# we nan-out the first non-nan element of every col
11311130
for col in self.prices.columns:
1132-
self.prices[col].loc[
1133-
(~(self.prices[col].isnull())).idxmax()
1134-
] = np.nan
1131+
self.prices.loc[
1132+
(~(self.prices[col].isnull())).idxmax(), col] = np.nan
11351133

11361134
# and we drop the first row, which is mostly NaNs anyway
11371135
self.prices = self.prices.iloc[1:]

cvxportfolio/tests/test_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,17 @@ def _base_test_series(self, loader, storer):
203203
name="test2"),
204204
pd.Series("hello",
205205
pd.date_range("2020-01-01", "2020-01-02", tz='UTC-05:00',
206-
freq="H"),
206+
freq="h"),
207207
name="test3"),
208208
# test overwrite
209209
pd.Series("hello",
210-
pd.date_range("2020-01-01", "2020-01-02", tz='UTC', freq="H"),
210+
pd.date_range("2020-01-01", "2020-01-02", tz='UTC', freq="h"),
211211
name="test3"),
212212
# test datetime conversion
213213
pd.Series(
214214
pd.date_range("2022-01-01", "2022-01-02", tz='UTC',
215-
freq="H"),
216-
pd.date_range("2020-01-01", "2020-01-02", tz='UTC', freq="H"),
215+
freq="h"),
216+
pd.date_range("2020-01-01", "2020-01-02", tz='UTC', freq="h"),
217217
name="test4"),
218218
]:
219219

@@ -248,7 +248,7 @@ def _base_test_series(self, loader, storer):
248248
def _base_test_dataframe(self, loader, storer):
249249
"""Test storing and retrieving of a DataFrame with datetime index."""
250250

251-
index = pd.date_range("2020-01-01", "2020-01-02", freq="H", tz='UTC')
251+
index = pd.date_range("2020-01-01", "2020-01-02", freq="h", tz='UTC')
252252
data = {
253253
"one": range(len(index)),
254254
"two": np.arange(len(index)) / 19.0,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = {text = "Apache License (2.0)"}
77
authors = [{name = "Enzo Busseti"}, {name = "Stephen Boyd"},
88
{name = "Steven Diamond"}, {name = "BlackRock Inc."}]
99
maintainers = [{name = "Enzo Busseti", email = "[email protected]"}]
10-
dependencies = ["pandas<2.2.0", "numpy", "matplotlib", "requests", "cvxpy",
10+
dependencies = ["pandas", "numpy", "matplotlib", "requests", "cvxpy",
1111
"multiprocess"]
1212

1313
[project.optional-dependencies]

0 commit comments

Comments
 (0)