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

Apply typing.Literal whereever appropriate #4803

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions py/server/deephaven/dbc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
#
"""The dbc package includes the modules and functions for using external databases with Deephaven."""
from typing import Any
from typing import Any, Literal

import deephaven.arrow as dharrow
from deephaven import DHError
from deephaven.table import Table


def read_sql(conn: Any, query: str, driver: str = "connectorx") -> Table:
def read_sql(conn: Any, query: str, driver: Literal["odbc", "adbc", "connectorx"] = "connectorx") -> Table:
"""Executes the provided SQL query via a supported driver and returns a Deephaven table.

Args:
Expand Down
6 changes: 3 additions & 3 deletions py/server/deephaven/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

""" This module supports the conversion between Deephaven tables and pandas DataFrames. """
from typing import List, Dict, Tuple
from typing import List, Dict, Tuple, Literal

import jpy
import numpy as np
Expand Down Expand Up @@ -112,8 +112,8 @@ def _column_to_series(table: Table, col_def: Column, conv_null: bool) -> pd.Seri
}


def to_pandas(table: Table, cols: List[str] = None, dtype_backend: str = None, conv_null: bool = True) -> \
pd.DataFrame:
def to_pandas(table: Table, cols: List[str] = None, dtype_backend: Literal[None, "pyarrow", "numpy_nullable"] = None,
conv_null: bool = True) -> pd.DataFrame:
"""Produces a pandas DataFrame from a table.

Note that the **entire table** is going to be cloned into memory, so the total number of entries in the table
Expand Down
2 changes: 0 additions & 2 deletions py/server/deephaven/table_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
_JFunctionGeneratedTableFactory = jpy.get_type("io.deephaven.engine.table.impl.util.FunctionGeneratedTableFactory")



def empty_table(size: int) -> Table:
"""Creates a table with rows but no columns.

Expand Down Expand Up @@ -395,7 +394,6 @@ def function_generated_table(table_generator: Callable[..., Table],
if exec_ctx is None:
raise ValueError("No execution context is available and exec_ctx was not provided! ")


def table_generator_function():
with exec_ctx:
result = table_generator(*args, **kwargs)
Expand Down
9 changes: 5 additions & 4 deletions py/server/deephaven/table_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from abc import ABC, abstractmethod
from functools import wraps
from inspect import signature
from typing import Callable, Union, List, Generator, Dict, Optional
from typing import Callable, Union, List, Generator, Dict, Optional, Literal

import jpy
import numpy
Expand Down Expand Up @@ -237,7 +237,8 @@ def modified_columns(self) -> List[str]:
return list(cols) if cols else []


def _do_locked(ug: Union[UpdateGraph, Table], f: Callable, lock_type="shared") -> None:
def _do_locked(ug: Union[UpdateGraph, Table], f: Callable, lock_type: Literal["shared","exclusive"] = "shared") -> \
None:
"""Executes a function while holding the UpdateGraph (UG) lock. Holding the UG lock
ensures that the contents of a table will not change during a computation, but holding
the lock also prevents table updates from happening. The lock should be held for as little
Expand Down Expand Up @@ -308,7 +309,7 @@ def _wrap_listener_obj(t: Table, listener: TableListener):


def listen(t: Table, listener: Union[Callable, TableListener], description: str = None, do_replay: bool = False,
replay_lock: str = "shared"):
replay_lock: Literal["shared", "exclusive"] = "shared"):
"""This is a convenience function that creates a TableListenerHandle object and immediately starts it to listen
for table updates.

Expand Down Expand Up @@ -372,7 +373,7 @@ def __init__(self, t: Table, listener: Union[Callable, TableListener], descripti

self.started = False

def start(self, do_replay: bool = False, replay_lock: str = "shared") -> None:
def start(self, do_replay: bool = False, replay_lock: Literal["shared", "exclusive"] = "shared") -> None:
"""Start the listener by registering it with the table and listening for updates.

Args:
Expand Down
9 changes: 4 additions & 5 deletions py/server/deephaven/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from __future__ import annotations

import datetime
from typing import Union, Optional
from typing import Union, Optional, Literal

import jpy
import numpy
Expand All @@ -32,7 +32,7 @@
# region Clock


def dh_now(system: bool = False, resolution: str = 'ns') -> Instant:
def dh_now(system: bool = False, resolution: Literal["ns", "ms"] = "ns") -> Instant:
""" Provides the current datetime according to the current Deephaven clock.

Query strings should use the built-in "now" function instead of this function.
Expand All @@ -43,9 +43,8 @@ def dh_now(system: bool = False, resolution: str = 'ns') -> Instant:
system (bool): True to use the system clock; False to use the default clock. Under most circumstances,
the default clock will return the current system time, but during replay simulations, the default
clock can return the replay time.

resolution (str): The resolution of the returned time. The default 'ns' will return nanosecond resolution times
if possible. 'ms' will return millisecond resolution times.
resolution (str): The resolution of the returned time. The default "ns" will return nanosecond resolution times
if possible. "ms" will return millisecond resolution times.

Returns:
Instant
Expand Down
Loading