Skip to content
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

Python: Add doctest to tox #4285

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion python/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ package_dir =
= src
packages = find:
python_requires = >=3.7

[options.extras_require]
arrow =
pyarrow
dev=
tox-travis==0.12
pytest
[options.packages.find]
where = src
29 changes: 0 additions & 29 deletions python/setup.py

This file was deleted.

11 changes: 5 additions & 6 deletions python/src/iceberg/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from enum import Enum, auto


class Operation(Enum):
"""Operations to be used as components in expressions

Operations can be negated by calling the negate method.
>>> print(Operation.TRUE.negate())
Operation.FALSE
>>> print(Operation.IS_NULL.negate())
Operation.NOT_NULL
>>> Operation.TRUE.negate()
<Operation.FALSE: 2>
>>> Operation.IS_NULL.negate()
<Operation.NOT_NULL: 4>

The above example uses the OPERATION_NEGATIONS map which maps each enum
to it's opposite enum.
Expand Down Expand Up @@ -53,7 +52,7 @@ class Operation(Enum):
AND = auto()
OR = auto()

def negate(self):
def negate(self) -> "Operation":
"""Returns the operation used when this is negated."""

try:
Expand Down
9 changes: 7 additions & 2 deletions python/src/iceberg/io/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ class PyArrowFile(InputFile, OutputFile):
Examples:
>>> from iceberg.io.pyarrow import PyArrowFile
>>> input_file = PyArrowFile("s3://foo/bar.txt")
>>> file_content = input_file.open().read() # Read the contents of the PyArrowFile instance
>>> # Read the contents of the PyArrowFile instance
>>> # Make sure that you have permissions to read/write
>>> # file_content = input_file.open().read()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense for now to get the checkdocs test passing but we talked about either mocking out S3 with some conftest monkeypatches or using a minio instance for more robustness. I'm not exactly sure if there's a way to inject mocks into checkdocs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me dive into this and see if I can get this working 👍🏻


>>> output_file = PyArrowFile("s3://baz/qux.txt")
>>> output_file.create().write(b'foobytes') # Write bytes to the PyArrowFile instance
>>> # Write bytes to a file
>>> # Make sure that you have permissions to read/write
>>> # output_file.create().write(b'foobytes')
"""

def __init__(self, location: str):
Expand Down
27 changes: 13 additions & 14 deletions python/src/iceberg/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
describe an Iceberg table schema, these classes can be used in the construction of a StructType instance.

Example:
>>> StructType(
NestedField(True, 1, "required_field", StringType()),
NestedField(False, 2, "optional_field", IntegerType())
)
>>> str(StructType(
... NestedField(1, "required_field", StringType(), True),
... NestedField(2, "optional_field", IntegerType())
... ))
'struct<1: required_field: optional string, 2: optional_field: optional int>'

Notes:
- https://iceberg.apache.org/#spec/#primitive-types
Expand Down Expand Up @@ -98,7 +99,7 @@ class DecimalType(PrimitiveType):
Example:
>>> DecimalType(32, 3)
DecimalType(precision=32, scale=3)
>>> DecimalType(8, 3)==DecimalType(8, 3)
>>> DecimalType(8, 3) == DecimalType(8, 3)
True
"""

Expand Down Expand Up @@ -201,10 +202,11 @@ class StructType(IcebergType):
"""A struct type in Iceberg

Example:
>>> StructType(
NestedField(True, 1, "required_field", StringType()),
NestedField(False, 2, "optional_field", IntegerType())
)
>>> str(StructType(
... NestedField(1, "required_field", StringType(), True),
... NestedField(2, "optional_field", IntegerType())
... ))
'struct<1: required_field: optional string, 2: optional_field: optional int>'
"""

_instances: Dict[Tuple[NestedField, ...], "StructType"] = {}
Expand All @@ -231,7 +233,7 @@ class ListType(IcebergType):

Example:
>>> ListType(element_id=3, element_type=StringType(), element_is_optional=True)
ListType(element=NestedField(is_optional=True, field_id=3, name='element', field_type=StringType(), doc=None))
ListType(element_id=3, element_type=StringType(), element_is_optional=True)
"""

_instances: Dict[Tuple[bool, int, IcebergType], "ListType"] = {}
Expand Down Expand Up @@ -275,10 +277,7 @@ class MapType(IcebergType):

Example:
>>> MapType(key_id=1, key_type=StringType(), value_id=2, value_type=IntegerType(), value_is_optional=True)
MapType(
key=NestedField(is_optional=False, field_id=1, name='key', field_type=StringType(), doc=None),
value=NestedField(is_optional=True, field_id=2, name='value', field_type=IntegerType(), doc=None)
)
MapType(key_id=1, key_type=StringType(), value_id=2, value_type=IntegerType(), value_is_optional=True)
"""

_instances: Dict[Tuple[int, IcebergType, int, IcebergType, bool], "MapType"] = {}
Expand Down
16 changes: 9 additions & 7 deletions python/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ envlist = py37,py38,py39,linters

[testenv]
usedevelop = true
extras = arrow
deps =
coverage
mock
pytest
pyarrow
pytest-checkdocs
setenv =
COVERAGE_FILE = test-reports/{envname}/.coverage
PYTEST_ADDOPTS = --junitxml=test-reports/{envname}/junit.xml -vv
Expand All @@ -50,17 +51,17 @@ deps =
isort
autoflake
commands =
autoflake -r --check --ignore-init-module-imports --remove-all-unused-imports setup.py src tests
isort --profile black --check-only setup.py src tests
black --line-length 130 --check --diff setup.py src tests
autoflake -r --check --ignore-init-module-imports --remove-all-unused-imports src tests
isort --profile black --check-only src tests
black --line-length 130 --check --diff src tests

[testenv:format]
deps =
{[testenv:format-check]deps}
commands =
autoflake -r --in-place --ignore-init-module-imports --remove-all-unused-imports setup.py src tests
isort --profile black setup.py src tests
black --line-length 130 setup.py src tests
autoflake -r --in-place --ignore-init-module-imports --remove-all-unused-imports src tests
isort --profile black src tests
black --line-length 130 src tests

[testenv:type-check]
deps =
Expand All @@ -86,6 +87,7 @@ commands =

[pytest]
norecursedirs=.*
addopts = --doctest-modules

[gh-actions]
python =
Expand Down