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

[DOCS] Updated docstring for date2num #467

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cf_units/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,14 +1861,18 @@ def date2num(self, date):
Works for scalars, sequences and numpy arrays. Returns a scalar
if input is a scalar, else returns a numpy array.

Return type will be of type `integer` if (all) the times can be
encoded exactly as an integer with the specified units,
otherwise a float type will be returned.

Args:

* date (datetime):
A datetime object or a sequence of datetime objects.
The datetime objects should not include a time-zone offset.

Returns:
float or numpy.ndarray of float.
float/integer or numpy.ndarray of floats/integers

For example:

Expand All @@ -1882,6 +1886,11 @@ def date2num(self, date):
... datetime.datetime(1970, 1, 1, 6, 30)])
array([5.5, 6.5])

# Integer type preferentially returned if possible:
>>> u.date2num([datetime.datetime(1970, 1, 1, 5, 0),
... datetime.datetime(1970, 1, 1, 6, 0)])
array([5, 6])

"""
return cftime.date2num(date, self.cftime_unit, self.calendar)

Expand Down
Loading