Skip to content

Conversation

@jdbcode
Copy link
Member

@jdbcode jdbcode commented Sep 15, 2023

In ee_to_df, non-geometry features are created using toDictionary with the default setting, which excludes non-system properties. Later, when the dataframe is subset by the col_names parameter, if the default column names (None) is used, column names are fetched from a representative feature using propertyNames, which includes system properties. The two lists should be the same to avoid errors.

The fix is to get propertyNames and use the variable for both creating features and later subsetting dataframe columns.

This code demonstrates the issue:

import geemap
import ee
ee.Authenticate()
ee.Initialize()

img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508')

# sample image and copy image properties to each feature
samp = img.sample(numPixels=10).map(
    lambda feature: feature.copyProperties(img, img.propertyNames()))

df = geemap.ee_to_df(samp)
df

@jdbcode jdbcode requested a review from giswqs September 15, 2023 20:55
@jdbcode jdbcode changed the title Make prop names and col names same ee_to_df Make prop names and col names same Sep 15, 2023
@giswqs
Copy link
Member

giswqs commented Sep 15, 2023

Good suggestion! Thanks for the fix.

Copy link
Member

@giswqs giswqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@giswqs giswqs merged commit a8b852e into master Sep 15, 2023
@giswqs giswqs deleted the ee_to_df_fix branch September 15, 2023 21:01
@github-actions
Copy link

@github-actions github-actions bot temporarily deployed to pull request September 15, 2023 21:01 Inactive
jgarcia525 pushed a commit to jgarcia525/geemap that referenced this pull request Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants