Skip to content

Commit

Permalink
Change np.NaN to np.nan
Browse files Browse the repository at this point in the history
Prep for supporting numpy 2.0 (np.NaN deprecated in numpy
2.0).
  • Loading branch information
maread99 committed Jun 25, 2024
1 parent 2f85f48 commit 281a025
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/market_prices/prices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,7 @@ def _set_indexes_status(self):
indices_aligned = self._indices_aligned[bi]
for session, start, end in zip(sessions, session_opens, session_opens_next):
if not indices_aligned[session]:
status[session] = np.NaN
status[session] = np.nan
continue
bv = (all_in_left_nanos >= start.value) & (
all_in_right_nanos <= end.value
Expand Down Expand Up @@ -4649,7 +4649,7 @@ def _price_at_from_daily(
c = self.calendars[s]
sdf = table[s].dropna()
if sdf.empty:
d[s] = np.NaN
d[s] = np.nan
continue
v = None
if set_indice_to_now:
Expand Down
4 changes: 2 additions & 2 deletions src/market_prices/pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ def _are_trading_sessions(
elif len(dates) == len(sessions) and (dates == sessions).all():
return True
else:
return np.NaN
return np.nan

@functools.cache
@parse
Expand Down Expand Up @@ -2625,7 +2625,7 @@ def close_at(self, date: mptypes.DateTimestamp) -> pd.DataFrame:
For symbols where `date` represents a trading session, price will
be as at session close. For all other symbols price is as at
previous close (or np.NaN if prices table starts later than the
previous close (or np.nan if prices table starts later than the
previous close).
Note: only available over range of index defined by sessions
Expand Down
74 changes: 37 additions & 37 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ def f(
return m.fill_reindexed(df, cal, mock_bi, mock_symbol, "Yahoo")

ohlcv = (
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[1.4, 1.8, 1.2, 1.6, 11],
[2.4, 2.8, 2.2, 2.6, 22],
[3.4, 3.8, 3.2, 3.6, 33],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[8.4, 8.8, 8.2, 8.6, 88],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[10.4, 10.8, 10.2, 10.6, 101],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
)
index = pd.DatetimeIndex(
[
Expand Down Expand Up @@ -176,9 +176,9 @@ def f(

ohlcv = (
[0.4, 0.8, 0.2, 0.6, 1],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[2.4, 2.8, 2.2, 2.6, 22],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[4.4, 4.8, 4.2, 4.6, 44],
)

Expand All @@ -203,9 +203,9 @@ def f(
[0.4, 0.8, 0.2, 0.6, 1],
[1.4, 1.8, 1.2, 1.6, 11],
[2.4, 2.8, 2.2, 2.6, 22],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[6.4, 6.8, 6.2, 6.6, 66],
[7.4, 7.8, 7.2, 7.6, 77],
[8.4, 8.8, 8.2, 8.6, 88],
Expand Down Expand Up @@ -252,9 +252,9 @@ def f(
# when prices for a first day are missing, verify raises warning and
# fills back from next open.
ohlcv = (
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[3.4, 3.8, 3.2, 3.6, 33],
[4.4, 4.8, 4.2, 4.6, 44],
[5.4, 5.8, 5.2, 5.6, 55],
Expand Down Expand Up @@ -291,24 +291,24 @@ def f(
# verify raises warning and fills both ways (as noted above) for both xlon and
# xasx (i.e. crossing UTC midnight, which involves different code path).
ohlcv = (
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[1.4, 1.8, 1.2, 1.6, 11],
[2.4, 2.8, 2.2, 2.6, 22],
[3.4, 3.8, 3.2, 3.6, 33],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[6.4, 6.8, 6.2, 6.6, 66],
[7.4, 7.8, 7.2, 7.6, 77],
[8.4, 8.8, 8.2, 8.6, 88],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
)
index = pd.DatetimeIndex(
[
Expand Down Expand Up @@ -419,15 +419,15 @@ def match(sessions: pd.DatetimeIndex | list[str]) -> str:
]
)
ohlcv = (
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[1.4, 1.8, 1.2, 1.6, 11],
[2.4, 2.8, 2.2, 2.6, 22],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[5.4, 5.8, 5.2, 5.6, 55],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[7.4, 7.8, 7.2, 7.6, 77],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
)

df = pd.DataFrame(ohlcv, index=index, columns=columns)
Expand Down Expand Up @@ -473,7 +473,7 @@ def match(sessions: pd.DatetimeIndex | list[str]) -> str:
warnings.warn(warnings_[0])

missing_row = pd.DataFrame(
[[np.NaN] * 5], index=index[-1:], columns=columns, dtype="float64"
[[np.nan] * 5], index=index[-1:], columns=columns, dtype="float64"
)
expected = pd.concat([expected[:-1], missing_row])
assert_frame_equal(rtrn, expected)
Expand Down Expand Up @@ -502,7 +502,7 @@ def match(sessions: pd.DatetimeIndex | list[str]) -> str:
[5.4, 5.8, 5.2, 5.6, 55],
[6.4, 6.8, 6.2, 6.6, 66],
[7.4, 7.8, 7.2, 7.6, 77],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
)
df = pd.DataFrame(ohlcv, index=index, columns=columns)
rtrn, _ = f(df.copy(), xlon)
Expand All @@ -527,8 +527,8 @@ def match(sessions: pd.DatetimeIndex | list[str]) -> str:

# verify that missing prices before mindate are not filled and no warning raised
ohlcv = (
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.NaN, np.NaN, np.NaN, np.NaN, np.NaN],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan],
[2.4, 2.8, 2.2, 2.6, 22],
[3.4, 3.8, 3.2, 3.6, 33],
[4.4, 4.8, 4.2, 4.6, 44],
Expand Down Expand Up @@ -2383,7 +2383,7 @@ def assert_all_same(
sessions = get_sessions(prices, bi)
xasx_sessions, xhkg_sessions = get_calendars_sessions(prices, bi, [xasx, xhkg])
# ...on a normal day sessions will conflict
expected = pd.Series(np.NaN, index=sessions, dtype="object")
expected = pd.Series(np.nan, index=sessions, dtype="object")
# ...but if xasx open and xhkg closed, no partial indices
expected[xasx_sessions.difference(xhkg_sessions)] = True
# ...whilst if xhkg open and xasx closed, always partial indices
Expand Down

0 comments on commit 281a025

Please sign in to comment.