Creating list for Pandas_datareader symbol warning - pandas

How can i create a list which would log the symbols for each symbol warning ?
Everytime I execute data = web.DataReader(ticker, 'yahoo', start, end) i get symbol warnings, i want to create a list of symbols which i got the warning for how can i do that?
SymbolWarning: Failed to read symbol: 'BRK.B', replacing with NaN.
warnings.warn(msg.format(sym), SymbolWarning)
Full code :
start = datetime.date(2008,11,1)
end = datetime.date.today()
# df = web.get_data_yahoo(tickers, start, end)
df = web.DataReader(tickers, 'yahoo', start, end)

It looks like yahoo in your case is rejecting requests after a set limit.

I also ran into the same error. Basically we need to catch the warnings and extract the symbols from it.
Easier said than done.. I wasn't able to do it with try & except. (If anybody was able to, please let me know..).
I found out warnings had a catch_warnings subclass (context manager) which I can use to capture the warning messages and extract the symbols from them.
The way I did (maybe not the best way):
import warnings
import pandas_datareader
list_ = ["AAPL","TSLA","XYZ","QUAL","IOV"] # Sample list of symbols
bad_symbol_list=[]
df = pandas_datareader.yahoo.daily.YahooDailyReader(list_, start='2008-01-11',end='2020-01-31', interval='d')
with warnings.catch_warnings(record=True) as err:
warnings.resetwarnings()
df_processed=df.read()
for w in err:
print(w.message)
tmp = w.message.args[0].replace("'","")
bad_symbol_list +=[ tmp.split(" ")[4].replace("," , "") ]
print(bad_symbol_list)
Output:
Failed to read symbol: 'XYZ', replacing with NaN.
Failed to read symbol: 'IOV', replacing with NaN.
['XYZ', 'IOV']

Related

Error: ('HY000', 'The driver did not supply an error!') - with string

I am trying to push a pandas DataFrame from python to Impala but am getting a very uninformative error. The code I am using looks as such:
cursor = connection.cursor()
cursor.fast_executemany = True
cursor.executemany(
f"INSERT INTO table({', '.join(df.columns.tolist())}) VALUES ({('?,' * len(df.columns))[:-1]})",
list(df.itertuples(index=False, name=None))
)
cursor.commit()
connection.close()
This works for the first 23 rows and then suddenly throws this error:
Error: ('HY000', 'The driver did not supply an error!')
This doesn't help me locate the issue at all. I've turned all Na values to None so there is compatibility, Unfortunatly I can't share the data.
Does anyone have any ideas/ leads as to how I would solve this. Thanks

Pandas diff-function: NotImplementedError

When I use the diff function in my snippet:
for customer_id, cus in tqdm(df.groupby(['customer_ID'])):
# Get differences
diff_df1 = cus[num_features].diff(1, axis = 0).iloc[[-1]].values.astype(np.float32)
I get:
NotImplementedError
The exact same code did run without any error before (on Colab), whereas now I'm using an Azure DSVM via JupyterHub and I get this error.
I already found this
pandas pd.DataFrame.diff(axis=1) NotImplementationError
but the solution doesnt work for me as I dont have any Date types. Also I did upgrade pandas but it didnt change anything.
EDIT:
I have found that the error occurs when the datatype is 'int16' or 'int8'. Converting the dtypes to 'int64' solves it.
However I leave the question open in case someone can explain it or show a solution that works with int8/int16.

Telegram Global Search using the raw API function via Telethon

I am trying to use the SearchGlobalRequest API method for global, full-text search on Telegram, but I am not sure what to use for some of the arguments, especially the offset_peer parameter. When I do this:
try:
result = client(SearchGlobalRequest(
q=search_term,
filter=None,
min_date=datetime.datetime.strptime(min_date, '%Y-%m-%d'),
max_date=datetime.datetime.strptime(max_date, '%Y-%m-%d'),
offset_rate=-1,
# offset_peer=None,
offset_id=-1,
limit=10
))
except Exception as e:
print(e)
I get __init__() missing 1 required positional argument: 'offset_peer'.
When I try to pass None as offset_peer, I get Cannot cast NoneType to any kind of Peer. I am not trying to search in any specific channel, I just want to specify the start and end date and find all (or rather as many as possible) matching results.
I am using Telethon version 1.24.0.
Next code works for me:
from telethon.tl.functions.messages import SearchGlobalRequest
from telethon.tl.types import InputMessagesFilterEmpty, InputPeerEmpty
results = client(SearchGlobalRequest(
q='your_query_here',
filter=InputMessagesFilterEmpty(),
min_date=None,
max_date=None,
offset_rate=0,
offset_peer=InputPeerEmpty(),
offset_id=0,
limit=100,
folder_id=None
))
print(results.stringify())

readNetFromDarknet assertion error separator_index < line.size()

I am failing to use readNetFromDarknet function for the reasons I do not understand. I am trying to use yolo3-spp with this configuration file https://github.com/pjreddie/darknet/blob/master/cfg/yolov3-spp.cfg.
import cv2
net = cv2.dnn.readNetFromDarknet("../models/yolov3-spp.weights", "../models/yolov3-spp.cfg")
However, this gives me the following error:
error: OpenCV(4.5.4) /tmp/pip-req-build-3129w7z7/opencv/modules/dnn/src/darknet/darknet_io.cpp:660: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream
Interestingly, if I use readNet instead of readNetFromDarknet, it seems to work just fine. Should I stick to using readNet instead and why readNetFromDarknet is not actually working?
Your problem in order function arguments. readNetFromDarknet waits first config file and second - weights. A readNet function can swap arguments if they have a wrong order.
So right code:
net = cv2.dnn.readNetFromDarknet("../models/yolov3-spp.cfg", "../models/yolov3-spp.weights")

Error in data frame creation in R in Spark using as.data.frame

I am trying to convert SparkDataFrame to R data frame.
%python
temp_df.createOrReplaceTempView("temp_df_r")
%r
temp_sql = sql("select * from temp_df_r")
temp_r = as.data.frame(temp_sql)
Error in as.data.frame.default(temp_sql) :
cannot coerce class ‘structure("SparkDataFrame", package = "SparkR")’ to a data.frame
Sometimes I get error, it's still unknown why I get error sometimes and sometimes not.
I need more details. What environment do you use?