-
Notifications
You must be signed in to change notification settings - Fork 28
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
"KeyError: 'building_id'" when running lcm_simulate #19
Comments
I think (I'm not totally sure) that you need a building_id in the households table. Do you have that column? The vacant_residential_units requires there to be a building_id. |
Thanks for replying! |
OK - yeah I've definitely seen this before but am having a hard time remembering the problem. I would try 2 things - first, try naming the index of your buildings table -
then I would double check the index for duplicates
|
I've checked my buildings data with the method you suggested. There is no duplicates in buildings.index. And I got same error message... |
And you tried changing the name of the index? On Tue, Jun 2, 2015 at 1:55 PM lisalan520 [email protected] wrote:
|
Yes I did. Could it be related to data type? |
Is building_id a float because there are nans? If so, that is very likely it - is should be an int column. |
The building_id is an int column. Should it be consecutive integers? I have something like this [1,2,3,5,9,10] will this be an issue? |
Definitely does NOT have to consecutive. |
Are you sure you're talking about the right table? The error is occurring here: C:\Users\xzhang\Documents\PythonScripts\Marion_urbansim_test_0514_with_building_ids\utils.pyc in lcm_simulate(cfg, choosers, buildings, nodes, out_fname, supply_fname, vacant_fname)
198
199 # go from units back to buildings
--> 200 new_buildings = pd.Series(units.ix[new_units.values][out_fname].values,
201 index=new_units.index)
202 And I think the most likely way to get a KeyError there is if the |
Units comes from here: https://github.com/synthicity/urbansim_defaults/blob/master/urbansim_defaults/utils.py#L358 It's an expansion of the original buildings table and it needs a building_id to get back to the buildings. I really think the building_id comes from the call to |
It looks like @lisalan520 is not using the same version of |
It seems like it's a lot different - the line number has gone from 200 to 437. @lisalan520 what version are you using? I don't know for sure, but it's definitely possible the new version would fix the problem. I have made some small changes in the function in the past 2-3 months. If we know what version @lisalan520 is running maybe we can diff them? |
The lcm_simulate I used comes from here: https://github.com/synthicity/sanfran_urbansim/blob/master/utils.py I have the same code as in the link. I'm using UrbanSim 1.3. I'll try to update my urbansim to see whether it solves the problem. |
Seems the two 2.0 versions both use discrete choice model, which should not solve the problem here. I'll try to run discrete choice model again and hope my computer can afford it this time. Many thanks! |
So just to be clear, when you print out |
So can you then run |
I was able to run units.loc[new_units.values]["building_id"] to get the results. But when I define out_fname= building_id, I cannot run units.loc[new_units.values][out_fname] here. |
Can you print units.columns? Grasping at straws here... |
Interesting - and you put |
Note that in the code @lisalan520 is using it's using |
You're not going to be able to use |
@lisalan520 You're not in SF, are you? I wish I could debug this in person. We might also be able to use a Google Hangout, I think I can drive your computer from those. |
Sorry for some reason I thought it was building_id in my models.py. I just checked it and it was "building_id" when I got the error... I'm in Indianapolis. I'll check if I can use Google Hangout on this computer. Thanks! |
Hi @jiffyclub I think we can try Google Hangouts. So how do I connect with you? |
You can join me here: https://plus.google.com/hangouts/_/gvttqyhgmmnclmstprvgwmrhwma |
Just had a call with @lisalan520 and for some reason for her the expression units = locations_df.loc[np.repeat(vacant_units.index.values,
vacant_units.values.astype('int'))].reset_index() is resulting in the |
Many thanks @jiffyclub ! I could only update my Pandas to 0.16.0 due to our firewall. The problem was still there. At this moment I don't think the error comes from pandas but I will continue to update it to 0.16.1. Meanwhile, with the problem we've found, I changed out_fname to 'index' in the code: and the model works fine after this change. Though I still don't understand why "building_id" turns into "index" in the loc() function.. But it seems the problem is solved for now. Thank you very much! I really appreciate your help! |
So weird that |
Hi,
I also have problem running 'hlcm_simulate' & 'elcm_simulate' models using my own data. It raised keyerror: 'building_id' for both models. I've checked my data and found nothing weird. I've also managed to break the model to individual steps and run them one by one. Do you have any idea what could be wrong? Thank you!
Here is my error message:
The text was updated successfully, but these errors were encountered: