From 281a025e99dc5f2c9e854a6771c5bcca103c89e9 Mon Sep 17 00:00:00 2001 From: Marcus Read Date: Tue, 25 Jun 2024 18:19:22 +0100 Subject: [PATCH] Change np.NaN to np.nan Prep for supporting numpy 2.0 (np.NaN deprecated in numpy 2.0). --- src/market_prices/prices/base.py | 4 +- src/market_prices/pt.py | 4 +- tests/test_base.py | 74 ++++++++++++++++---------------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/market_prices/prices/base.py b/src/market_prices/prices/base.py index 48efe0c..607ffa7 100644 --- a/src/market_prices/prices/base.py +++ b/src/market_prices/prices/base.py @@ -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 @@ -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: diff --git a/src/market_prices/pt.py b/src/market_prices/pt.py index e057d76..9210d5b 100644 --- a/src/market_prices/pt.py +++ b/src/market_prices/pt.py @@ -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 @@ -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 diff --git a/tests/test_base.py b/tests/test_base.py index 4f3bc1e..3cef3c4 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -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( [ @@ -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], ) @@ -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], @@ -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], @@ -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( [ @@ -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) @@ -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) @@ -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) @@ -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], @@ -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