-
Notifications
You must be signed in to change notification settings - Fork 901
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
ENH: explore(): skip if fields/index are Timestamp #2378
Comments
Thanks for linking the issue and the WIP PR. Closing here as a dup |
Apologies not related to the API here but it seems other interactive plotting options handle the date dtype ok. Linking as one could dig into source code there to help here. I understand this is outside of json encoding but may help with the plotting issue.
|
@raybellwaves can you move this to one of the open issues linked above? It'll get lost here. |
@martinfleis if ok. I'll repopen this. To summarize: this issue is for discussion on how to currently use #1906 is how to handle low level json serialization for datetime and geometry fields (the core underlying issue here). |
@raybellwaves why do you propose that timestamps should be removed? It would make more sense if they are converted to numeric if the This way, you can read the date on the pop-up, and you can get a color change indicating how far along the timeline you are. I have started to use the following work-around: def explore(gdf: gpd.GeoDataFrame, *args, column=None, **kwargs) -> folium.Map:
"""Version of `GeoDataFrame.explore()` method that handles columns of
DateTime64 somewhat reasonably. All arguments are passed on to `.explore()` after
handling DateTime64 columns in `gdf` or `column`.
Can be used in a pipe like so:
gdf.pipe(explore, m=m, column="datetime64_col", name="time")"""
dt_columns = gdf.select_dtypes(["datetime64", "timedelta64"]).columns
if isinstance(column, str):
column = gdf[column]
if pd.api.types.is_datetime64_any_dtype(column):
column = column.astype("int64")
# this keeps the branca from encountering an overflow in long_scalars
column = column-column.min()
column = column / column.max()
gdf = gdf[:]
gdf[dt_columns] = gdf[dt_columns].astype("str")
return gdf.explore(*args, column=column, **kwargs) xs, ys =np.random.rand(20)+np.linspace(0,5, 20), np.random.rand(20)+np.linspace(0,5, 20)
gdf = gpd.GeoDataFrame({
"id": "a",
"timestamp1": pd.date_range("2020-01-01", "2020-10-10", 20),
"timestamp2": pd.date_range("2020-01-01", "2020-10-10", 20),
"geometry": gpd.points_from_xy(xs, ys)
}
)
gdf.pipe(explore, column="timestamp1") As you can see in the screenshot, additional arguments are passed on without problems. Of course things like the colorbar needs better labels, but it is good enough that one can use |
The same situation applies to other non-serializable types. In my case it was a column of |
That would be ideal. Would you, or anyone else, be willing to do a PR for that? |
Just ran into this issue again, working with GeoDataFrame with a DateTimeIndex. Any more recent efforts to fix? The |
@dshean sorry, not yet. It will be fixed by 1.0. |
@martinfleis is it fixed in 1.0? |
@anitagraser Will be once #3261 is merged. It is not in the alpha but will be in the RC. |
Is your feature request related to a problem?
Running
gdf.explore
and gettingTypeError: Object of type Timestamp is not JSON serializable
when a dataframe has a dtype datetime64Describe the solution you'd like
Raise a warning and have output behave like explore without the datetime fields.
skip_datetime_fields arg in
explore
?API breaking implications
None
Describe alternatives you've considered
This one liner may fix it:
Additional context
Goes into folium/ipython traceback so may be worth upstreaming the issue (or finding the issue if it exists)
Traceback:
The text was updated successfully, but these errors were encountered: