diff --git a/packages/db-dtypes/db_dtypes/__init__.py b/packages/db-dtypes/db_dtypes/__init__.py index 0718a2ca4a46..a45dff80081f 100644 --- a/packages/db-dtypes/db_dtypes/__init__.py +++ b/packages/db-dtypes/db_dtypes/__init__.py @@ -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 @@ -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 @@ -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) @@ -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(): diff --git a/packages/db-dtypes/db_dtypes/core.py b/packages/db-dtypes/db_dtypes/core.py index 926a11094018..6baa46cf2d2d 100644 --- a/packages/db-dtypes/db_dtypes/core.py +++ b/packages/db-dtypes/db_dtypes/core.py @@ -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 @@ -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(" 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`, @@ -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 diff --git a/packages/db-dtypes/db_dtypes/pandas_backports.py b/packages/db-dtypes/db_dtypes/pandas_backports.py index 378bb41708f7..c9a658c2006e 100644 --- a/packages/db-dtypes/db_dtypes/pandas_backports.py +++ b/packages/db-dtypes/db_dtypes/pandas_backports.py @@ -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 diff --git a/packages/db-dtypes/noxfile.py b/packages/db-dtypes/noxfile.py index c7200dce77f1..d8736dca1da3 100644 --- a/packages/db-dtypes/noxfile.py +++ b/packages/db-dtypes/noxfile.py @@ -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", + *session.posargs, + )