ProjError: Error creating Transformer from CRS.: - python-3.x

I am having an issue with Geopandas and PyProj.
I am loading a premade shp file from GeoPandas
borough = gpd.read_file(gpd.datasets.get_path('nybb'))
When trying to do a crs transformation with the following code:
borough = borough.to_crs({'init': 'epsg:4326'})
I get the error:
ProjError: Error creating Transformer from CRS.: (Internal Proj Error: proj_create_operations: SQLite error on SELECT source_crs_auth_name, source_crs_code, target_crs_auth_name, target_crs_code, cov.auth_name, cov.code, cov.table_name, area.south_lat, area.west_lon, area.north_lat, area.east_lon, ss.replacement_auth_name, ss.replacement_code FROM coordinate_operation_view cov JOIN area ON cov.area_of_use_auth_name = area.auth_name AND cov.area_of_use_code = area.code LEFT JOIN supersession ss ON ss.superseded_table_name = cov.table_name AND ss.superseded_auth_name = cov.auth_name AND ss.superseded_code = cov.code AND ss.superseded_table_name = ss.replacement_table_name AND ss.same_source_target_crs = 1 WHERE ((source_crs_auth_name = ? AND source_crs_code = ? AND target_crs_auth_name = ? AND target_crs_code = ?) OR (source_crs_auth_name = ? AND source_crs_code = ? AND target_crs_auth_name = ? AND target_crs_code = ?)) AND cov.deprecated = 0 AND cov.auth_name = ? ORDER BY pseudo_area_from_swne(south_lat, west_lon, north_lat, east_lon) DESC, (CASE WHEN accuracy is NULL THEN 1 ELSE 0 END), accuracy: no such column: ss.same_source_target_crs)
I really am totally clueless about what to do here.
PS: This is my first stackoverflow post, so I apologize in advanced for the poor layout of this post.

Related

networkx output scale problem with matplotlib (re-post)

I'm re-posting this question since I didn't make a good example code in last question.
I'm trying to make a nodes to set in specific location.
But I found out that the output drawing is not... fixed. Let me show you the pic.
So this is the one I make with 10 nodes. worked perfectly as I intended.
Also it has plt.text on the bottom left.
And here's the other picture
As you can see, something is wrong. plt.text is gone, and USA's location is weird. Actually that location is where DEU is located in the first pic. Both pics use same code.
Now, let me show you some of my code.
for spec_df, please download from my gdrive:
https://drive.google.com/drive/folders/11X_i5-pRLGBfQ9vIwQ3hfDU5EWIfR3Uo?usp=sharing
auto_flag = 0
spec_df=pd.read_stata("C:\\"Your_file_loc"\\CombinedHS6_example.dta")
#top_10_list = ["USA","CHN","KOR"] (Try for three nodes)
#or
#auto_flag = 1 (Try for 10 nodes)
df_p = spec_df[['partneriso3','tradevalue']]
df_p = df_p.groupby('partneriso3').sum().reset_index()
df_r = spec_df[['reporteriso3','tradevalue']]
df_r = df_r.groupby('reporteriso3').sum().reset_index()
df_r = df_r.rename(columns={'reporteriso3': 'Nation'})
df_r = df_r.rename(columns={'tradevalue': 'tradevalue_r'})
df_p = df_p.rename(columns={'partneriso3': 'Nation'})
df_s = pd.merge(df_r, df_p, on='Nation', how='outer').fillna(0)
df_s["final"] = df_s['tradevalue'] + df_s['tradevalue_r']
if auto_flag == 1:
df_s = df_s.sort_values(by=['final'], ascending = False).reset_index()
cut = df_s[:10]
else:
cut = df_s[(df_s['Nation'].isin(top_10_list))]
cut['final'] = cut['final'].apply(lambda x: normalize(x, cut['final'].max()))
cut['font_size'] = cut['final'] * 13
cut['final'] = cut['final'] * 1500
top_10_list = list(cut["Nation"])
top10 = spec_df[(spec_df['reporteriso3'].isin(top_10_list))&(spec_df['partneriso3'].isin(top_10_list))]
top10['tradevalue'] = top10['tradevalue'].apply(lambda x: normalize(x, top10['tradevalue'].max()))
top10['tradevalue'] = top10['tradevalue']*10
plt.figure(figsize=(10,10), dpi = 100)
G = nx.from_pandas_edgelist(top10, 'reporteriso3', 'partneriso3', 'tradevalue', create_using= nx.DiGraph())
widths = nx.get_edge_attributes(G,'tradevalue')
pos = {}
pos_cord = [(-0.30779309, -0.26419882), (0.26767895, 0.19524759), (-0.38479095, 0.88179998), (0.33785317, 0.96090914), (0.94090464, 0.40707934), (0.9270665, -0.38403114), (0.41246223, -0.85684049), (-0.32083322, -1.0), (-0.99724456, -0.34947554), (-0.87530367, 0.40950993)]
for t in range(len(top_10_list)):
if top_10_list == "":
continue
else:
pos[top_10_list[t]] = pos_cord[t]
pos_nodes = nudge(pos, 0, 0.12)
nx.draw_networkx_edges(G,pos, width=list(widths.values()), edge_color = '#9ECAE4')
nx.draw_networkx_nodes(G, pos=pos, nodelist = cut['Nation'], node_size= cut['final'], node_color ='#AB89EF', edgecolors ='#000000')
nx.draw_networkx_labels(G,pos_nodes, font_size=15)
plt.text(-1.15,-1.15,s='hs : ')
plt.savefig(location,dpi=300)
Sorry for the crude code. But I want to ask that I'm using fixed coordinates. So nodes are not supposed to move there location. So I think the plt's size is kinda interacting with the contents...? But I don't know how it does that.
Could anyone enlighten me please? This drives me crazy...
Thanks to #Paul Brodersen's comment, I found a way to fix the location.
I just added these codes in my codes.
fig = plt.figure(figsize=(10,10), dpi = 100)
axes = fig.add_axes([0,0,1,1])
axes.set_xlim([-1.3,1.3])
axes.set_ylim([-1.3,1.3])
Thank you for the help again!

Errors in mlr3 package using "surv.rfsrc" as a learner

When I try to running survival randomforest model in mlr3 using codes as below:
data(veteran)
veteran.xgb <- veteran[, !(names(veteran) %in% c("celltype"))]
set.seed(1369)
train = sample(nrow(veteran.xgb), 0.5 * nrow(veteran.xgb))
test = setdiff(seq(nrow(veteran.xgb)), train)
task = TaskSurv$new("RFSCRC_VET", backend = veteran.xgb, time = "time", event = "trt")
learn = lrn("surv.rfsrc")
learn$train(task, row_ids = train)
And the errors happened, Error: pv$codes %??% -1L, and suggests that there is no %??% in R. Was it a bug?

Value error in assigning to dataframe

I am assigning different data to one dataframe. And I had the following
ValueError: If using all scalar values, you must pass an index
I follow the question post by other Here
But it did not work out.
The following is my code. All you have to do is copy and paste the code to IDE.
import pandas as pd
import numpy as np
#Loading Team performance Data (ExpG (Home away)) For and against
epl_1718 = pd.read_csv("http://www.football-data.co.uk/mmz4281/1718/E0.csv")
epl_1718 = epl_1718[['HomeTeam','AwayTeam','FTHG','FTAG']]
epl_1718 = epl_1718.rename(columns={'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals'})
Home_goal_avg = epl_1718['HomeGoals'].mean()
Away_goal_avg = epl_1718['AwayGoals'].mean()
Home_team_goals = epl_1718.groupby(['HomeTeam'])['HomeGoals'].sum()
Home_count = epl_1718.groupby(['HomeTeam'])['HomeTeam'].count()
Home_team_avg_goal = Home_team_goals/Home_count
Home_team_concede = epl_1718.groupby(['HomeTeam'])['AwayGoals'].sum()
EPL_Home_average_score = epl_1718['HomeGoals'].mean()
EPL_Home_average_conc = epl_1718['HomeGoals'].mean()
Home_team_avg_conc = Home_team_concede/Home_count
Away_team_goals = epl_1718.groupby(['AwayTeam'])['AwayGoals'].sum()
Away_count = epl_1718.groupby(['AwayTeam'])['AwayTeam'].count()
Away_team_avg_goal = Away_team_goals/Away_count
Away_team_concede = epl_1718.groupby(['AwayTeam'])['HomeGoals'].sum()
EPL_Away_average_score = epl_1718['AwayGoals'].mean()
EPL_Away_average_conc = epl_1718['HomeGoals'].mean()
Away_team_avg_conc = Away_team_concede/Away_count
Home_attk_sth = Home_team_avg_goal/EPL_Home_average_score
Home_attk_sth = Home_attk_sth.sort_index().reset_index()
Home_def_sth = Home_team_avg_conc/EPL_Home_average_conc
Home_def_sth = Home_def_sth .sort_index().reset_index()
Away_attk_sth = Away_team_avg_goal/EPL_Away_average_score
Away_attk_sth = Away_attk_sth .sort_index().reset_index()
Away_def_sth = Away_team_avg_conc/EPL_Away_average_conc
Away_def_sth = Away_def_sth.sort_index().reset_index()
Home_def_sth
HomeTeam = epl_1718['HomeTeam'].drop_duplicates().sort_index().reset_index().set_index('HomeTeam')
AwayTeam = epl_1718['AwayTeam'].drop_duplicates().sort_index().reset_index().sort_values(['AwayTeam']).set_index(['AwayTeam'])
#HomeTeam = HomeTeam.sort_index().reset_index()
Team = HomeTeam.append(AwayTeam).drop_duplicates()
Data = pd.DataFrame({"Team":Team,
"Home_attkacking":Home_attk_sth,
"Home_def": Home_def_sth,
"Away_Attacking":Away_attk_sth,
"Away_def":Away_def_sth,
"EPL_Home_avg_score":EPL_Home_average_score,
"EPL_Home_average_conc":EPL_Home_average_conc,
"EPL_Away_average_score":EPL_Away_average_score,
"EPL_Away_average_conc":EPL_Away_average_conc},
columns =['Team','Home_attacking','Home_def','Away_attacking','Away_def',
'EPL_Home_avg_score','EPL_Home_avg_conc','EPL_Away_avg_score','EPL_Away_average_conc'])
In this code, what I am trying to do is to get average goal score per team per game, average goals conceded per team per game.
And then I am calculating other performance factors such as attacking strength, defensive strenght etc.
I have to paste the code as if i use example, creating data frame would work.
Thanks for understanding.
Thanks in advance for the advice too.
The format (or the columns) of final data frame will look like as follow:
Team Home Attacking Home Defensive Away attacking away defensive
and so on as mentioned in the data frame.
It means, there will be only 20 teams under team columns
The shape of dataframe will be ( 20,9)
Regards,
Zep
Here main idea is remove reset_index for Series with index by teams, so variable Team is not necessary and is created as last step by reset_index. Also be carefull with columns names in DataFrame constructor, if there are changed like EPL_Home_average_conc in dictionary and then EPL_Home_avg_conc get NaNs columns:
Home_team_goals = epl_1718.groupby(['HomeTeam'])['HomeGoals'].sum()
Home_count = epl_1718.groupby(['HomeTeam'])['HomeTeam'].count()
Home_team_avg_goal = Home_team_goals/Home_count
Home_team_concede = epl_1718.groupby(['HomeTeam'])['AwayGoals'].sum()
EPL_Home_average_score = epl_1718['HomeGoals'].mean()
EPL_Home_average_conc = epl_1718['HomeGoals'].mean()
Home_team_avg_conc = Home_team_concede/Home_count
Away_team_goals = epl_1718.groupby(['AwayTeam'])['AwayGoals'].sum()
Away_count = epl_1718.groupby(['AwayTeam'])['AwayTeam'].count()
Away_team_avg_goal = Away_team_goals/Away_count
Away_team_concede = epl_1718.groupby(['AwayTeam'])['HomeGoals'].sum()
EPL_Away_average_score = epl_1718['AwayGoals'].mean()
EPL_Away_average_conc = epl_1718['HomeGoals'].mean()
Away_team_avg_conc = Away_team_concede/Away_count
#removed reset_index
Home_attk_sth = Home_team_avg_goal/EPL_Home_average_score
Home_attk_sth = Home_attk_sth.sort_index()
Home_def_sth = Home_team_avg_conc/EPL_Home_average_conc
Home_def_sth = Home_def_sth .sort_index()
Away_attk_sth = Away_team_avg_goal/EPL_Away_average_score
Away_attk_sth = Away_attk_sth .sort_index()
Away_def_sth = Away_team_avg_conc/EPL_Away_average_conc
Away_def_sth = Away_def_sth.sort_index()
Data = pd.DataFrame({"Home_attacking":Home_attk_sth,
"Home_def": Home_def_sth,
"Away_attacking":Away_attk_sth,
"Away_def":Away_def_sth,
"EPL_Home_average_score":EPL_Home_average_score,
"EPL_Home_average_conc":EPL_Home_average_conc,
"EPL_Away_average_score":EPL_Away_average_score,
"EPL_Away_average_conc":EPL_Away_average_conc},
columns =['Home_attacking','Home_def','Away_attacking','Away_def',
'EPL_Home_average_score','EPL_Home_average_conc',
'EPL_Away_average_score','EPL_Away_average_conc'])
#column from index
Data = Data.rename_axis('Team').reset_index()
print (Data)

How to get rid of lmer warning message?

I have made some changes to the lmer. It works as it should but I could not get rid of the warning message that pops when I run the program. I have added the following options which allows the program run without stopping but with the warning message. I believe it is the check.nobs.vs.rankZ = "warningSmall" part. How could I get rid of this, any suggestions? Thank you.
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"warningSmall",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),check.scaleX = "ignore",check.formula.LHS="ignore",
## convergence checking options
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL),
check.conv.singular = .makeCC(action = "ignore", tol = 1e-4),
check.conv.hess = .makeCC(action = "warning", tol = 1e-6)
Warning Message from R:
Warning message:
In checkZrank(reTrms$Zt, n = n, control, nonSmall = 1e+06) :
number of observations (=300) <= rank(Z) (=300); the random-effects parameters and the
residual variance (or scale parameter) are probably unidentifiable
You should try check.nobs.vs.rankZ="ignore".
lmerControl doesn't need to specify anything other than the non-default options: at a quick glance, these are your non-default values:
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"ignore",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),
check.scaleX = "ignore",
check.formula.LHS="ignore",
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL))
In general I would suggest it's wise to turn off only the specific warnings and errors you know you want to override -- the settings above look like they could get you in trouble.
I haven't checked this since you didn't give a reproducible example ...

What is the maximum number of parameters I can use in a subsonic 2.1+ 'IN' statment?

I think i am hitting a limit. I have two IN statements in the SQL generated by subsonic. Or am I hitting the varchar ( 8000 ) limit?
When I send i fewer parameters, the statement returns results, when I send in more, the result set comes back blank.
Below is what I am catching in SQL Profiler:
exec sp_executesql N'/* GetDataSet() */
SELECT
[dbo].[QuoteDBAll].[quote_id],
[dbo].[conn_quote_result].[product_category_name],
part_number,
quote_result_special_price * ( quote_result_quantity + quote_result_quantity_spare) AS Total,
company_name
FROM [dbo].[QuoteDBAll]
INNER JOIN [dbo].[conn_quote_result]
ON [dbo].[QuoteDBAll].[quote_number] = [dbo].[conn_quote_result].[quote_number]
INNER JOIN [dbo].[conn_company]
ON [dbo].[QuoteDBAll].[company_id] = [dbo].[conn_company].[company_id]
GROUP BY [dbo].[QuoteDBAll].[quote_id],
[dbo].[conn_quote_result].[product_category_name],
[dbo].[conn_quote_result].[part_number],
[dbo].[conn_quote_result].[quote_result_quantity],
[dbo].[conn_quote_result].[quote_result_quantity_spare],
[dbo].[conn_quote_result].[quote_result_special_price],
[dbo].[QuoteDBAll].[quote_status_id],
company_name
HAVING (quote_status_id = #quote_status_id0)
AND (company_name IN
(#in1,#in2,#in3,#in4,#in5,#in6,#in7,#in8,#in9,#in10,
#in11,#in12,#in13,#in14,#in15,#in16,#in17,#in18,#in19,#in20,
#in21,#in22,#in23,#in24,#in25,#in26,#in27,#in28,#in29,#in30,#in31))
AND ([dbo].[conn_quote_result].[product_category_name] IN
(#in1,#in2,#in3,#in4,#in5,#in6,#in7,#in8,#in9,#in10,
#in11,#in12,#in13,#in14,#in15,#in16,#in17,#in18,#in19,#in20,
#in21,#in22,#in23,#in24,#in25,#in26,#in27,#in28,#in29,#in30,
#in31,#in32,#in33,#in34,#in35,#in36,#in37,#in38))',
N'#quote_status_id0 varchar(1),### varchar(8000),#in1 varchar(15),#in2 varchar(22),
#in3 varchar(21),#in4 varchar(13),#in5 varchar(5),#in6 varchar(6),#in7 varchar(13),
#in8 varchar(25),#in9 varchar(8),#in10 varchar(14),#in11 varchar(9),#in12 varchar(11),
#in13 varchar(16),#in14 varchar(12),#in15 varchar(14),#in16 varchar(16),
#in17 varchar(11),#in18 varchar(15),#in19 varchar(6),#in20 varchar(12),
#in21 varchar(12),#in22 varchar(10),#in23 varchar(15),#in24 varchar(15),
#in25 varchar(15),#in26 varchar(11),#in27 varchar(16),#in28 varchar(20),
#in29 varchar(6),#in30 varchar(16),#in31 varchar(17),#in32 varchar(11),
#in33 varchar(18),#in34 varchar(23),#in35 varchar(14),#in36 varchar(19),
#in37 varchar(12),#in38 varchar(14)',
#quote_status_id0 = '1', ### = NULL, #in1 = 'Widget1', #in2 = 'Widget2',
#in3 = 'Widget3', #in4 = 'Widget4', #in5 = 'Widget5', #in6 = 'Widget6', #in7 = 'Widget7',
#in8 = 'Widget7', #in9 = 'Widget7', #in10 = 'Widget8', #in11 = 'Widget9', #in12 = 'Widget10',
#in13 = 'Widget11', #in14 = 'Widget12', #in15 = 'Widget13', #in16 = 'Widget14',
#in17 = 'Widget15', #in18 = 'Widget16', #in19 = 'Widget17', #in20 = 'Widget18',
#in21 = 'DWidget19', #in22 = 'Widget20', #in23 = 'Widget21', #in24 = 'Widget22',
#in25 = 'Widget23', #in26 = 'Widget24', #in27 = 'Widget25', #in28 = 'Widget26',
#in29 = 'Widget27', #in30 = 'Widget28', #in31 = 'Widget29', #in32 = 'Widget30',
#in33 = 'Widget31', #in34 = 'Widget32', #in35 = 'Widget33', #in36 = 'Widget34',
#in37 = 'Widget35', #in38 = 'Widget36'
If you have to ask this question, you should probably use a temp table. Insert your parameters to the temp table and either JOIN your main table to it, or use an IN() predicate against a subquery of the temp table.
In most cases when you have 30+ parameters in an IN() predicate, you're going to find that you need more periodically. Using a temp table allows you to keep increasing the number of values without having to rewrite your query.
And it avoids any possibility of hitting a limit of the number of parameters or a limit on query length.

Resources