Select to view content in your preferred language

The notebook in ArcGIS Pro kept recalling previous results even I haved cleared caches

806
5
05-30-2024 10:58 PM
Labels (3)
clai
by
Emerging Contributor

Hi I encountered a werid situation as follows:

1. I set my working space by using the code following code and then using UpdateCursor api:

 

 

 

 

import arcpy
from pprint import pprint

# Setting the default location for geoprocessing tool inputs and outputs.
arcpy.env.workspace = r"original_path\....gdb"
arcpy.env.overwriteOutput = True

merge_chinesefields = ["CHINESENAME","CHINESESTREETNAME"]

with arcpy.da.UpdateCursor("test", merge_chinesefields) as cursor:
    for row in cursor:
        print (row)

 

 

 

 

 

2. I closed ArcGIS Pro and changed my whole working folder from "original_path\....gdb" to a new place as "new_path\....gdb"

 

3. I reopened the ArcGIS Project file from the new folder and then re-runed the exactly same code as above without changing the workspace. Therefore, in this time the code was still

 

 

 

arcpy.env.workspace = r"original_path\....gdb"

 

 

 

 

4. The werid thing is that although I did not change the workspace path, the code still worked and succesfully printed each row of the table. The code did not report error like: 

Input Workspace: Dataset original_path\....gdb does not exist or is not supported

 

5. It seemed that the notebook can memory previous results and recall the previous results without noticing  path change. Therefore, I tried the command of "arcpy.management.ClearWorkspaceCache()" as well as the process "Options - Display - Clear Cache Now". But the kernel can still run without errors and return the previous print result to me. 

 

Did anyone encounter the same problem before? Is it because ArcGIS Pro somehow automatically generate a connection to my folder whereever it is stored in my computer?

0 Kudos
5 Replies
MicZatorsky_AEC
Frequent Contributor

Here's another example of Notebooks remembering things you'd prefer they didn't 

Once you assign a value to a variable in an ArcGIS Pro notebook, it will remember and use that variable for the remainder of that session until you close ArcGIS Pro. It's super easy to demonstrate. It is even better if you do the same thing side by side in IDLE.

In IDLE create, and reference a variable:

MicZatorsky_AEC_0-1717717592450.png

Then, edit the code to delete the variable and re-run.

MicZatorsky_AEC_1-1717717644610.png

X is not defined.  Good!

Let's try the same experiment in a Notebook. First, when the variable exists:

MicZatorsky_AEC_2-1717717777857.png

Then, when it does not exist

MicZatorsky_AEC_3-1717717832409.png

It remembers.  Refactoring code to rename variables in a Notebook is fraught with danger.







clai
by
Emerging Contributor

Hi MicZatorsky,

Yes, I think that's exactly what I encountered in ArcGIS Notebook. And even I closed ArcGIS Pro and re-opened it, Notebook still remembered what I deleted. I don't know how I can clear its memories. Do you have any idea?

 

0 Kudos
MicZatorsky_AEC
Frequent Contributor

No, but I've yet to notice this persist between sessions.  A restart usually fixes it.

0 Kudos
clai
by
Emerging Contributor

You mean restarting the ArcGIS Pro software?

0 Kudos
MicZatorsky_AEC
Frequent Contributor

Standalone Jupyter notebooks have a 'Kernel > Restart" menu option, but Pro does not, so you have to restart Pro.

0 Kudos