-
Notifications
You must be signed in to change notification settings - Fork 139
Open
Description
If you encounter a bug in UrbanSim please: 1) first search the previously opened issues to see if the problem has already been reported; 2) If not, fill in the template below and tag with the appropriate Type label. You can delete any sections that do not apply.
Description of the bug
The urbansim/models/transition.py contains the use of np.int, which was originally deprecated in NumPy 1.20, so it cause the problem during the model run.
Data (optional)
If the issue is related to specific data please provide a link to download your data or provide an example dataset that illustrates the issue.
Environment
- Operating system:
Mac OSX Ventura - Python version:
3.11 - UrbanSim version:
3.2 - UrbanSim required packages versions (optional):
Paste the code that reproduces the issue here:
def add_rows(data, nrows, starting_index=None, accounting_column=None):
"""
Add rows to data table according to a given nrows.
New rows will have their IDs set to NaN.
Parameters
----------
data : pandas.DataFrame
nrows : int
Number of rows to add.
starting_index : int, optional
The starting index from which to calculate indexes for the new
rows. If not given the max + 1 of the index of `data` will be used.
accounting_column: string, optional
Name of column with accounting totals/quanties to apply towards the control. If not provided
then row counts will be used for accounting.
Returns
-------
updated : pandas.DataFrame
Table with rows added. New rows will have their index values
set to NaN.
added : pandas.Index
New indexes of the rows that were added.
copied : pandas.Index
Indexes of rows that were copied. A row copied multiple times
will have multiple entries.
"""
logger.debug('start: adding {} rows in transition model'.format(nrows))
if nrows == 0:
return data, _empty_index(), _empty_index()
if not starting_index:
starting_index = data.index.values.max() + 1
new_rows = sample_rows(nrows, data, accounting_column=accounting_column)
copied_index = new_rows.index
added_index = pd.Index(np.arange(
starting_index, starting_index + len(new_rows.index), dtype=np.int))
new_rows.index = added_index
logger.debug(
'finish: added {} rows in transition model'.format(len(new_rows)))
return pd.concat([data, new_rows]), added_index, copied_index
# place code herePaste the error message (if applicable):
File "/Users/wangweihan/Desktop/Straford_Project/Stratford_urbansim/fast_api/app/urbansim_model/run_model.py", line 27, in run_model
orca.run([
File "/Users/wangweihan/Library/Caches/pypoetry/virtualenvs/stratford-urbansim-api-lZAW07Ha-py3.11/lib/python3.11/site-packages/orca/orca.py", line 2177, in run
step()
File "/Users/wangweihan/Library/Caches/pypoetry/virtualenvs/stratford-urbansim-api-lZAW07Ha-py3.11/lib/python3.11/site-packages/orca/orca.py", line 973, in __call__
return self._func(**kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/Users/wangweihan/Desktop/Straford_Project/Stratford_urbansim/fast_api/app/urbansim_model/model_config/models.py", line 125, in households_transition
return utils.simple_transition(households, .05, "building_id")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wangweihan/Desktop/Straford_Project/Stratford_urbansim/fast_api/app/urbansim_model/model_config/utils.py", line 159, in simple_transition
df, added, copied, removed = transition.transition(df, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wangweihan/Library/Caches/pypoetry/virtualenvs/stratford-urbansim-api-lZAW07Ha-py3.11/lib/python3.11/site-packages/urbansim/models/transition.py", line 201, in transition
return add_or_remove_rows(data, nrows, accounting_column=self.accounting_column)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wangweihan/Library/Caches/pypoetry/virtualenvs/stratford-urbansim-api-lZAW07Ha-py3.11/lib/python3.11/site-packages/urbansim/models/transition.py", line 136, in add_or_remove_rows
updated, added, copied = add_rows(
^^^^^^^^^
File "/Users/wangweihan/Library/Caches/pypoetry/virtualenvs/stratford-urbansim-api-lZAW07Ha-py3.11/lib/python3.11/site-packages/urbansim/models/transition.py", line 63, in add_rows
starting_index, starting_index + len(new_rows.index), dtype=np.int))
^^^^^^
File "/Users/wangweihan/Library/Caches/pypoetry/virtualenvs/stratford-urbansim-api-lZAW07Ha-py3.11/lib/python3.11/site-packages/numpy/__init__.py", line 305, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
# place error message hereMetadata
Metadata
Assignees
Labels
No labels