Skip to content

Commit 906d6f1

Browse files
committed
update Screener's querying logic and sector industry mapping
1 parent 39c2f76 commit 906d6f1

3 files changed

Lines changed: 67 additions & 61 deletions

File tree

yfinance/const.py

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
"futuresChain",
160160
)
161161

162-
# map last updated as of 2024.09.18
162+
# map last updated as of 2025.12.19
163163
SECTOR_INDUSTY_MAPPING = {
164164
'Basic Materials': {'Specialty Chemicals',
165165
'Gold',
@@ -205,9 +205,9 @@
205205
'Specialty Retail',
206206
'Textile Manufacturing',
207207
'Travel Services'},
208-
'Consumer Defensive': {'Beverages - Brewers',
209-
'Beverages - Non-Alcoholic',
210-
'Beverages - Wineries & Distilleries',
208+
'Consumer Defensive': {'BeveragesBrewers',
209+
'BeveragesNon-Alcoholic',
210+
'BeveragesWineries & Distilleries',
211211
'Confectioners',
212212
'Discount Stores',
213213
'Education & Training Services',
@@ -217,95 +217,95 @@
217217
'Household & Personal Products',
218218
'Packaged Foods',
219219
'Tobacco'},
220-
'Energy': {'Oil Gas Drilling',
221-
'Oil Gas E P',
222-
'Oil Gas Equipment Services',
223-
'Oil Gas Integrated',
224-
'Oil Gas Midstream',
225-
'Oil Gas Refining Marketing',
220+
'Energy': {'Oil & Gas Drilling',
221+
'Oil & Gas E&P',
222+
'Oil & Gas Equipment & Services',
223+
'Oil & Gas Integrated',
224+
'Oil & Gas Midstream',
225+
'Oil & Gas Refining & Marketing',
226226
'Thermal Coal',
227227
'Uranium'},
228228
'Financial Services': {'Asset Management',
229-
'Banks Diversified',
230-
'Banks Regional',
229+
'BanksDiversified',
230+
'BanksRegional',
231231
'Capital Markets',
232232
'Credit Services',
233233
'Financial Conglomerates',
234-
'Financial Data Stock Exchanges',
234+
'Financial Data & Stock Exchanges',
235235
'Insurance Brokers',
236-
'Insurance Diversified',
237-
'Insurance Life',
238-
'Insurance Property Casualty',
239-
'Insurance Reinsurance',
240-
'Insurance Specialty',
236+
'InsuranceDiversified',
237+
'InsuranceLife',
238+
'InsuranceProperty & Casualty',
239+
'InsuranceReinsurance',
240+
'InsuranceSpecialty',
241241
'Mortgage Finance',
242242
'Shell Companies'},
243243
'Healthcare': {'Biotechnology',
244-
'Diagnostics Research',
245-
'Drug Manufacturers General',
246-
'Drug Manufacturers Specialty Generic',
244+
'Diagnostics & Research',
245+
'Drug ManufacturersGeneral',
246+
'Drug ManufacturersSpecialty & Generic',
247247
'Health Information Services',
248248
'Healthcare Plans',
249249
'Medical Care Facilities',
250250
'Medical Devices',
251+
'Medical Instruments & Supplies',
251252
'Medical Distribution',
252-
'Medical Instruments Supplies',
253253
'Pharmaceutical Retailers'},
254-
'Industrials': {'Aerospace Defense',
254+
'Industrials': {'Aerospace & Defense',
255255
'Airlines',
256-
'Airports Air Services',
257-
'Building Products Equipment',
258-
'Business Equipment Supplies',
256+
'Airports & Air Services',
257+
'Building Products & Equipment',
258+
'Business Equipment & Supplies',
259259
'Conglomerates',
260260
'Consulting Services',
261-
'Electrical Equipment Parts',
262-
'Engineering Construction',
263-
'Farm Heavy Construction Machinery',
261+
'Electrical Equipment & Parts',
262+
'Engineering & Construction',
263+
'Farm & Heavy Construction Machinery',
264264
'Industrial Distribution',
265265
'Infrastructure Operations',
266-
'Integrated Freight Logistics',
266+
'Integrated Freight & Logistics',
267267
'Marine Shipping',
268268
'Metal Fabrication',
269-
'Pollution Treatment Controls',
269+
'Pollution & Treatment Controls',
270270
'Railroads',
271-
'Rental Leasing Services',
272-
'Security Protection Services',
271+
'Rental & Leasing Services',
272+
'Security & Protection Services',
273273
'Specialty Business Services',
274274
'Specialty Industrial Machinery',
275-
'Staffing Employment Services',
276-
'Tools Accessories',
275+
'Staffing & Employment Services',
276+
'Tools & Accessories',
277277
'Trucking',
278278
'Waste Management'},
279-
'Real Estate': {'Real Estate Development',
280-
'Real Estate Diversified',
279+
'Real Estate': {'Real Estate—Development',
281280
'Real Estate Services',
282-
'Reit Diversified',
283-
'Reit Healthcare Facilities',
284-
'Reit Hotel Motel',
285-
'Reit Industrial',
286-
'Reit Mortgage',
287-
'Reit Office',
288-
'Reit Residential',
289-
'Reit Retail',
290-
'Reit Specialty'},
281+
'Real Estate—Diversified',
282+
'REIT—Healthcare Facilities',
283+
'REIT—Hotel & Motel',
284+
'REIT—Industrial',
285+
'REIT—Office',
286+
'REIT—Residential',
287+
'REIT—Retail',
288+
'REIT—Mortgage',
289+
'REIT—Specialty',
290+
'REIT—Diversified'},
291291
'Technology': {'Communication Equipment',
292292
'Computer Hardware',
293293
'Consumer Electronics',
294294
'Electronic Components',
295-
'Electronics Computer Distribution',
295+
'Electronics & Computer Distribution',
296296
'Information Technology Services',
297-
'Scientific Technical Instruments',
298-
'Semiconductor Equipment Materials',
297+
'Scientific & Technical Instruments',
298+
'Semiconductor Equipment & Materials',
299299
'Semiconductors',
300-
'Software Application',
301-
'Software Infrastructure',
300+
'SoftwareApplication',
301+
'SoftwareInfrastructure',
302302
'Solar'},
303-
'Utilities': {'Utilities Diversified',
304-
'Utilities Independent Power Producers',
305-
'Utilities Regulated Electric',
306-
'Utilities Regulated Gas',
307-
'Utilities Regulated Water',
308-
'Utilities Renewable'},
303+
'Utilities': {'UtilitiesDiversified',
304+
'UtilitiesIndependent Power Producers',
305+
'UtilitiesRegulated Electric',
306+
'UtilitiesRegulated Gas',
307+
'UtilitiesRegulated Water',
308+
'UtilitiesRenewable'},
309309
}
310310
SECTOR_INDUSTY_MAPPING_LC = {}
311311
for k in SECTOR_INDUSTY_MAPPING.keys():

yfinance/data.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,11 @@ def get(self, url, params=None, timeout=30):
398398
return response
399399

400400
@utils.log_indent_decorator
401-
def post(self, url, body, params=None, timeout=30):
402-
return self._make_request(url, request_method = self._session.post, body=body, params=params, timeout=timeout)
401+
def post(self, url, body=None, params=None, timeout=30, data=None):
402+
return self._make_request(url, request_method = self._session.post, body=body, params=params, timeout=timeout, data=data)
403403

404404
@utils.log_indent_decorator
405-
def _make_request(self, url, request_method, body=None, params=None, timeout=30):
405+
def _make_request(self, url, request_method, body=None, params=None, timeout=30, data=None):
406406
# Important: treat input arguments as immutable.
407407

408408
if len(url) > 200:
@@ -430,6 +430,10 @@ def _make_request(self, url, request_method, body=None, params=None, timeout=30)
430430

431431
if body:
432432
request_args['json'] = body
433+
434+
if data:
435+
request_args['data'] = data
436+
request_args['headers'] = {"Content-Type": "application/json"}
433437

434438
for attempt in range(YfConfig().retries + 1):
435439
try:

yfinance/screener/screener.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import curl_cffi
22
from typing import Union
33
import warnings
4+
from json import dumps
45

56
from yfinance.const import _QUERY1_URL_, _SENTINEL_
67
from yfinance.data import YfData
@@ -198,10 +199,11 @@ def screen(query: Union[str, EquityQuery, FundQuery],
198199
elif isinstance(post_query['query'], FndQy):
199200
post_query['quoteType'] = 'MUTUALFUND'
200201
post_query['query'] = post_query['query'].to_dict()
202+
data = dumps(post_query, separators=(",", ":"), ensure_ascii=False)
201203

202204
# Fetch
203205
response = _data.post(_SCREENER_URL_,
204-
body=post_query,
206+
data=data,
205207
params=params_dict)
206208
response.raise_for_status()
207209
return response.json()['finance']['result'][0]

0 commit comments

Comments
 (0)