Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ee_to_df Make prop names and col names same #1703

Merged
merged 1 commit into from
Sep 15, 2023
Merged

ee_to_df Make prop names and col names same #1703

merged 1 commit into from
Sep 15, 2023

Conversation

jdbcode
Copy link
Collaborator

@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
13 checks passed
@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.

2 participants