Skip to content

Commit 8fa5f49

Browse files
authored
chore: cleanup type errors in bigframes/core/indexes/base.py (#762)
1 parent c254e9c commit 8fa5f49

File tree

2 files changed

+13
-7
lines changed
  • bigframes/core/indexes
  • third_party/bigframes_vendored/pandas/core/indexes

2 files changed

+13
-7
lines changed

bigframes/core/indexes/base.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ def __new__(
9090
# TODO: Support more index subtypes
9191
from bigframes.core.indexes.multi import MultiIndex
9292

93-
klass = MultiIndex if len(block._index_columns) > 1 else cls
94-
# TODO(b/340893286): fix type error
95-
result = typing.cast(Index, object.__new__(klass)) # type: ignore
93+
if len(block._index_columns) <= 1:
94+
klass = cls
95+
else:
96+
klass = MultiIndex
97+
98+
result = typing.cast(Index, object.__new__(klass))
9699
result._query_job = None
97100
result._block = block
98101
block.session._register_object(result)
@@ -161,7 +164,8 @@ def dtype(self):
161164
@property
162165
def dtypes(self) -> pandas.Series:
163166
return pandas.Series(
164-
data=self._block.index.dtypes, index=self._block.index.names # type:ignore
167+
data=self._block.index.dtypes,
168+
index=typing.cast(typing.Tuple, self._block.index.names),
165169
)
166170

167171
@property
@@ -408,10 +412,10 @@ def drop(
408412
block = block.drop_columns([condition_id])
409413
return Index(block)
410414

411-
def dropna(self, how: str = "any") -> Index:
415+
def dropna(self, how: typing.Literal["all", "any"] = "any") -> Index:
412416
if how not in ("any", "all"):
413417
raise ValueError("'how' must be one of 'any', 'all'")
414-
result = block_ops.dropna(self._block, self._block.index_columns, how=how) # type: ignore
418+
result = block_ops.dropna(self._block, self._block.index_columns, how=how)
415419
return Index(result)
416420

417421
def drop_duplicates(self, *, keep: str = "first") -> Index:

third_party/bigframes_vendored/pandas/core/indexes/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Contains code from https://github.com/pandas-dev/pandas/blob/main/pandas/core/indexes/base.py
22
from __future__ import annotations
33

4+
import typing
5+
46
from bigframes import constants
57

68

@@ -320,7 +322,7 @@ def drop(self, labels) -> Index:
320322
"""
321323
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
322324

323-
def dropna(self, how: str = "any"):
325+
def dropna(self, how: typing.Literal["all", "any"] = "any"):
324326
"""Return Index without NA/NaN values.
325327
326328
Args:

0 commit comments

Comments
 (0)