AI4Finance-Foundation / AI4Finance-Foundation/FinRL-Meta

FinRL_PaperTrading_Demo.ipynb: TypeError: Invalid comparison between dtype=datetime64[ns] and Timestamp

Ouverte
#287 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
bug
Langage dominant
Python
Étoiles
1.9k
Forks
751
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I keep getting this error. All my Alpaca credentials are correct and that is the only thing i have touched in the notebook. Any help on what to do is appreciated.

data = DP.clean_data(data)
data = DP.add_technical_indicator(data, INDICATORS)
data = DP.add_vix(data)

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
[/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py](https://localhost:8080/#) in _validate_comparison_value(self, other)
563 try:
--> 564 self._check_compatible_with(other)
565

24 frames
[/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimes.py](https://localhost:8080/#) in _check_compatible_with(self, other)
521 def _check_compatible_with(self, other) -> None:
--> 522 if other is NaT:
523 return

[/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimes.py](https://localhost:8080/#) in _assert_tzawareness_compat(self, other)
743 # pd.NaT quacks both aware and naive
--> 744 pass
745 elif self.tz is None:

TypeError: Cannot compare tz-naive and tz-aware datetime-like objects.

The above exception was the direct cause of the following exception:

InvalidComparison Traceback (most recent call last)
[/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py](https://localhost:8080/#) in _cmp_method(self, other, op)
933
--> 934 try:
935 other = self._validate_comparison_value(other)

[/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py](https://localhost:8080/#) in _validate_comparison_value(self, other)
566 except (TypeError, IncompatibleFrequency) as err:
--> 567 # e.g. tzawareness mismatch
568 raise InvalidComparison(other) from err

InvalidComparison: 2003-04-13 00:00:00+00:00

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
[](https://localhost:8080/#) in ()
----> 1 data = DP.clean_data(data)
2 data = DP.add_technical_indicator(data, INDICATORS)
3 data = DP.add_vix(data)

[/usr/local/lib/python3.9/site-packages/finrl/meta/data_processor.py](https://localhost:8080/#) in clean_data(self, df)
44
45 def clean_data(self, df) -> pd.DataFrame:
---> 46 df = self.processor.clean_data(df)
47
48 return df

[/usr/local/lib/python3.9/site-packages/finrl/meta/data_processors/processor_alpaca.py](https://localhost:8080/#) in clean_data(self, df)
73 df = df[df.timestamp != time]
74
---> 75 trading_days = self.get_trading_days(start=self.start, end=self.end)
76 # produce full timestamp index
77 times = []

[/usr/local/lib/python3.9/site-packages/finrl/meta/data_processors/processor_alpaca.py](https://localhost:8080/#) in get_trading_days(self, start, end)
295
296 def get_trading_days(self, start, end):
--> 297 nyse = tc.get_calendar("NYSE")
298 df = nyse.sessions_in_range(
299 pd.Timestamp(start, tz=pytz.UTC), pd.Timestamp(end, tz=pytz.UTC)

[/usr/local/lib/python3.9/site-packages/exchange_calendars/calendar_utils.py](https://localhost:8080/#) in get_calendar(self, name, start, end, side)
284
285 cached = self._get_cached_factory_output(name, **kwargs)
--> 286 return cached if cached is not None else self._fabricate(name, **kwargs)
287
288 def get_calendar_names(

[/usr/local/lib/python3.9/site-packages/exchange_calendars/calendar_utils.py](https://localhost:8080/#) in _fabricate(self, name, **kwargs)
180 except KeyError as e:
181 raise InvalidCalendarName(calendar_name=name) from e
--> 182 calendar = factory(**kwargs)
183 self._factory_output_cache[name] = (calendar, kwargs)
184 return calendar

[/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py](https://localhost:8080/#) in __init__(self, start, end, side)
291 # Series mapping sessions with nonstandard opens/closes.
292 _special_opens = self._calculate_special_opens(start, end)
--> 293 _special_closes = self._calculate_special_closes(start, end)
294
295 # Overwrite the special opens and closes on top of the standard ones.

[/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py](https://localhost:8080/#) in _calculate_special_closes(self, start, end)
2593
2594 def _calculate_special_closes(self, start, end):
-> 2595 return self._special_dates(
2596 self.special_closes,
2597 self.special_closes_adhoc,

[/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py](https://localhost:8080/#) in _special_dates(self, calendars, ad_hoc_dates, start_date, end_date)
2542 """
2543 # List of Series for regularly-scheduled times.
-> 2544 regular = [
2545 scheduled_special_times(
2546 calendar,

[/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py](https://localhost:8080/#) in (.0)
2543 # List of Series for regularly-scheduled times.
2544 regular = [
-> 2545 scheduled_special_times(
2546 calendar,
2547 start_date,

[/usr/local/lib/python3.9/site-packages/exchange_calendars/exchange_calendar.py](https://localhost:8080/#) in scheduled_special_times(calendar, start, end, time, tz)
2840 ``time`` (as a UTC Timestamp).
2841 """
-> 2842 days = calendar.holidays(start, end)
2843 return pd.Series(
2844 index=pd.DatetimeIndex(days, tz=UTC),

[/usr/local/lib/python3.9/site-packages/pandas/tseries/holiday.py](https://localhost:8080/#) in holidays(self, start, end, return_name)
456 # get them again
457 if self._cache is None or start < self._cache[0] or end > self._cache[1]:
--> 458 pre_holidays = [
459 rule.dates(start, end, return_name=True) for rule in self.rules
460 ]

[/usr/local/lib/python3.9/site-packages/pandas/tseries/holiday.py](https://localhost:8080/#) in (.0)
457 if self._cache is None or start < self._cache[0] or end > self._cache[1]:
458 pre_holidays = [
--> 459 rule.dates(start, end, return_name=True) for rule in self.rules
460 ]
461 if pre_holidays:

[/usr/local/lib/python3.9/site-packages/pandas/tseries/holiday.py](https://localhost:8080/#) in dates(self, start_date, end_date, return_name)
284 )
285 holiday_dates = holiday_dates[
--> 286 (holiday_dates >= filter_start_date) & (holiday_dates <= filter_end_date)
287 ]
288 if return_name:

[/usr/local/lib/python3.9/site-packages/pandas/core/ops/common.py](https://localhost:8080/#) in new_method(self, other)
79 other = item_from_zerodim(other)
80
---> 81 return method(self, other)
82
83 return new_method

[/usr/local/lib/python3.9/site-packages/pandas/core/arraylike.py](https://localhost:8080/#) in __ge__(self, other)
58 @unpack_zerodim_and_defer("__ge__")
59 def __ge__(self, other):
---> 60 return self._cmp_method(other, operator.ge)
61
62 # -------------------------------------------------------------

[/usr/local/lib/python3.9/site-packages/pandas/core/indexes/base.py](https://localhost:8080/#) in _cmp_method(self, other, op)
6769
6770 elif isinstance(self._values, ExtensionArray):
-> 6771 result = op(self._values, other)
6772
6773 elif is_object_dtype(self.dtype) and not isinstance(self, ABCMultiIndex):

[/usr/local/lib/python3.9/site-packages/pandas/core/ops/common.py](https://localhost:8080/#) in new_method(self, other)
79 other = item_from_zerodim(other)
80
---> 81 return method(self, other)
82
83 return new_method

[/usr/local/lib/python3.9/site-packages/pandas/core/arraylike.py](https://localhost:8080/#) in __ge__(self, other)
58 @unpack_zerodim_and_defer("__ge__")
59 def __ge__(self, other):
---> 60 return self._cmp_method(other, operator.ge)
61
62 # -------------------------------------------------------------

[/usr/local/lib/python3.9/site-packages/pandas/core/arrays/datetimelike.py](https://localhost:8080/#) in _cmp_method(self, other, op)
934 try:
935 other = self._validate_comparison_value(other)
--> 936 except InvalidComparison:
937 return invalid_comparison(self, other, op)
938

[/usr/local/lib/python3.9/site-packages/pandas/core/ops/invalid.py](https://localhost:8080/#) in invalid_comparison(left, right, op)
34 else:
35 typ = type(right).__name__
---> 36 raise TypeError(f"Invalid comparison between dtype={left.dtype} and {typ}")
37 return res_values
38

TypeError: Invalid comparison between dtype=datetime64[ns] and Timestamp

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.