Skip to content

Commit 6d602aa

Browse files
committed
feat: fix remaining mypy errors in db-dtypes
1 parent 663d7fe commit 6d602aa

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

packages/db-dtypes/db_dtypes/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class TimeDtype(core.BaseDatetimeDtype):
5555
name = time_dtype_name
5656
type = datetime.time
5757

58-
def construct_array_type(self):
58+
@classmethod
59+
def construct_array_type(cls):
5960
return TimeArray
6061

6162
@staticmethod
@@ -213,7 +214,8 @@ class DateDtype(core.BaseDatetimeDtype):
213214
name = date_dtype_name
214215
type = datetime.date
215216

216-
def construct_array_type(self):
217+
@classmethod
218+
def construct_array_type(cls):
217219
return DateArray
218220

219221
@staticmethod
@@ -322,7 +324,7 @@ def __add__(self, other):
322324
if isinstance(other, TimeArray):
323325
return (other._ndarray - _NPEPOCH) + self._ndarray
324326

325-
return super().__add__(other)
327+
return super().__add__(other) # type: ignore[misc]
326328

327329
def __radd__(self, other):
328330
return self.__add__(other)
@@ -334,7 +336,7 @@ def __sub__(self, other):
334336
if isinstance(other, self.__class__):
335337
return self._ndarray - other._ndarray
336338

337-
return super().__sub__(other)
339+
return super().__sub__(other) # type: ignore[misc]
338340

339341

340342
def _check_python_version():

packages/db-dtypes/db_dtypes/core.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Optional
15+
from typing import Optional, Callable, Any
1616

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

53+
_box_func: Callable[[Any], Any]
54+
_from_backing_data: Callable[[Any], Any]
55+
56+
@classmethod
57+
def _datetime(cls, value: Any) -> Any:
58+
raise NotImplementedError
59+
5360
def __init__(self, values, dtype=None, copy: bool = False):
5461
if not (
5562
isinstance(values, numpy.ndarray) and values.dtype == numpy.dtype("<M8[ns]")
@@ -164,17 +171,17 @@ def min(self, *, axis: Optional[int] = None, skipna: bool = True, **kwargs):
164171
values=self._ndarray, axis=axis, mask=self.isna(), skipna=skipna
165172
)
166173
if axis is None or self.ndim == 1:
167-
return self._box_func(result) # type: ignore[attr-defined]
168-
return self._from_backing_data(result) # type: ignore[attr-defined]
174+
return self._box_func(result)
175+
return self._from_backing_data(result)
169176

170177
def max(self, *, axis: Optional[int] = None, skipna: bool = True, **kwargs):
171178
pandas_backports.numpy_validate_max((), kwargs)
172179
result = pandas_backports.nanmax(
173180
values=self._ndarray, axis=axis, mask=self.isna(), skipna=skipna
174181
)
175182
if axis is None or self.ndim == 1:
176-
return self._box_func(result) # type: ignore[attr-defined]
177-
return self._from_backing_data(result) # type: ignore[attr-defined]
183+
return self._box_func(result)
184+
return self._from_backing_data(result)
178185

179186
def median(
180187
self,
@@ -191,5 +198,5 @@ def median(
191198
)
192199
result = pandas_backports.nanmedian(self._ndarray, axis=axis, skipna=skipna)
193200
if axis is None or self.ndim == 1:
194-
return self._box_func(result) # type: ignore[attr-defined]
195-
return self._from_backing_data(result) # type: ignore[attr-defined]
201+
return self._box_func(result)
202+
return self._from_backing_data(result)

packages/db-dtypes/db_dtypes/json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class JSONDtype(pd.api.extensions.ExtensionDtype):
3232
name = "dbjson"
3333

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

@@ -203,7 +203,7 @@ def __getitem__(self, item):
203203
assert item.dtype.kind == "b"
204204
return type(self)(self.pa_data.filter(item))
205205
elif isinstance(item, tuple):
206-
item = indexers.unpack_tuple_and_ellipses(item)
206+
item = indexers.unpack_tuple_and_ellipses(item) # type: ignore[attr-defined]
207207

208208
if common.is_scalar(item) and not common.is_integer(item):
209209
# e.g. "foo" or 2.5

0 commit comments

Comments
 (0)