chore: Replace np.NAN with np.nan

properly implements what #10402 tried to do.
This commit is contained in:
Matthias
2024-07-05 07:46:27 +02:00
parent 53043d1978
commit ab0fd461ed
+11 -11
View File
@@ -11,7 +11,7 @@ from typing import Any, Dict, Generator, List, Optional, Sequence, Tuple, Union
import psutil import psutil
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from dateutil.tz import tzlocal from dateutil.tz import tzlocal
from numpy import NAN, inf, int64, mean from numpy import inf, int64, mean, nan
from pandas import DataFrame, NaT from pandas import DataFrame, NaT
from sqlalchemy import func, select from sqlalchemy import func, select
@@ -204,9 +204,9 @@ class RPC:
trade.pair, side="exit", is_short=trade.is_short, refresh=False trade.pair, side="exit", is_short=trade.is_short, refresh=False
) )
except (ExchangeError, PricingError): except (ExchangeError, PricingError):
current_rate = NAN current_rate = nan
if len(trade.select_filled_orders(trade.entry_side)) > 0: if len(trade.select_filled_orders(trade.entry_side)) > 0:
current_profit = current_profit_abs = current_profit_fiat = NAN current_profit = current_profit_abs = current_profit_fiat = nan
if not isnan(current_rate): if not isnan(current_rate):
prof = trade.calculate_profit(current_rate) prof = trade.calculate_profit(current_rate)
current_profit = prof.profit_ratio current_profit = prof.profit_ratio
@@ -277,7 +277,7 @@ class RPC:
raise RPCException("no active trade") raise RPCException("no active trade")
else: else:
trades_list = [] trades_list = []
fiat_profit_sum = NAN fiat_profit_sum = nan
for trade in trades: for trade in trades:
# calculate profit and send message to user # calculate profit and send message to user
try: try:
@@ -285,9 +285,9 @@ class RPC:
trade.pair, side="exit", is_short=trade.is_short, refresh=False trade.pair, side="exit", is_short=trade.is_short, refresh=False
) )
except (PricingError, ExchangeError): except (PricingError, ExchangeError):
current_rate = NAN current_rate = nan
trade_profit = NAN trade_profit = nan
profit_str = f"{NAN:.2%}" profit_str = f"{nan:.2%}"
else: else:
if trade.nr_of_successful_entries > 0: if trade.nr_of_successful_entries > 0:
profit = trade.calculate_profit(current_rate) profit = trade.calculate_profit(current_rate)
@@ -533,9 +533,9 @@ class RPC:
trade.pair, side="exit", is_short=trade.is_short, refresh=False trade.pair, side="exit", is_short=trade.is_short, refresh=False
) )
except (PricingError, ExchangeError): except (PricingError, ExchangeError):
current_rate = NAN current_rate = nan
profit_ratio = NAN profit_ratio = nan
profit_abs = NAN profit_abs = nan
else: else:
_profit = trade.calculate_profit(trade.close_rate or current_rate) _profit = trade.calculate_profit(trade.close_rate or current_rate)
@@ -1317,7 +1317,7 @@ class RPC:
# replace NaT with `None` # replace NaT with `None`
dataframe[date_column] = dataframe[date_column].astype(object).replace({NaT: None}) dataframe[date_column] = dataframe[date_column].astype(object).replace({NaT: None})
dataframe = dataframe.replace({inf: None, -inf: None, NAN: None}) dataframe = dataframe.replace({inf: None, -inf: None, nan: None})
res = { res = {
"pair": pair, "pair": pair,