Skip to content

Commit

Permalink
Merge pull request #929 from static-frame/928/mypy-110
Browse files Browse the repository at this point in the history
Update `mypy==1.10`, `pyright==1.1.361`
  • Loading branch information
flexatone committed May 6, 2024
2 parents bea1f0e + 8767fef commit 76b2e19
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 55 deletions.
4 changes: 2 additions & 2 deletions requirements-dev-3_11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ msgpack-numpy==0.4.8
visidata==2.11
frame-fixtures==0.2.1

mypy==1.9.0
pyright==1.1.331
mypy==1.10.0
pyright==1.1.361
pylint==2.17.5
isort==5.12.0
memray==1.3.1 # only linux
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev-3_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ msgpack-numpy==0.4.8
visidata==2.11
frame-fixtures==0.2.1

mypy==1.9.0
pyright==1.1.331
mypy==1.10.0
pyright==1.1.361
pylint==2.17.5
isort==5.12.0
memray==1.11.0 # only linux
Expand Down
2 changes: 1 addition & 1 deletion static_frame/core/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def type_attributes(
'''
Return the `type_input` as a string, applying delimters to either numpy dtypes or Python classes.
'''
type_ref: THeaderSpecifier
type_ref: tp.Union[type, TDtypeAny]
if isinstance(type_input, np.dtype):
type_str = str(type_input)
type_ref = type_input
Expand Down
7 changes: 5 additions & 2 deletions static_frame/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5204,7 +5204,9 @@ def _extract_iloc(self, key: TILocSelectorCompound) -> tp.Any: # pyright: ignore
return self._extract(key)

def _compound_loc_to_iloc(self,
key: TLocSelectorCompound) -> TILocSelectorCompound:
key: TLocSelectorCompound,
# ) -> TILocSelectorCompound:
) -> tp.Tuple[TILocSelector, TILocSelector]:
'''
Given a compound iloc key, return a tuple of row, column keys. Assumes the first argument is always a row extractor.
'''
Expand All @@ -5219,7 +5221,8 @@ def _compound_loc_to_iloc(self,
return iloc_row_key, iloc_column_key

def _extract_loc(self, key: TLocSelectorCompound) -> tp.Any:
return self._extract(*self._compound_loc_to_iloc(key))
r, c = self._compound_loc_to_iloc(key)
return self._extract(r, c)

def _extract_loc_columns(self, key: TLocSelector) -> TFrameOrSeries:
'''Alternate extract of a columns only selection.
Expand Down
3 changes: 2 additions & 1 deletion static_frame/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def __init__(self,

self._name = None if name is NAME_DEFAULT else name_filter(name) # pyright: ignore

size: int
if self._map is None: # if _map not shared from another Index
if not loc_is_iloc:
if isinstance(labels, str):
Expand All @@ -355,7 +356,7 @@ def __init__(self,
except NonUniqueError: # Automap will raise ValueError of non-unique values are encountered
raise self._error_init_index_non_unique(labels) from None
# must take length after map as might be iterator
size = len(self._map)
size = len(self._map) # pyright: ignore
else:
# if loc_is_iloc, labels must be positions and we assume that internal clients that provided loc_is_iloc will not give a generator
size = len(labels) #type: ignore
Expand Down
12 changes: 6 additions & 6 deletions static_frame/core/store_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,16 @@ def read_many(self,
ws = wb[label_encoded] # pyright: ignore
name = label # set name to the un-encoded hashable

if ws.max_column <= 1 or ws.max_row <= 1:
if ws.max_column <= 1 or ws.max_row <= 1: # pyright: ignore
# https://openpyxl.readthedocs.io/en/stable/optimized.html
# says that some clients might not report correct dimensions
ws.calculate_dimension()
ws.calculate_dimension() # pyright: ignore

max_column = ws.max_column
max_row = ws.max_row
max_column: int = ws.max_column # pyright: ignore
max_row: int = ws.max_row # pyright: ignore

# adjust for downward shift for skipping header, then reduce for footer; at this value and beyond we stop
last_row_count = max_row - skip_header - skip_footer
last_row_count: int = max_row - skip_header - skip_footer

index_values: tp.List[tp.Any] = []
columns_values: tp.List[tp.Any] = []
Expand All @@ -433,7 +433,7 @@ def read_many(self,
mask = np.full((last_row_count, max_column), False)

for row_count, row in enumerate(
ws.iter_rows(max_row=max_row), start=-skip_header):
ws.iter_rows(max_row=max_row), start=-skip_header): # pyright: ignore
if row_count < 0:
continue # due to skip header; preserves comparison to columns_depth
if row_count >= last_row_count:
Expand Down
4 changes: 2 additions & 2 deletions static_frame/core/type_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ class CallGuard:

@tp.overload
@staticmethod
def check(func: TVFunc) -> TVFunc: ...
def check(func: TVFunc, /) -> TVFunc: ...

@tp.overload
@staticmethod
Expand Down Expand Up @@ -1512,7 +1512,7 @@ def wrapper(*args: tp.Any, **kwargs: tp.Any) -> tp.Any:

@tp.overload
@staticmethod
def warn(func: TVFunc) -> TVFunc: ...
def warn(func: TVFunc, /) -> TVFunc: ...

@tp.overload
@staticmethod
Expand Down
66 changes: 33 additions & 33 deletions static_frame/test/typing/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,14 @@ def test_frame_astype_a() -> None:


#-------------------------------------------------------------------------------
h1: tp.TypeAlias = sf.Frame[sf.Index[np.int64], sf.Index[np.str_], np.int64, np.int64, np.bool_]

def test_frame_interface_a() -> None:
records = (
(1, 2, False),
(30, 34,True),
(54, 95, False),
)
h1 = sf.Frame[sf.Index[np.int64], sf.Index[np.str_], np.int64, np.int64, np.bool_]
f: h1 = sf.Frame.from_records(records,
columns=('a', 'b', 'c'),
index=sf.Index((10, 20, 30), dtype=np.int64),
Expand All @@ -190,6 +191,10 @@ def proc1(f: h1) -> sf.Series[sf.Index[np.int64], np.int64]:

# s2 = proc2(f) # pyright: Type parameter "TVDtypes@Frame" is invariant, but "*tuple[int_, int_, bool_]" is not the same as "*tuple[int_, bool_]" (reportGeneralTypeIssues)

hf1: tp.TypeAlias = sf.Frame[sf.IndexDate, sf.Index[np.str_], np.int_, np.int_, np.bool_]
hs: tp.TypeAlias = sf.Series[sf.IndexDate, np.int_]
hf2: tp.TypeAlias = sf.Frame[sf.Index[np.int_], sf.Index[np.str_], np.int_, np.int_, np.bool_]
hf3: tp.TypeAlias = sf.Frame[sf.IndexDate, sf.Index[np.str_], np.int_, np.bool_]

def test_frame_interface_b() -> None:

Expand All @@ -198,8 +203,6 @@ def test_frame_interface_b() -> None:
(30, 34, False),
(54, 95, True),
)
hf1 = sf.Frame[sf.IndexDate, sf.Index[np.str_], np.int_, np.int_, np.bool_]
hs = sf.Series[sf.IndexDate, np.int_]

f1: hf1 = sf.Frame.from_records(records, columns=('a', 'b', 'c'), index=sf.IndexDate(('2022-01-03', '2022-02-05', '2018-04-02')))

Expand All @@ -211,7 +214,6 @@ def proc(f: hf1) -> hs:

# if we define a Frame with a different index type, we can statically check it

hf2 = sf.Frame[sf.Index[np.int_], sf.Index[np.str_], np.int_, np.int_, np.bool_]
f2: hf2 = sf.Frame.from_records(records, columns=('a', 'b', 'c'))

# s = proc(f2) # pyright: error: Argument of type "Frame[Index[int_], Index[str_], int_, int_, bool_]" cannot be assigned to parameter "f" of type "Frame[IndexDate, Index[str_], int_, int_, bool_]" in function "proc"
Expand All @@ -220,14 +222,36 @@ def proc(f: hf1) -> hs:

# if we define a Frame with different column typing, we can statically check it

hf3 = sf.Frame[sf.IndexDate, sf.Index[np.str_], np.int_, np.bool_]
f3: hf3 = sf.Frame.from_records((r[1:] for r in records), columns=('b', 'c'), index=sf.IndexDate(('2022-01-03', '2022-02-05', '2018-04-02')))

# s = proc(f3) #pyright: error: Argument of type "Frame[IndexDate, Index[str_], int_, bool_]" cannot be assigned to parameter "f" of type "Frame[IndexDate, Index[str_], int_, int_, bool_]" in function "proc"
# "Frame[IndexDate, Index[str_], int_, bool_]" is incompatible with "Frame[IndexDate, Index[str_], int_, int_, bool_]"
# Type parameter "TVDtypes@Frame" is invariant, but "*tuple[int_, bool_]" is not the same as "*tuple[int_, int_, bool_]" (reportGeneralTypeIssues)


h10: tp.TypeAlias = sf.Frame[sf.IndexDate,
sf.Index[np.str_],
np.int_,
np.bool_]

h20: tp.TypeAlias = sf.Frame[sf.IndexDate,
sf.Index[np.str_],
np.int_,
np.int_,
np.int_,
np.bool_]
h30: tp.TypeAlias = sf.Frame[sf.IndexDate,
sf.Index[np.str_],
np.bool_,
np.int_,
]

hflex: tp.TypeAlias = sf.Frame[sf.IndexDate,
sf.Index[np.str_],
tp.Unpack[tp.Tuple[np.int_, ...]],
np.bool_]


def test_frame_interface_c() -> None:


Expand All @@ -247,32 +271,10 @@ def test_frame_interface_c() -> None:
(True, 3),
)

h1 = sf.Frame[sf.IndexDate,
sf.Index[np.str_],
np.int_,
np.bool_]

h2 = sf.Frame[sf.IndexDate,
sf.Index[np.str_],
np.int_,
np.int_,
np.int_,
np.bool_]
h3 = sf.Frame[sf.IndexDate,
sf.Index[np.str_],
np.bool_,
np.int_,
]

index = sf.IndexDate(('2022-01-03', '2022-02-05', '2018-04-02'))
f1: h1 = sf.Frame.from_records(records1, columns=('a', 'b'), index=index)
f2: h2 = sf.Frame.from_records(records2, columns=('a', 'b', 'c', 'd'), index=index)
f3: h3 = sf.Frame.from_records(records3, columns=('a', 'd'), index=index)

hflex = sf.Frame[sf.IndexDate,
sf.Index[np.str_],
tp.Unpack[tp.Tuple[np.int_, ...]],
np.bool_]
f1: h10 = sf.Frame.from_records(records1, columns=('a', 'b'), index=index)
f2: h20 = sf.Frame.from_records(records2, columns=('a', 'b', 'c', 'd'), index=index)
f3: h30 = sf.Frame.from_records(records3, columns=('a', 'd'), index=index)

fflex1: hflex = f1
fflex2: hflex = f2
Expand All @@ -284,11 +286,9 @@ def test_frame_interface_c() -> None:

def test_frame_type_var_tuple_a() -> None:
records = ((1, 3, True), (3, 8, True),)
h1 = sf.Frame[sf.IndexDate,
sf.Index[np.str_],]
index = sf.IndexDate(('2022-01-03', '2018-04-02'))
# NOTE: this works because of default of TypeVarTuple
f: h1 = sf.Frame.from_records(records,
f:sf.Frame[sf.IndexDate, sf.Index[np.str_],] = sf.Frame.from_records(records,
columns=('a', 'b', 'c'),
index=index,
)
Expand Down
13 changes: 7 additions & 6 deletions static_frame/test/typing/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def test_series_he_iloc_a() -> None:
v3: sf.SeriesHE[sf.Index[np.str_], np.int64] = s.iloc[1:]
assert len(v3) == 2

TSeries0: tp.TypeAlias = sf.Series[sf.Index[np.str_], np.int64]

def test_series_drop() -> None:
TSeries = sf.Series[sf.Index[np.str_], np.int64]
s1: TSeries = sf.Series((10, 20, 30), index=('a', 'b', 'c'))
s2: TSeries = s1.drop['b'] # dropping always returns a series
s1: TSeries0 = sf.Series((10, 20, 30), index=('a', 'b', 'c'))
s2: TSeries0 = s1.drop['b'] # dropping always returns a series

def proc1(x: TSeries) -> TSeries:
def proc1(x: TSeries0) -> TSeries0:
return x.dropna()

y1 = proc1(s1.drop['b'])
Expand All @@ -73,9 +73,10 @@ def proc2(x: sf.Series[sf.Index[np.str_], np.str_]) -> sf.Series[sf.Index[np.str



TSeries1: tp.TypeAlias = sf.Series[sf.IndexDate, np.float64]
TSeries2: tp.TypeAlias = sf.Series[sf.Index[np.int64], np.float64]

def test_series_ih1() -> None:
TSeries1 = sf.Series[sf.IndexDate, np.float64]
TSeries2 = sf.Series[sf.Index[np.int64], np.float64]

s1: TSeries1 = sf.Series((10, 20, np.nan), index=sf.IndexDate(('2022-01-01', '2022-01-02', '2022-01-03')))

Expand Down

0 comments on commit 76b2e19

Please sign in to comment.