Comments (6)
@knoopum What version of the python api are you using?
from arcgis-python-api.
@nanaeaubry whichever version Esri has packaged in ArcGIS Online Notebooks (ArcGIS Notebook Python 3 Standard - 9.0)
from arcgis-python-api.
@knoopum I followed the steps to reproduce using the ArcGIS Notebook Python 3 Standard - 9.0 runtime in ArcGIS Online Notebooks without issue. Can you post a code snippet?
Sidenote: You can check the arcgis
versions in your ArcGIS Online Notebook by running
import arcgis
arcgis.__version__
or navigating to Info > Runtime in the Notebook UI
It should be 2.2.0.1
.
from arcgis-python-api.
@tyhranac Sorry! I left off an important part of the instructions to reproduce. In step 5, when you query the table, set as_df = True.
Querying for all the records works:
Querying for a value that exists in the data also works:
Querying for a value that does not exist in the data generates the error:
from arcgis-python-api.
I've been running into this issue too.
I have a feature layer collection that has empty data but query with as_df against Feature Layer types works and queries against tables results in the same error. This is on arcgis.gis verions '2.2.0.1'.
I think the issue lies in that the "Fields" array that details all the different fields and their data types when returning just a featureset is included in for Feature Layer types but this isn't the case for Tables. So when you have date fields in a table it autos unit-less dtype.
Interestingly if you query to make it a featureset and then use the sdf method on the featureset to return a dataframe it works but returns essentially an empty dataframe with no columns or dtypes.
My work around is basically capturing the "Fields" array from the properties of the table, making a new dictionary that mimics the table featureset structure and injects the Fields array into it. Then when I create a Dataframe from this updated featureset it understands that the datetime fields should be 'datetime64[ns].
flc_master = WF_Data_All_Item.layers[0].container
wf_data = {}
for lyr in flc_master.layers + flc_master.tables:
_obj = {}
_id = lyr.properties.id
_name = lyr.properties.name
_recCount = lyr.query(where='1=1', out_fields='*',return_count_only=True)
_type = lyr.properties.type
_obj['id'] = _id
_obj['name'] = _name
_obj['record count'] = _recCount
_obj['lyr'] = lyr
_obj['type'] = _type
if _recCount == 0:
if _type == 'Feature Layer':
df = lyr.query(where='1=1', out_fields='*',as_df=True)
_obj['df'] = df
if _type == 'Table':
try:
df = lyr.query(where='1=1', out_fields='*',as_df=True)
print(df.info())
print(df)
except Exception as e:
print(e)
else:
print("Query as_df worked")
finally:
try:
df = lyr.query(where='1=1', out_fields='*').sdf
print(df.info())
print(df)
except Exception as e:
print(e)
else:
print("FeatureSet as sdf worked")
finally:
pass
fields = lyr.properties.fields
fs = lyr.query(where='1=1', out_fields='*').to_dict()
new_dict = {}
for key,value in fs.items():
if key == 'fields':
new_dict[key] = fields
else:
new_dict[key] = value
fs_new = FeatureSet.from_dict(new_dict)
df = fs_new.sdf
print(df.info())
print(df)
This outputs:
Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 0 entries
Empty DataFrame
None
Empty DataFrame
Columns: []
Index: []
FeatureSet as sdf worked
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 0 entries
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 name 0 non-null string
1 contactnumber 0 non-null string
2 userid 0 non-null string
3 GlobalID 0 non-null string
4 wfprivileges 0 non-null string
5 CreationDate 0 non-null datetime64[us]
6 Creator 0 non-null string
7 EditDate 0 non-null datetime64[us]
8 Editor 0 non-null string
9 Project 0 non-null string
10 OG 0 non-null string
11 OBJECTID 0 non-null Int64
dtypes: Int64(1), datetime64[us](2), string(9)
memory usage: 124.0 bytes
None
Empty DataFrame
Columns: [name, contactnumber, userid, GlobalID, wfprivileges, CreationDate, Creator, EditDate, Editor, Project, OG, OBJECTID]
Index: []
Casting to unit-less dtype 'datetime64' is not supported. Pass e.g. 'datetime64[ns]' instead.
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 0 entries
Empty DataFrame
None
Empty DataFrame
Columns: []
Index: []
FeatureSet as sdf worked
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 0 entries
Data columns (total 10 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 description 0 non-null string
1 GlobalID 0 non-null string
2 CreationDate 0 non-null datetime64[us]
3 Creator 0 non-null string
4 EditDate 0 non-null datetime64[us]
5 Editor 0 non-null string
6 Sequence 0 non-null Int32
7 Project 0 non-null string
8 OG 0 non-null string
9 OBJECTID 0 non-null Int64
dtypes: Int32(1), Int64(1), datetime64[us](2), string(6)
memory usage: 124.0 bytes
None
Empty DataFrame
Columns: [description, GlobalID, CreationDate, Creator, EditDate, Editor, Sequence, Project, OG, OBJECTID]
Index: []
from arcgis-python-api.
@knoopum can you please export your table to a FGDB and share it? or share the URL?
from arcgis-python-api.
Related Issues (20)
- Property resouces of Server class is misspelled. HOT 1
- Identify a StoryMap's Theme HOT 7
- AttributeError: 'Server' object has no attribute 'services' HOT 1
- Empty SHAPE HOT 4
- Efficient way to identify ArcGIS Online Named User Pro licenses that have been taken offline HOT 1
- Why is the Folders class not named FolderManager? HOT 3
- workforce.Project.assignment.add() - TypeError: Object of type FeatureSet is not JSON serializable (Did not exist in previous version)
- Upload a photo returns 'Item type not valid.' HOT 2
- `sources` endpoint for hosted views is not exposed
- GeoAccessor.to_featureclass function converting all column names to lowercase when sanitize_columns parameter is True HOT 1
- Publish function for shapefile items create duplicate indexes for area and length HOT 10
- In clone_items, a valid name is not always created if the name of the original item is missing (None) HOT 1
- FeatureLayerCollectionManager insert_layer() fails with unknown error HOT 9
- License.all() returns incorrect results for orgs with >10,000 users
- to_featureset() is not handling fields with null date values correctly HOT 7
- Extract_Changes failing to return proper edit arrays HOT 3
- Feature Layer query() using return_all_records does not return all records HOT 5
- Esri job failed when using content.add() HOT 2
- ArcGIS API for Python StoryMaps v 2.3.0 Issues on StoryMap Publishing ("get" & "node" deprecation and content_list alternative) HOT 11
- _register_extension() method attached to incorrect Class - Service, not ServiceManager HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arcgis-python-api.