Skip to content
Open
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
3 changes: 1 addition & 2 deletions packages/db-dtypes/db_dtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
time_dtype_name = "dbtime"
_EPOCH = datetime.datetime(1970, 1, 1)
_NPEPOCH = numpy.datetime64(_EPOCH, "ns")
_NP_DTYPE = "datetime64[ns]"

# Numpy converts datetime64 scalars to datetime.datetime only if microsecond or
# smaller precision is used.
Expand Down Expand Up @@ -168,7 +167,7 @@ def _box_func(self, x):
) # Integers are stored with nanosecond precision.
return x.astype(_NP_BOX_DTYPE).item().time()

__return_deltas = {"timedelta", "timedelta64", "timedelta64[ns]", "<m8", _NP_DTYPE}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this was the last use of _NP_DTYPE, so could we remove that constant too?

__return_deltas = {"timedelta", "timedelta64", "timedelta64[ns]", "<m8", "<m8[ns]"}

def astype(self, dtype, copy=True):
deltas = self._ndarray - _NPEPOCH
Expand Down
7 changes: 7 additions & 0 deletions packages/db-dtypes/tests/unit/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ def test_asdatetime(dtype, same):
assert pd.isna(b[2]) and str(b[2]) == "NaT"


@pytest.mark.parametrize("dtype", ["datetime64[ns]", np.dtype("datetime64[ns]")])
def test_timearray_astype_datetime64(dtype):
arr = _cls("dbtime")(["12:34:56"])
with pytest.raises(TypeError):
arr.astype(dtype)


@pytest.mark.parametrize(
"dtype",
[
Expand Down
Loading