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

Convert datetimes explicitly to int64 not int #25

Merged
merged 1 commit into from
May 28, 2024

Conversation

jashlearn
Copy link
Collaborator

On at least one platform (Windows I think) I've seen while working with someone else int can be a 32-bit integer and the conversion from numpy datetime64/timedelta64 objects fail to convert to 32-bit integers (fair enough due to overflow possibilities). But we don't care about the size of the integer, we just want the conversion to work, and so I've changed to explicitly converting to 64-bit integers.
There's generally also some suspicious stuff going on in gn_datetime but I didn't bother looking at it at this stage, just making the minimal changes needed at this stage.

Copy link
Collaborator

@ronaldmaj ronaldmaj left a comment

Choose a reason for hiding this comment

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

Had a quick test of this, seems to work fine on a couple datetime conversions I did with relevant functions:

In [15]: dt = datetime(year=2024, month=5, day=28,hour=4,minute=37)
...
In [21]: datetime2j2000(np.array(dt))
Out[21]: 770143020

In [22]: datetime2gpsweeksec(np.array(dt))
Out[22]: (2316, 189420)

There are other errors that seem to be causing problems, but these aren't related to your change, e.g.:

In [20]: datetime2yydoysec(np.array(dt))
---------------------------------------------------------------------------
UFuncTypeError                            Traceback (most recent call last)
Cell In[20], line 1
----> 1 datetime2yydoysec(np.array(dt))

File /data/review-repos/gnssanalysis/gnssanalysis/gn_datetime.py:165, in datetime2yydoysec(datetime)
    163 datetime_D = datetime.astype("datetime64[D]")
    164 doy = _pd.Series((datetime_D - datetime_Y).astype("int64").astype(str))
--> 165 seconds = _pd.Series((datetime - datetime_D).astype("timedelta64[s]").astype("int64").astype(str))
    166 yydoysec = (
    167     _pd.Series(datetime_Y.astype(str)).str.slice(2).values
    168     + ":"
   (...)
    171     + seconds.str.zfill(5).values
    172 )
    173 return yydoysec

UFuncTypeError: ufunc 'subtract' cannot use operands with types dtype('O') and dtype('<M8[D]')

Happy for this PR to go in

@ronaldmaj ronaldmaj merged commit 01730d1 into GeoscienceAustralia:main May 28, 2024
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