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

Transition to python using native python time types instead of Java types #4388

Merged
merged 43 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fa56930
Implementing new time conversions.
chipkent Aug 22, 2023
aca48d2
Code formatting
chipkent Aug 22, 2023
7473493
Better error handling
chipkent Aug 23, 2023
01af7bc
Support string conversions.
chipkent Aug 23, 2023
47feee4
Added docs strings and removed deprecated methods.
chipkent Aug 23, 2023
6b97b11
Cleanup
chipkent Aug 23, 2023
549d5d7
Docs
chipkent Aug 23, 2023
ed8fc42
Cleanup
chipkent Aug 23, 2023
d81129b
Unit testing
chipkent Aug 25, 2023
66e199d
Unit testing
chipkent Aug 25, 2023
0ba8839
Unit testing
chipkent Aug 25, 2023
28ddac2
Unit testing
chipkent Aug 25, 2023
e94093e
Unit testing
chipkent Aug 25, 2023
af454eb
Unit testing
chipkent Aug 25, 2023
76e221f
Unit testing
chipkent Aug 28, 2023
37ceba4
Todos. Docs.
chipkent Aug 28, 2023
f5e7659
Todos. Docs.
chipkent Aug 28, 2023
69a78e0
Unit test fixes
chipkent Aug 28, 2023
f5640b8
Unit test fixes. Support other methods that accept other time types.
chipkent Aug 28, 2023
86501d3
Addressing review comments
chipkent Aug 30, 2023
1911a14
Addressing review comments
chipkent Aug 30, 2023
f285952
Addressing review comments
chipkent Aug 30, 2023
8a42dd3
Addressing review comments
chipkent Aug 30, 2023
aee85fa
Addressing review comments
chipkent Aug 30, 2023
bf75cc3
Addressing review comments
chipkent Aug 30, 2023
33deae6
Addressing review comments. Support more types.
chipkent Aug 31, 2023
4958636
Addressing review comments. Code format.
chipkent Aug 31, 2023
0aa2a15
Addressing review comments.
chipkent Aug 31, 2023
c34817b
Addressing review comments.
chipkent Aug 31, 2023
dd79ef6
Addressing review comments.
chipkent Aug 31, 2023
093c1ad
Update py/server/deephaven/time.py
chipkent Aug 31, 2023
f5f34eb
Addressing review comments.
chipkent Aug 31, 2023
366b301
Merge remote-tracking branch 'origin/native_py_time' into native_py_time
chipkent Aug 31, 2023
84e74dd
Addressing review comments.
chipkent Aug 31, 2023
9560317
Addressing review comments.
chipkent Aug 31, 2023
d8de71f
Addressing review comments.
chipkent Aug 31, 2023
e031a1e
Addressing review comments.
chipkent Aug 31, 2023
ab8bf4e
Rebase
chipkent Aug 31, 2023
7bd1a91
Addressing review comments.
chipkent Aug 31, 2023
9fad38b
Removed todos
chipkent Aug 31, 2023
aedc7b9
Addressing review. Removing unneeded jpy imports.
chipkent Sep 1, 2023
176f668
Addressing review.
chipkent Sep 1, 2023
cf56896
Addressing review. Reduce exception depth.
chipkent Sep 1, 2023
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
6 changes: 4 additions & 2 deletions py/server/deephaven/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import jpy

import deephaven.dtypes as dtypes
from deephaven import DHError
from deephaven import DHError, time
from deephaven.dtypes import DType

_JColumnHeader = jpy.get_type("io.deephaven.qst.column.header.ColumnHeader")
Expand Down Expand Up @@ -196,11 +196,13 @@ def datetime_col(name: str, data: Sequence) -> InputColumn:

Args:
name (str): the column name
data (Any): a sequence of Datetime instances
data (Any): a sequence of Datetime instances or values that can be converted to Datetime instances
(e.g. Instant, int nanoseconds since the Epoch, str, datetime.datetime, numpy.datetime64, pandas.Timestamp).

Returns:
a new input column
"""
data = [time.to_j_instant(d) for d in data]
return InputColumn(name=name, data_type=dtypes.Instant, input_data=data)


Expand Down
22 changes: 12 additions & 10 deletions py/server/deephaven/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from typing import Union
import jpy

import datetime
import numpy as np
import pandas as pd

from deephaven import dtypes, DHError, time
from deephaven._wrapper import JObjectWrapper
from deephaven.table import Table
Expand All @@ -23,23 +27,21 @@ class TableReplayer(JObjectWrapper):

j_object_type = _JReplayer

def __init__(self, start_time: Union[dtypes.Instant,str], end_time: Union[dtypes.Instant,str]):
def __init__(self, start_time: Union[dtypes.Instant, int, str, datetime.datetime, np.datetime64, pd.Timestamp],
end_time: Union[dtypes.Instant, int, str, datetime.datetime, np.datetime64, pd.Timestamp]):
"""Initializes the replayer.

Args:
start_time (DateTime): replay start time
end_time (DateTime): replay end time
start_time (Union[dtypes.Instant, int, str, datetime.datetime, np.datetime64, pd.Timestamp]):
replay start time. Integer values are nanoseconds since the Epoch.
end_time (Union[dtypes.Instant, int, str, datetime.datetime, np.datetime64, pd.Timestamp]):
replay end time. Integer values are nanoseconds since the Epoch.

Raises:
DHError
"""

if isinstance(start_time, str):
start_time = time.parse_instant(start_time)

if isinstance(end_time, str):
end_time = time.parse_instant(end_time)

start_time = time.to_j_instant(start_time)
end_time = time.to_j_instant(end_time)
self.start_time = start_time
self.end_time = end_time
try:
Expand Down
29 changes: 22 additions & 7 deletions py/server/deephaven/table_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
""" This module provides various ways to make a Deephaven table. """

from typing import List, Dict, Any, Union, Sequence
import datetime

import jpy
import numpy as np
import pandas as pd

from deephaven import DHError
from deephaven import DHError, time
from deephaven._wrapper import JObjectWrapper
from deephaven.column import InputColumn, Column
from deephaven.dtypes import DType
from deephaven.dtypes import DType, Duration, Instant
from deephaven.jcompat import to_sequence
from deephaven.table import Table
from deephaven.update_graph import auto_locking_ctx
Expand Down Expand Up @@ -47,14 +50,18 @@ def empty_table(size: int) -> Table:
raise DHError(e, "failed to create an empty table.") from e


def time_table(period: Union[str, int], start_time: str = None, blink_table: bool = False) -> Table:
def time_table(period: Union[Duration, int, str, datetime.timedelta, np.timedelta64, pd.Timedelta],
start_time: Union[None, Instant, int, str, datetime.datetime, np.datetime64, pd.Timestamp] = None,
blink_table: bool = False) -> Table:
"""Creates a table that adds a new row on a regular interval.

Args:
period (Union[str, int]): time interval between new row additions, can be expressed as an integer in
nanoseconds or a time interval string, e.g. "PT00:00:00.001" or "PT1s"
start_time (str, optional): start time for adding new rows, defaults to None which means use the current time
as the start time
period (Union[dtypes.Duration, int, str, datetime.timedelta, np.timedelta64, pd.Timedelta]):
time interval between new row additions, can be expressed as an integer in nanoseconds,
a time interval string, e.g. "PT00:00:00.001" or "PT1s", or other time duration types.
start_time (Union[None, str, datetime.datetime, np.datetime64], optional):
start time for adding new rows, defaults to None which means use the current time
as the start time.
blink_table (bool, optional): if the time table should be a blink table, defaults to False

Returns:
Expand All @@ -65,11 +72,19 @@ def time_table(period: Union[str, int], start_time: str = None, blink_table: boo
"""
try:
builder = _JTableTools.timeTableBuilder()

if not isinstance(period, str) and not isinstance(period, int):
period = str(time.to_j_duration(period))

builder.period(period)

if start_time:
start_time = str(time.to_j_instant(start_time))
builder.startTime(start_time)

if blink_table:
builder.blinkTable(blink_table)

return Table(j_table=builder.build())
except Exception as e:
raise DHError(e, "failed to create a time table.") from e
Expand Down
Loading