Python "checknull() takes no keyword arguments" error - python

I have tried to research this error and I cannot seem to find an answer. I've never seen this and this code worked fine last month and now I receive this error with the same code. Please advise and thank you. I've included my code and the error message below. The program is designed to read data from a URL and ingest that data into a new dataframe. I do not understand the meaning of "checknull()".
import os
os.environ["PROJ_LIB"] = 'C:\\Users\\Yury\\anaconda3\\Library\\share'
from sys import exit
import netCDF4 as nc4
from netCDF4 import Dataset
import numpy as np
import matplotlib as m
import matplotlib.pyplot as plt
#from mpl_toolkits.basemap import Basemap, cm
import datetime
from datetime import datetime
import pandas as pd
import xarray as xr
import cartopy.crs as ccrs
import math
#import cdstoolbox as ct
import bottleneck as bn
from mpl_toolkits.basemap import Basemap
import cdsapi
from matplotlib.pyplot import figure
import cartopy.feature as cfeature
import time
import calendar
# -----------------------------------------------------------------------------------------------------------
#
# -----------------------------------------------------------------------------------------------------------
#setx ECCODES_DEFINITION_PATH "C:\\Users\\U321103\\Anaconda3\\envs\\Maps2\\Library\\share\\eccodes\\definitions"
# copy setx... in command prompt in C:\\Users\\U321103
#!/usr/bin/env python3
c = cdsapi.Client()
url = c.retrieve(
'reanalysis-era5-single-levels-monthly-means',
{
'product_type': 'monthly_averaged_reanalysis',
'format': 'grib',
'variable': ['Mean sea level pressure'],
'year': ['1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006',
'2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021','2022'],
'month': ['01','02','03','04','05','06','07','08','09','10','11','12'],
# 'month': '12',
# 'day': '01',
'time': ['00:00'],
'grid': [0.25, 0.25],
# GRID = 0.5 TO MATCH VORTEX ?
'area': [65.00, -140.00, 15.00, -53.00],
},
"C:\\Users\\U321103\\.spyder-py3\\ERA5_MAPPING\\mean_sea_level_pressure")
path = "C:\\Users\\U321103\\.spyder-py3\\ERA5_MAPPING\\mean_sea_level_pressure"
ds = xr.load_dataset(path, engine='cfgrib')
exit()
And the error --- >
runfile('//porfiler03.ar.local/gtdshare/GOALS_2022/WeatherTypes/ERA5_Get_MSLP_USA_WORKING_MONTHLY.py', wdir='//porfiler03.ar.local/gtdshare/GOALS_2022/WeatherTypes')
2023-01-16 18:09:51,830 INFO Welcome to the CDS
2023-01-16 18:09:51,831 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels-monthly-means
2023-01-16 18:09:52,149 INFO Request is completed
2023-01-16 18:09:52,150 INFO Downloading https://download-0001-clone.copernicus-climate.eu/cache-compute-0001/cache/data0/adaptor.mars.internal-1673912965.1298344-26515-5-eb9a349c-be6c-4e0c-b3fb-79e0d436a411.grib to C:\Users\U321103\.spyder-py3\ERA5_MAPPING\mean_sea_level_pressure (49.9M)
2023-01-16 18:09:59,400 INFO Download rate 6.9M/s
2023-01-16 18:09:59,401 WARNING Ignoring index file 'C:\\Users\\U321103\\.spyder-py3\\ERA5_MAPPING\\mean_sea_level_pressure.923a8.idx' older than GRIB file
Traceback (most recent call last):
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\conventions.py", line 523, in decode_cf_variables
new_vars[k] = decode_cf_variable(
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\conventions.py", line 364, in decode_cf_variable
var = coder.decode(var, name=name)
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\coding\variables.py", line 189, in decode
encoded_fill_values = {
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\coding\variables.py", line 193, in <setcomp>
if not pd.isnull(fv)
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\pandas\core\dtypes\missing.py", line 185, in isna
return _isna(obj)
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\pandas\core\dtypes\missing.py", line 208, in _isna
return libmissing.checknull(obj, inf_as_na=inf_as_na)
TypeError: checknull() takes no keyword arguments
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "\\porfiler03.ar.local\gtdshare\goals_2022\weathertypes\era5_get_mslp_usa_working_monthly.py", line 58, in <module>
ds = xr.load_dataset(path, engine='cfgrib')
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\backends\api.py", line 258, in load_dataset
object.
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\backends\api.py", line 545, in open_dataset
ds = _dataset_from_backend_dataset(
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\backends\api.py", line 451, in maybe_decode_store
specified). If None (default), attempt to decode times to
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\conventions.py", line 659, in decode_cf
vars, attrs, coord_names = decode_cf_variables(
File "C:\Users\U321103\Anaconda3\envs\Maps2\lib\site-packages\xarray\conventions.py", line 534, in decode_cf_variables
raise type(e)(f"Failed to decode variable {k!r}: {e}")
TypeError: Failed to decode variable 'number': checknull() takes no keyword arguments

Related

Using rpy2 with streamlit

I am trying to build an app by using python and rpy2. I read a .csv file (see below, table_mean_plain) and I would like to plot an histogram of its percentage of explained variances. When I use the code in Jupyter notebook it is working fine. But when I try through streamlit the code is loading forever and I receive the message:
2022-10-25 17:08:05.231 Uncaught app exception
Traceback (most recent call last):
File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 562, in _run_script
exec(code, module.__dict__)
File "/Users/XX/Documents/XX/pages/4_Visualisations.py", line 69, in <module>
res_pca = FactoMineR.PCA(my_data)
File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/rpy2/robjects/functions.py", line 201, in __call__
return (super(SignatureTranslatedFunction, self)
File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/rpy2/robjects/functions.py", line 124, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/rpy2/rinterface_lib/conversion.py", line 45, in _
cdata = function(*args, **kwargs)
File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/rpy2/rinterface.py", line 810, in __call__
raise embedded.RRuntimeError(_rinterface._geterrmessage())
rpy2.rinterface_lib.embedded.RRuntimeError: Erreur dans (function (title, width, height, pointsize, family, antialias, :
impossible de créer le périphérique cible quartz(), le type fourni n'est peut-être pas supporté
Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file NSView.m, line 13477.
[9] 59974 illegal hardware instruction streamlit run 1_Workbench.py
Here is my code
from rpy2.robjects.packages import importr, data
from rpy2.robjects.vectors import DataFrame
from rpy2.ipython.ggplot import image_png
import streamlit as st
import matplotlib.pyplot as plt
from rpy2 import robjects
import matplotlib.image as mpimg
utils = importr('utils')
corrplot = importr('corrplot')
FactoMineR = importr('FactoMineR')
factoextra = importr('factoextra')
my_datafile = 'table/plain/table_mean_plain.csv'
#my_data = utils.read_csv(my_datafile)
my_data = DataFrame.from_csvfile(my_datafile, row_names="X")
#rownames(my_data = my_data$X
#my_dataX = NULL
# Do PCA
# --------
res_pca = FactoMineR.PCA(my_data)
# Eigen values / Variance
# --------
eig_val = factoextra.get_eigenvalue(res_pca)
st.pyplot(display(image_png(factoextra.fviz_eig(res_pca, addlabels = True))))
The corresponding .csv file is
,logistic-regression,svm-linear,svm-rbf,Gnb,decision-tree,random-forest,XGBoost,MLP,Ensemble,GEV,iForest,DevNet
news,0.827,0.566,0.724,0.681,0.687,0.852,0.865,0.859,0.866,0.87,0.497,0.666
telE,0.761,0.552,0.623,0.756,0.86,0.944,0.957,0.915,0.95,0.941,0.399,0.717
bank,0.832,0.62,0.772,0.817,0.687,0.848,0.841,0.848,0.855,0.873,0.625,0.793
member,0.648,0.488,0.514,0.625,0.574,0.696,0.695,0.669,0.707,0.667,0.545,0.598
dsn,0.735,0.708,0.785,0.707,0.761,0.884,0.897,0.754,0.884,0.766,0.568,0.661
mobile,0.889,0.432,0.393,0.842,0.776,0.9,0.906,0.9,0.908,0.907,0.7,0.852
campaign,0.907,0.543,0.668,0.809,0.709,0.928,0.933,0.923,0.935,0.924,0.65,0.832
HR,0.85,0.766,0.841,0.762,0.615,0.809,0.797,0.825,0.838,0.827,0.589,0.72
sato,0.794,0.747,0.8,0.729,0.651,0.808,0.809,0.799,0.825,0.82,0.5,0.739
uci,0.854,0.586,0.897,0.859,0.818,0.901,0.905,0.847,0.913,0.91,0.663,0.793
TelC,0.844,0.632,0.797,0.814,0.658,0.819,0.825,0.842,0.841,0.85,0.295,0.784
median_AUC,0.832,0.586,0.772,0.762,0.687,0.852,0.866,0.847,0.866,0.87,0.568,0.739
Rank,5.67,10.67,7.5,8.08,9.0,4.0,3.25,5.0,1.83,2.67,11.42,8.92

How do I get around a GeneralName TypeError?

I am trying to get into writing code to scrape stock web pages, I came across this youtube video https://www.youtube.com/watch?v=2BrpKpWwT2A. When I copy and paste the following code (from the video)
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use("ggplot")
start = dt.datetime(2015, 1, 1)
end = dt.datetime.now()
df = web.DataReader("TSLA", "yahoo", start, end)
print(df.head())
I still get the same error (Full traceback is too long to add here) but the last few lines say:
File "/anaconda3/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 363, in getpeercert
'subjectAltName': get_subj_alt_name(x509)
File "/anaconda3/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 213, in get_subj_alt_name
ext = cert.extensions.get_extension_for_class(
File "/anaconda3/lib/python3.6/site-packages/cryptography/utils.py", line 170, in inner
result = func(instance)
File "/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/x509.py", line 127, in extensions
self._backend, self._x509
File "/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/decode_asn1.py", line 252, in parse
value = handler(backend, ext_data)
File "/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/decode_asn1.py", line 438, in _decode_subject_alt_name
_decode_general_names_extension(backend, ext)
File "/anaconda3/lib/python3.6/site-packages/cryptography/x509/extensions.py", line 1262, in __init__
self._general_names = GeneralNames(general_names)
File "/anaconda3/lib/python3.6/site-packages/cryptography/x509/extensions.py", line 1217, in __init__
"Every item in the general_names list must be an "
TypeError: Every item in the general_names list must be an object conforming to the GeneralName interface
Any ideas as to what I could be doing wrong?
I tried the above code and got the following output:

Getting error to extract data from coinmarketcap

import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
import time
import seaborn as sns
import matplotlib.pyplot as plt
import datetime
import numpy as np
df=pd.read_excel('currencynames.xlsx', sheet_name='Sheet1')
writer = pd.ExcelWriter('cryptodata.xlsx', engine='xlsxwriter')
currencies = df['Currency Name']
print(currencies[0])
for i in range(0,1465,1):
print("https://coinmarketcap.com/currencies/"+currencies[i]+"/historical-data/?start=20130428&end="+time.strftime("%Y%m%d"))
currency_market_info = pd.read_html("https://coinmarketcap.com/currencies/"+currencies[i].lower()+"/historical-data/?start=20130428&end="+time.strftime("%Y%m%d"))[0]
currency_market_info = currency_market_info.assign(Date=pd.to_datetime(currency_market_info['Date']))
currency_market_info.loc[currency_market_info['Volume']=="-",'Volume']=0
currency_market_info['Volume'] = currency_market_info['Volume'].astype('int64')
currency_market_info.head()
currency_market_info.to_excel(writer, sheet_name=currencies[i])
currency_market_info = 0
print("Done with "+currencies[i])
C:\Users\SAU\Anaconda3\lib\site-packages\pandas\core\ops.py:816:
FutureWarning: elementwise comparison failed; returning scalar
instead, but in the future will perform elementwise comparison
result = getattr(x, name)(y) Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/SAU/Desktop/deep learning/cryptodata/data.py', wdir='C:/Users/SAU/Desktop/deep learning/cryptodata')
File
"C:\Users\SAU\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py",
line 880, in runfile
execfile(filename, namespace)
File
"C:\Users\SAU\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py",
line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/SAU/Desktop/deep learning/cryptodata/data.py", line
19, in
currency_market_info.loc[currency_market_info['Volume']=="-",'Volume']=0
File "C:\Users\SAU\Anaconda3\lib\site-packages\pandas\core\ops.py",
line 879, in wrapper
res = na_op(values, other)
File "C:\Users\SAU\Anaconda3\lib\site-packages\pandas\core\ops.py",
line 818, in na_op
raise TypeError("invalid type comparison")
TypeError: invalid type comparison

Pyalgotrade - AttributeError: 'SequenceDatasSeries' object has no attribute 'getHighDataSeries'

I'm using pyalgotrade to write a trading algo. I got the error above and can't seem to fix it. I'm trying to use the "SLOW STOCHASTIC", any help on solving this error and getting the slow stochastic to work is greatly appreciated:
Error:
C:\Users\...\Desktop>python bobo.py
Traceback (most recent call last):
File "bobo.py", line 114, in <module>
main()
File "bobo.py", line 110, in main
run_strategy(10,inst,2,14,5,2,3)
File "bobo.py", line 102, in run_strategy
myStrategy = MyStrategy(feed, inst, smaPeriod,emaPeriod,rsiPeriod,fastk_period,slowk_period,slowd_period)
File "bobo.py", line 26, in __init__
self.__stoch = indicator.STOCH(self.__prices,fastk_period,slowk_period,slowd_period)
File "C:\Users\...\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 803, in STOCH
ret = call_talib_with_hlc(barDs, count, talib.STOCH, fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype)
File "C:\Users\...\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 93, in call_talib_with_hlc
high = bar_ds_high_to_numpy(barDs, count)
File "C:\Users\...\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 45, in bar_ds_high_to_numpy
return value_ds_to_numpy(barDs.getHighDataSeries(), count)
AttributeError: 'SequenceDataSeries' object has no attribute 'getHighDataSeries'
Code:
from pyalgotrade.tools import yahoofinance
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
from pyalgotrade.technical import stoch
from pyalgotrade import dataseries
from pyalgotrade.technical import ma
from pyalgotrade import technical
from pyalgotrade.technical import highlow
from pyalgotrade import bar
from pyalgotrade.talibext import indicator
from pyalgotrade.technical import rsi
import numpy
import talib
class MyStrategy(strategy.BacktestingStrategy):
def __init__(self, feed,instrument,smaPeriod,emaPeriod,rsiPeriod,fastk_period,slowk_period,slowd_period):
strategy.BacktestingStrategy.__init__(self, feed, 1000) #change portfolio amount
self.__position = None
self.__instrument = instrument
self.setUseAdjustedValues(True)
self.__prices = feed[instrument].getPriceDataSeries()
self.__sma = ma.SMA(self.__prices, smaPeriod)
self.__ema = ma.EMA(self.__prices, emaPeriod)
self.__rsi = rsi.RSI(self.__prices, rsiPeriod)
self.__stoch = indicator.STOCH(self.__prices,fastk_period,slowk_period,slowd_period)
Now I'm getting the error:
Traceback (most recent call last):
File "bobo.py", line 103, in <module>
main()
File "bobo.py", line 99, in main
run_strategy(inst,10,250,14,5,5,5)
File "bobo.py", line 90, in run_strategy
myStrategy = MyStrategy(feed, inst, smaPeriod,emaPeriod,rsiPeriod,fastk_period,slowk_period,slowd_period)
File "bobo.py", line 28, in __init__
self.__stoch = indicator.STOCH(feed[instrument],fastk_period,slowk_period,slowd_period)
File "C:\Users\JDOG\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 803, in STOCH
ret = call_talib_with_hlc(barDs, count, talib.STOCH, fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype)
File "C:\Users\JDOG\Anaconda2\lib\site-packages\pyalgotrade\talibext\indicator.py", line 105, in call_talib_with_hlc
return talibFunc(high, low, close, *args, **kwargs)
File "talib/func.pyx", line 9388, in talib.func.STOCH (talib\func.c:87125)
Exception: inputs are all NaN
Try this:
self.__stoch = indicator.STOCH(feed[instrument],fastk_period,slowk_period,slowd_period)
The stochastic oscillator is expecting a bar dataseries, not a regular one.

Pandas' corrwith usage about SPY vs. ^GSPC

Pandas' corrwith work fine with SPY but not OK with ^GSPC.
Can anybody help me ? Thanks in advance.
import pandas.io.data as web
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import csv
Symbol = ['^GSPC','SPY','XLK','XLV','XLY','XLP','XLE','XLF','XLI','XLB','XLU']
STOCK = web.DataReader(name=Symbol,data_source='yahoo',start='2000-1-1',end='2009-3-1')
STOCK['PercentA'] = np.round(np.log(STOCK['Adj Close']/STOCK['Adj Close'].shift(1)),3)
### OK wiht SPY, but not OK wiht ^GSPC
STOCKCORR = np.round(STOCK['PercentA'].corrwith(STOCK['PercentA'].^GSPC),3)
StockNan = STOCKCORR[~STOCKCORR.isnull()]
StockOrder = StockNan.order().iloc[::-1]
StockRows = StockOrder.iloc[:20]
print StockRows
the error messages:
runfile('D:/###pg/yahoo_final_Chang/150830__Revised/test.py', wdir='D:/###pg/yahoo_final_Chang/150830__Revised')
Traceback (most recent call last):
File "", line 1, in
File "C:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 682, in runfile
execfile(filename, namespace)
File "C:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "D:/###pg/yahoo_final_Chang/150830__Revised/test.py", line 16
STOCKCORR = np.round(STOCK['PercentA'].corrwith(STOCK['PercentA'].^GSPC),3)
^
SyntaxError: invalid syntax

Categories

Resources