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

implicit casting for dt.datetime #95

Merged
merged 4 commits into from
Sep 26, 2023
Merged

Conversation

emanuel-schmid
Copy link
Contributor

@emanuel-schmid emanuel-schmid commented Sep 26, 2023

Changes proposed in this PR:

  • implicit casting to integer when calling dt.datetime()

This PR fixes #96

PR Author Checklist

PR Reviewer Checklist

@tovogt
Copy link
Collaborator

tovogt commented Sep 26, 2023

Why is this necessary? The used dt.year, dt.month and dt.day accessors should return integer types already, right? https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dt.month.html

@emanuel-schmid
Copy link
Contributor Author

@tovogt right! But that will eventually have changed by python 3.11.

(However - since python 3.11 also seems to inhibit the lint stage of the jenkins pipeline I'm going to re-pin it to python 3.9.)

@tovogt
Copy link
Collaborator

tovogt commented Sep 26, 2023

Ah, now I get it. The problem is not that the dtype is wrong, but the problem is that the expression track.time.dt.year[0] still returns a DataArray object with zero dimensions (i.e., a scalar). In this case, I suggest to use the expression track.time.dt.year.values[0] instead (as is already done in climada.hazard.trop_cyclone in CLIMADA-project/climada_python@7ba187b).

Copy link
Collaborator

@tovogt tovogt left a comment

Choose a reason for hiding this comment

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

Suggestions to solve this issue similar to the code in climada.hazard.trop_cyclone (CLIMADA-project/climada_python@7ba187b)

climada_petals/hazard/river_flood.py Outdated Show resolved Hide resolved
climada_petals/hazard/tc_rainfield.py Outdated Show resolved Hide resolved
@emanuel-schmid
Copy link
Contributor Author

🙌 @tovogt, perfect!

@emanuel-schmid emanuel-schmid merged commit 74a7126 into develop Sep 26, 2023
3 checks passed
@emanuel-schmid emanuel-schmid deleted the fix/implicit_int_casting branch September 26, 2023 15:33
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