ig-python / trading-ig

A lightweight Python wrapper for the IG Markets API
https://trading-ig.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
318 stars 197 forks source link

pandas 2.2.0 causes warnings for future deprecations #329

Open Leotheone opened 7 months ago

Leotheone commented 7 months ago

Hello,

For all intents and purposes, since the latest library version upgrades, this causes futureWarnings in the conv_resol(resolution) function located in trading_ig\utils.py :

...\trading_ig\utils.py:49: FutureWarning: 'H' is deprecated and will be removed in a future version, please use 'h' instead. to_offset("1H"): "HOUR", ...\trading_ig\utils.py:50: FutureWarning: 'H' is deprecated and will be removed in a future version, please use 'h' instead. to_offset("2H"): "HOUR_2", ...\trading_ig\utils.py:51: FutureWarning: 'H' is deprecated and will be removed in a future version, please use 'h' instead. to_offset("3H"): "HOUR_3", ...\trading_ig\utils.py:52: FutureWarning: 'H' is deprecated and will be removed in a future version, please use 'h' instead. to_offset("4H"): "HOUR_4", ...\trading_ig\utils.py:55: FutureWarning: 'M' is deprecated and will be removed in a future version, please use 'ME' instead. to_offset("M"): "MONTH",

Best regards

bug-or-feature commented 6 months ago

Thanks for your interest in the project.

Please provide more information: what upgrades? what versions of which libraries are you using? etc

It is all documented here

Leotheone commented 6 months ago

Thanks so much for your reply and for all the work done so far. The shared sources have been a great help to me for several years!

You will find below the information that I hope is necessary and sufficient to produce the problem:

Used versions :

Python 3.10 trading-ig 0.0.22

Sources for producing a future warning :

from datetime import datetime, timedelta from trading_ig import IGService

username = "xxx" password = "xxx" api_key = "xxx" acc_type = "DEMO" acc_number = "xxx"

ig_service = IGService(username, password, api_key, acc_type) ig_service.create_session()

epic = 'IX.D.NASDAQ.IFE.IP' resolution = 'H' end_date = datetime.today() start_date = end_date + timedelta(hours=-6) session = None

response = ig_service.fetch_historical_prices_by_epic_and_date_range(epic, resolution, start_date, end_date, session) print(response)

femtotrader commented 6 months ago

Pandas renamed offsets aliases

See https://github.com/pandas-dev/pandas/issues/9586

https://github.com/pandas-dev/pandas/blob/main/doc/source/whatsnew/v2.2.0.rst#deprecate-aliases-m-q-y-etc-in-favour-of-me-qe-ye-etc-for-offsets

bug-or-feature commented 6 months ago

@Leotheone thanks for the code snippet - but you missed the most important (crucial) bit of information - your pandas version. The warnings you are seeing are due to your use of Pandas 2.2.0 which was released in January 2024. That's why we ask for dependencies and their versions when creating an issue

@femtotrader thanks for the clarification

bug-or-feature commented 6 months ago

From #330:

...\trading_ig\rest.py:1801: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set pd.set_option('future.no_silent_downcasting', True) data["prices"] = data["prices"].fillna(value=np.nan)

...\trading_ig\rest.py:1823: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set pd.set_option('future.no_silent_downcasting', True) data["prices"] = data["prices"].fillna(value=np.nan)

...\trading_ig\rest.py:1887: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set pd.set_option('future.no_silent_downcasting', True) data["prices"] = data["prices"].fillna(value=np.nan)