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

Pandas NaT times cause unexpected behaviour #19

Open
GalenReich opened this issue May 14, 2024 · 1 comment
Open

Pandas NaT times cause unexpected behaviour #19

GalenReich opened this issue May 14, 2024 · 1 comment

Comments

@GalenReich
Copy link

Currently if a datetime holding the NaT value (supported by Numpy and Pandas) is passed to get_position it returns results for 12:12:43 UTC on Tuesday, September 21, 1677!

Minimum example to reproduce:

import pandas as pd
from suncalc import get_position

# Create DatetimeIndex containing NaTs
test_pandas_df = pd.to_datetime([None, None], unit="s", utc=True) 

print(get_position(test_pandas_df, 0, 0))

Gives: {'azimuth': Index([-0.9723467728956097, -0.9723467728956097], dtype='float64'), 'altitude': Index([-1.5207425775049375, -1.5207425775049375], dtype='float64')}

The bug is introduced by the coercion in get_milliseconds, which returns -9223372036854.775 (ms) for NaT values. This time offset from the UNIX epoch corresponds to the above date in 1677!

# Pandas series of Pandas datetime objects
if pd and pd.api.types.is_datetime64_any_dtype(date):
# A datetime-like series coerce to int is (always?) in nanoseconds
return date.astype('int64') / 10 ** 6

Instead, it would be great if NaT values were handled gracefully and None or np.nan values were returned instead. Alternatively, an error could be raised indicating that NaT values are unsupported.

@kylebarron
Copy link
Owner

A pull request would be welcome. I don't have the bandwidth to make updates here myself now

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

No branches or pull requests

2 participants