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

Added static typing to data_readers/base_data.py and data_readers/json_data.py #666

Merged
merged 12 commits into from
Oct 7, 2022
12 changes: 9 additions & 3 deletions dataprofiler/data_readers/avro_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Contains class for saving and loading spreadsheet data."""
from io import BytesIO, StringIO
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Union, cast

import fastavro

Expand Down Expand Up @@ -91,13 +91,19 @@ def is_match(
options = dict()

# get current position of stream
if data_utils.is_stream_buffer(file_path) and not isinstance(file_path, str):
if data_utils.is_stream_buffer(file_path):
Sanketh7 marked this conversation as resolved.
Show resolved Hide resolved
file_path = cast(
Union[StringIO, BytesIO], file_path
) # guaranteed by is_stream_buffer
starting_location = file_path.tell()

is_valid_avro = fastavro.is_avro(file_path)

# return to original position in stream
if data_utils.is_stream_buffer(file_path) and not isinstance(file_path, str):
if data_utils.is_stream_buffer(file_path):
file_path = cast(
Union[StringIO, BytesIO], file_path
) # guaranteed by is_stream_buffer
file_path.seek(starting_location, 0)

return is_valid_avro
Expand Down