-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in bdp_Impl: attempt to set an attribute on NULL #102
Comments
note that this works Rblpapi::bdp(securities = c("IP Index","DE US Equity"), fields = "CRNCY", con = con) (I paste here the structure(list(CRNCY = c("", "USD")), class = "data.frame", .Names = "CRNCY", row.names = c("IP Index", "DE US Equity")) |
How do you suggest we deal with that programmatically? We only respond to what we get from Bloomberg and if the data is bunk, there is little we can do. We cannot know before the query whether it will fail or not i.e. guess whether a field is appropriate for the security in question or not. This seems like user error to me. So for an unanswerable query you get an empty result, which is currently an error condition. If you want to make that nicer, go for it. We generally take well written pull requests. (And you don't need to pass (Also don't use quote |
Yes, it's related to lazy initialization. The response vector for 'CRNCY' is never initialized because there is no data from bbg. We should revisit that part of the code. |
With that you get the 'assigned to Whit' label. |
Thank you for your feedbacks and for considering my suggestion. I have indeed looked at the source code of bdp, However I am less fluent in c++ than in R and couldnt find the exact replacement code. From the error message it seems that we are assigning an attribute on a NULL object. |
haha. nice. I'll try to knock this out. I think we can bring back the field search. just may have to reassign the Date/time vector to a Date vector later. but I'm much more comfortable w/ Rcpp now, so perhaps that will be easier... |
(Re DateVector and DatetimeVector in Rcpp: Those are bound to change "one day" as they are terrible. See eg here in Rblpapi itself for a (so-far ill-named) |
That should be fine. If memory serves, the issue was that bbg would frequently return 'date-time' for date fields or possibly 'date' for date-time fields. However, w/ lazyframe or whatever container we use. When we see the first instance of the field, we can simply reassign it to the correct type and delete the old vector. I guess I thought this was too inelegant the first time around... |
I also came across this issue today. Coming back to Dirk's initial question How do you suggest we deal with that programmatically? I sort of lean towards not doing anything on the Rblpapi side because the bdp function just responds to the output from Bloomberg and the end user can easily just catch the error and handle it (see my example below). The error arises only if there is no data so why not just catch the error with tryCatch and return NA? If handling the issue makes the bdp function slower because of extra checks I would prefer to leave the bdp function as it is and urge end user to solve the issue on their side. Do you guys agree? fields <- c("BEST_EPS", "BEST_EPS_YOY_GTH", "BEST_EPS_6MO_PCT_CHG",
"BEST_SALES", "BEST_SALES_YOY_GTH")
tryCatch({Rblpapi::bdp(securities = "7912 JT Equity",
fields = fields,
overrides = structure("1FY",
names = "BEST_FPERIOD_OVERRIDE"))},
error = function(e) {rep(NA, length(fields))})
# returns NA with |
The idea is right but the handling has to happen at the C++ level as @armstrtw has hinted at, and volunteered to do, eventually... |
It's coming. As usual, it's taking a little longer given what's been happening in the markets. |
Thank you both, it will a valuable commit when implemented at the C++ level @armstrtw makes sense. No rush since users can handle it for now outside the bdp function |
you can try the current master if you want. should be working. but limited testing has been done so far. |
I just installed the current master and my example still produces the same error. Do you also get the error if you run my example (without tryCatch)? |
or were you talking about the other example? |
This example... library(Rblpapi)
blpConnect()
fields <- c("BEST_EPS", "BEST_EPS_YOY_GTH", "BEST_EPS_6MO_PCT_CHG",
"BEST_SALES", "BEST_SALES_YOY_GTH")
bdp(securities = "7912 JT Equity", fields = fields,
overrides = structure("1FY",
names = "BEST_FPERIOD_OVERRIDE"))
|
yes. I get all NA for that. with overrides and without. |
Thanks. I'll go back and check whether an error occured when I installed the current master. |
and? |
An error in the installation of master had duck under the rader. After I found out, I tried every method of installing master
|
|
@eddelbuettel thanks! I'll try your solution first thing tomorrow morning (European time)... |
|
So do that part (ie |
Will do. Cannot wait for IT security to move on this... |
@eddelbuettel it worked. Thanks for your guidance. I learned a great deal along the way. @armstrtw your C++ implementation works as intended in my various scripts after I have removed the tryCatch functions. A quick question, maybe a bad one because I haven't paid enough attention to the recent commits, but is the output order of fields now identical to the input order? It seems so when I look through the results of my code. |
@pgarnry good to know -- we'll look into releasing 'shorty', in the meantime you now also now how to help yourself to newer binaries. |
@pgarnry can you close this out? this works now (github master). |
Or @RockScience who originally opened this. |
This one goes to @RockScience |
@RockScience I deleted my local binary after it was build with win-builder. I can send you the build version (0.3.2.2) if you want? If you insist on the binary I might be able to do it this evening (CET) - no promise though |
@RockScience Please scroll up two screens to this message where I explain how to roll your own via win-builder. It really is not that hard. We will release a new version at some point too. |
Thanks, I managed to create the bin with the win-builder. It passes also my unit tests. This closes the thread. Thank you @armstrtw . |
I reopen temporarly as unfortunately it seems that the following call now fails in the most recent version (I checked and in the CRAN version it works): con <- Rblpapi::blpConnect()
Rblpapi::bdh(securities="DOENUSCH Index",
fields="ECO_RELEASE_DT",
start.date = as.Date('2015-09-26'),
end.date = as.Date('2016-02-29'),
include.non.trading.days = FALSE,
options=NULL,
overrides=NULL,
identity=NULL,
con=con)
# Error: Attempt to access value of element 'ECO_RELEASE_DT'(type: 'Float64') as 'Datetime' type. Is it the same on your side? |
No, it also bombs for me with the most recent code base: R> Rblpapi::bdh(securities="DOENUSCH Index", fields="ECO_RELEASE_DT", start.date = as.Date('2015-09-26'), end.date = as.Date('2016-02-29'))
Error: Attempt to access value of element 'ECO_RELEASE_DT'(type: 'Float64') as 'Datetime' type.
R> @armstrtw Can you take a look? Bbg appears to have a screw loose with this fieldtype: R> Rblpapi::bdh(securities="DOENUSCH Index", fields="ECO_RELEASE_DT", start.date = as.Date('2016-02-01'), end.date = as.Date('2016-02-29'), include.non.trading.days = FALSE, verbose=TRUE)
HistoricalDataResponse = {
securityData = {
security = "DOENUSCH Index"
eidData[] = {
}
sequenceNumber = 0
fieldExceptions[] = {
}
fieldData[] = {
fieldData = {
date = 2016-02-05
ECO_RELEASE_DT = 20160211.000000
}
fieldData = {
date = 2016-02-12
ECO_RELEASE_DT = 20160218.000000
}
fieldData = {
date = 2016-02-19
ECO_RELEASE_DT = 20160225.000000
}
fieldData = {
date = 2016-02-26
ECO_RELEASE_DT = 20160303.000000
}
}
}
}
Error: Attempt to access value of element 'ECO_RELEASE_DT'(type: 'Float64') as 'Datetime' type.
R>
R> fieldInfo("ECO_RELEASE_DT")
id mnemonic datatype ftype
ECO_RELEASE_DT DX252 ECO_RELEASE_DT Datetime Date
R> |
I think I would classify this as a bbg fail... This call works as a bdp call: > bdp(c("CPI Index","DOENUSCH Index"),"ECO_RELEASE_DT")
ECO_RELEASE_DT
CPI Index 2016-03-16
DOENUSCH Index 2016-03-03 and the return type is 'Date' as it should be (and as fieldInfo says it is). but fails as BDH, as bbg decides to send the data as a double, in YYYYMMDD.HHMMSS format... I suppose. I'm really not sure what to do here. If we can't rely on fieldInfo, then we would have to build our own field->type map which is not something I think is sustainable. Especially when it changes from bdp to bdh, we would need to build a separate map for each call. @wmorgan85 can you please offer some advice? |
@armstrtw indeed this field is both a reference and a historical field. Maybe we need an argument in fieldInfo to specify the category of data? |
you can look: but it seems bbg does not distinguish between the two services in terms of fieldInfo. |
I was thinking about this last night, and perhaps the more pragmatic approach is just to test for dates returned as doubles in the populateDfRow function and convert them: My thinking is that for the other types (bool, double, int), the bbg functions getValueAsXXX will do an automatic conversion if the type is convertible. So, even if bbg lies to us about the actual types being returned, let's say getFieldType tells us something is an Int32, and bbg actually returns a double. The getValueAsInt32 function should be able to convert it without complaining (at least that is my working assumption for now). If we continue to see exceptions (if the getValueAsXXX functions are not able to autoconvert), then we will have to try another approach. |
👍 -- sounds good |
the patch works. will add a test case as well.
|
Works on all my examples so far. Thank you. |
This works
but this returns an error:
Maybe it is stupid to look for the CRNCY of IP Index, but I would have expected to get a NULL or an empty data.frame, not an error.
Thank you
The text was updated successfully, but these errors were encountered: