Skip to content

HDFStore.__iter__ #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
- flake8-pyi==23.1.2
types: [pyi]
args: [
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 W503 Y019 Y034 Y037 Y041 Y042,
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 W503 Y019 Y037 Y041 Y042,
# TypeVars in private files are already private
--per-file-ignores=_*.pyi:Y001
]
Expand Down
4 changes: 3 additions & 1 deletion pandas-stubs/_libs/missing.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing_extensions import Self

class NAType:
def __new__(cls, *args, **kwargs) -> NAType: ...
def __new__(cls, *args, **kwargs) -> Self: ...
def __format__(self, format_spec: str) -> str: ...
def __bool__(self) -> None: ...
def __hash__(self) -> int: ...
Expand Down
3 changes: 2 additions & 1 deletion pandas-stubs/core/indexes/category.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import numpy as np
from pandas.core import accessor
from pandas.core.indexes.base import Index # , maybe_extract_name
from pandas.core.indexes.extension import ExtensionIndex
from typing_extensions import Self

from pandas._typing import DtypeArg

Expand All @@ -18,7 +19,7 @@ class CategoricalIndex(ExtensionIndex, accessor.PandasDelegate):
dtype=...,
copy: bool = ...,
name=...,
) -> CategoricalIndex: ...
) -> Self: ...
def equals(self, other): ...
@property
def inferred_type(self) -> str: ...
Expand Down
3 changes: 2 additions & 1 deletion pandas-stubs/core/indexes/multi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from typing import (
import numpy as np
import pandas as pd
from pandas.core.indexes.base import Index
from typing_extensions import Self

from pandas._typing import (
T1,
Expand All @@ -32,7 +33,7 @@ class MultiIndex(Index):
name=...,
verify_integrity: bool = ...,
_set_identity: bool = ...,
) -> MultiIndex: ...
) -> Self: ...
def __init__(
self,
levels=...,
Expand Down
5 changes: 3 additions & 2 deletions pandas-stubs/io/excel/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ from odf.opendocument import OpenDocument
from openpyxl.workbook.workbook import Workbook
from pandas.core.frame import DataFrame
import pyxlsb.workbook
from typing_extensions import Self
from xlrd.book import Book

from pandas._typing import (
Expand Down Expand Up @@ -130,7 +131,7 @@ class ExcelWriter:
@property
def if_sheet_exists(self) -> Literal["error", "new", "replace", "overlay"]: ...
def __fspath__(self) -> str: ...
def __enter__(self) -> ExcelWriter: ...
def __enter__(self) -> Self: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
Expand Down Expand Up @@ -214,7 +215,7 @@ class ExcelFile:
@property
def sheet_names(self) -> list[int | str]: ...
def close(self) -> None: ...
def __enter__(self) -> ExcelFile: ...
def __enter__(self) -> Self: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
Expand Down
3 changes: 2 additions & 1 deletion pandas-stubs/io/parsers/readers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ from typing import (
from pandas.core.frame import DataFrame
from pandas.core.indexes.base import Index
from pandas.core.series import Series
from typing_extensions import Self

from pandas._typing import (
CompressionOptions,
Expand Down Expand Up @@ -479,7 +480,7 @@ class TextFileReader(abc.Iterator):
def read(self, nrows: int | None = ...) -> DataFrame: ...
def get_chunk(self, size: int | None = ...) -> DataFrame: ...
def __next__(self) -> DataFrame: ...
def __enter__(self) -> TextFileReader: ...
def __enter__(self) -> Self: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
Expand Down
6 changes: 4 additions & 2 deletions pandas-stubs/io/pytables.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import (
Generator,
Iterator,
Sequence,
)
from types import TracebackType
Expand All @@ -15,6 +16,7 @@ from pandas import (
)
from pandas.core.computation.pytables import PyTablesExpr
from pandas.core.generic import NDFrame
from typing_extensions import Self

from pandas._typing import (
FilePath,
Expand Down Expand Up @@ -113,15 +115,15 @@ class HDFStore:
def __getattr__(self, name: str) -> DataFrame | Series: ...
def __contains__(self, key: str) -> bool: ...
def __len__(self) -> int: ...
def __enter__(self) -> HDFStore: ...
def __enter__(self) -> Self: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None: ...
def keys(self) -> list[str]: ...
def __iter__(self) -> list[str]: ...
def __iter__(self) -> Iterator[str]: ...
def open(self, mode: Literal["a", "w", "r", "r+"] = ..., **kwargs) -> None: ...
def close(self) -> None: ...
@property
Expand Down
3 changes: 2 additions & 1 deletion pandas-stubs/io/sas/sasreader.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from typing import (
)

from pandas import DataFrame
from typing_extensions import Self

from pandas._typing import (
CompressionOptions as CompressionOptions,
Expand All @@ -24,7 +25,7 @@ class ReaderBase(metaclass=ABCMeta):
def read(self, nrows: int | None = ...) -> DataFrame: ...
@abstractmethod
def close(self) -> None: ...
def __enter__(self) -> ReaderBase: ...
def __enter__(self) -> Self: ...
def __exit__(self, exc_type, exc_value, traceback) -> None: ...

@overload
Expand Down
3 changes: 2 additions & 1 deletion pandas-stubs/io/stata.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from typing import (
)

from pandas.core.frame import DataFrame
from typing_extensions import Self

from pandas._typing import (
CompressionOptions,
Expand Down Expand Up @@ -92,7 +93,7 @@ class StataReader(StataParser, abc.Iterator):
compression: CompressionOptions = ...,
storage_options: StorageOptions = ...,
) -> None: ...
def __enter__(self) -> StataReader: ...
def __enter__(self) -> Self: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ def test_hdfstore():
DataFrame,
)
check(assert_type(store.get("df"), Union[DataFrame, Series]), DataFrame)
for key in store:
check(assert_type(key, str), str)
check(assert_type(store.close(), None), type(None))

store = HDFStore(path, model="r")
Expand Down