Select to view content in your preferred language

ArcGIS Python API 2.0.1 from_layer() automatically converts null strings to "None"

708
7
10-25-2022 11:57 AM
JohnHuillery1
Occasional Contributor

Since upgrading to version 2.0.1 I have noticed null string fields are automatically converted to the string "None".  

 

 

df = pd.DataFrame.spatial.from_layer(<valid_layer>)

 

 

 And I get something like this:

string_column1string_column2int_columntime_column
NoneNone201:54.9
NoneNone123:17.4
NoneNone236:55.4
NoneNone138:04.4

 

How do I disable this behaviour?

0 Kudos
7 Replies
jcarlson
MVP Esteemed Contributor

Is it literally the string None? Keep in mind that a dataframe will display that for null string fields.

If you want to check, try df.loc[:['string_column1', 'string_column2'].isna() to see which values are truly not there.

jcarlson_0-1666729289439.png

 

- Josh Carlson
Kendall County GIS
0 Kudos
jcarlson
MVP Esteemed Contributor

Oh, and to your question of "how do I disable" this, just call fillna('') on those columns, and the nulls will be replaced with empty strings, or whatever else you decide to put in.

- Josh Carlson
Kendall County GIS
0 Kudos
JohnHuillery1
Occasional Contributor

Yes it is literally the string "None"

0 Kudos
jcarlson
MVP Esteemed Contributor

That's very strange. Even though from_layer is really just doing FeatureLayer.query(as_df=True) on the back end, I sometimes see inexplicable differences between the two.

Can you try valid_layer.query(as_df=True) to see if it behaves the same way?

- Josh Carlson
Kendall County GIS
0 Kudos
JohnHuillery1
Occasional Contributor

I've tried that as well and it gives me the same results.

I've reverted back to a previous version.

0 Kudos
jcarlson
MVP Esteemed Contributor

And v 2.0.0 doesn't do this? Have you tested it against other sources? I wonder if it's got to do with the underlying DB the data is being stored in. I'm on 2.0.1 and do not see this behavior.

- Josh Carlson
Kendall County GIS
0 Kudos
JohnHuillery1
Occasional Contributor

v2.0.0 does not do this. I have tested it on other feature services - same result.

Can you replicate it when using the df.spatial.to_featureclass() or df.to_clipboard() methods?

0 Kudos