Skip to content
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
10 changes: 6 additions & 4 deletions packages/db-dtypes/db_dtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class TimeDtype(core.BaseDatetimeDtype):
name = time_dtype_name
type = datetime.time

def construct_array_type(self):
@classmethod
def construct_array_type(cls):
return TimeArray

@staticmethod
Expand Down Expand Up @@ -213,7 +214,8 @@ class DateDtype(core.BaseDatetimeDtype):
name = date_dtype_name
type = datetime.date

def construct_array_type(self):
@classmethod
def construct_array_type(cls):
return DateArray

@staticmethod
Expand Down Expand Up @@ -322,7 +324,7 @@ def __add__(self, other):
if isinstance(other, TimeArray):
return (other._ndarray - _NPEPOCH) + self._ndarray

return super().__add__(other)
return super().__add__(other) # type: ignore[misc]

def __radd__(self, other):
return self.__add__(other)
Expand All @@ -334,7 +336,7 @@ def __sub__(self, other):
if isinstance(other, self.__class__):
return self._ndarray - other._ndarray

return super().__sub__(other)
return super().__sub__(other) # type: ignore[misc]


def _check_python_version():
Expand Down
15 changes: 13 additions & 2 deletions packages/db-dtypes/db_dtypes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional
from typing import Optional, Callable, Any

import numpy
import pandas
Expand Down Expand Up @@ -50,6 +50,13 @@ class BaseDatetimeArray(pandas_backports.OpsMixin, _mixins.NDArrayBackedExtensio
# https://github.com/pandas-dev/pandas/blob/main/pandas/core/arrays/_mixins.py
_internal_fill_value = numpy.datetime64("NaT")

_box_func: Callable[[Any], Any]
_from_backing_data: Callable[[Any], Any]

@classmethod
def _datetime(cls, value: Any) -> Any:
raise NotImplementedError

def __init__(self, values, dtype=None, copy: bool = False):
if not (
isinstance(values, numpy.ndarray) and values.dtype == numpy.dtype("<M8[ns]")
Expand All @@ -58,7 +65,11 @@ def __init__(self, values, dtype=None, copy: bool = False):
elif copy:
values = values.copy()

super().__init__(values=values, dtype=values.dtype)
# We must pass values and dtype to the base constructor.
# Manual assignment (self._ndarray = values) will fail at runtime with
# AttributeError because the base is a Cython-backed 'NDArrayBacked'
# object with non-writable attributes.
super().__init__(values=values, dtype=values.dtype) # type: ignore[call-arg]

@classmethod
def __ndarray(cls, scalars):
Expand Down
6 changes: 3 additions & 3 deletions packages/db-dtypes/db_dtypes/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class JSONDtype(pd.api.extensions.ExtensionDtype):
name = "dbjson"

@property
def na_value(self) -> pd.NA:
def na_value(self) -> pd.NAType: # type: ignore[name-defined]
"""Default NA value to use for this type."""
return pd.NA

@property
def type(self) -> type[str]:
def type(self) -> type[str]: # type: ignore[override]
"""
Return the scalar type for the array elements.
The standard JSON data types can be one of `dict`, `list`, `str`, `int`, `float`,
Expand Down Expand Up @@ -203,7 +203,7 @@ def __getitem__(self, item):
assert item.dtype.kind == "b"
return type(self)(self.pa_data.filter(item))
elif isinstance(item, tuple):
item = indexers.unpack_tuple_and_ellipses(item)
item = indexers.unpack_tuple_and_ellipses(item) # type: ignore[attr-defined]

if common.is_scalar(item) and not common.is_integer(item):
# e.g. "foo" or 2.5
Expand Down
10 changes: 5 additions & 5 deletions packages/db-dtypes/db_dtypes/pandas_backports.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
pandas_release = packaging.version.parse(pandas.__version__).release

# # Create aliases for private methods in case they move in a future version.
nanall = pandas.core.nanops.nanall
nanany = pandas.core.nanops.nanany
nanmax = pandas.core.nanops.nanmax
nanmin = pandas.core.nanops.nanmin
nanall = pandas.core.nanops.nanall # type: ignore[attr-defined]
nanany = pandas.core.nanops.nanany # type: ignore[attr-defined]
nanmax = pandas.core.nanops.nanmax # type: ignore[attr-defined]
nanmin = pandas.core.nanops.nanmin # type: ignore[attr-defined]
numpy_validate_all = pandas.compat.numpy.function.validate_all
numpy_validate_any = pandas.compat.numpy.function.validate_any
numpy_validate_max = pandas.compat.numpy.function.validate_max
numpy_validate_min = pandas.compat.numpy.function.validate_min

nanmedian = pandas.core.nanops.nanmedian
nanmedian = pandas.core.nanops.nanmedian # type: ignore[attr-defined]
numpy_validate_median = pandas.compat.numpy.function.validate_median


Expand Down
18 changes: 15 additions & 3 deletions packages/db-dtypes/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ def core_deps_from_source(session):
@nox.session(python=DEFAULT_PYTHON_VERSION)
def mypy(session):
"""Run the type checker."""
# TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
# Add mypy tests
session.skip("mypy tests are not yet supported")
session.install(
"mypy<1.16.0",
"types-requests",
"types-protobuf",
"pandas-stubs",
)
session.install("-e", ".")
session.run(
"mypy",
"-p",
"db_dtypes",
"--check-untyped-defs",
"--ignore-missing-imports",
Comment thread
chalmerlowe marked this conversation as resolved.
*session.posargs,
)
Loading