Skip to main content

Introducing Deephaven's new calendar API

· 3 min read
AI prompt: a line chart sitting on top of a monthly calendar with visible dates
Elijah Petty
Enhanced calendar functions boost performance

Deephaven 0.32.0 introduced a number of new features, as well as improvements to old ones. Key features of the overhauled calendar API include:

  • An updated Java calendar API that boosts performance in table operations.
  • A streamlined Python API designed to minimize the chances of calling Python from query strings.
  • Simple and intuitive naming conventions for ease of use.
  • Support for user-defined calendars.
  • Conversion between Deephaven and NumPy calendar formats.

New calendar methods

The new Python API is designed to be minimal, and facilitate the use of the Java API in query strings. The new calendar class provides the following methods:

add_calendarAdds a new business calendar to the set of available options.
calendarRetrieves the calendar with the given name.
calendar_nameReturns the name of the default calendar.
calendar_namesReturns the names of all available calendars.
remove_calendarRemoves the given business calendar from the set of available options.
set_calendarSets the default calendar.

Example calendars

Deephaven provides three example calendars: USBANK_EXAMPLE, USNYSE_EXAMPLE, and UTC.

from deephaven.calendar import calendar_names

These example calendars are intended for learning, demonstration, and testing purposes - not production. Deephaven makes no guarantees about the accuracy of these calendars.

User-defined business calendars

Deephaven now allows users to create their own business calendars. First, create an XML file for the calendar.

To view the example calendar's XML format, click here.
Test calendar for the year 2024.
This calendar uses two business periods instead of one.
The periods are separated by a one hour lunch break.
This calendar file defines standard business hours, weekends, and holidays.

Now add it to the list of available calendars:

from deephaven.calendar import add_calendar, calendar


test_cal_2024 = calendar("TestCalendar_2024")

Convert calendars to numpy business calendars

Deephaven's numpy module has been updated with the to_np_busdaycalendar method, which converts a Deephaven calendar to a numpy business calendar:

from deephaven.calendar import calendar
from deephaven.numpy import to_np_busdaycalendar

cal = calendar()

result = to_np_busdaycalendar(cal)


Reach out

Our Community documentation has all of the resources you need to become a Deephaven power user. Our Slack community continues to grow, and we'd love to have you join us! If you have any questions, comments, or suggestions, please reach out to us there.