Skip to content

Commit 00a6c1c

Browse files
Fix lsun tests on GitHub by importing lmdb directly. (#11232)
PiperOrigin-RevId: 968380231 Co-authored-by: Pierre Marcenac <pierremarcenac@google.com>
1 parent 470d259 commit 00a6c1c

99 files changed

Lines changed: 344 additions & 333 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎setup.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
# tensorflow==2.20.0 is not compatible with gcld3 because of protobuf
154154
# version conflict.
155155
'tensorflow<2.20.0',
156+
'tensorflow-metadata<1.18.0',
156157
],
157158
'c4_wsrs': ['apache-beam<2.65.0'],
158159
'cats_vs_dogs': ['matplotlib'],
@@ -170,16 +171,10 @@
170171
'scipy',
171172
],
172173
'librispeech': ['pydub'], # and ffmpeg installed
173-
'lsun': [
174-
# tensorflow-io is compiled against specific versions of TF.
175-
'tensorflow-io[tensorflow]',
176-
],
174+
'lsun': ['lmdb'],
177175
'nsynth': [
178176
'crepe',
179177
'librosa',
180-
# tensorflow==2.20.0 is not compatible with librosa because of protobuf
181-
# version conflict.
182-
'tensorflow<2.20.0',
183178
],
184179
'ogbg_molpcba': ['pandas', 'networkx'],
185180
'pet_finder': ['pandas'],

‎tensorflow_datasets/core/community/register_package_test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_builder_cls(dummy_register: register_package.PackageRegister): # pylin
105105
builder_cls = dummy_register.builder_cls(ds_name)
106106
assert builder_cls.name == 'dummy_dataset'
107107

108-
clshash = '89a6603e427554b46d2b4895b24ce8d4c2d703d453deaff3946c941fefaf1412'
108+
clshash = '925292f8861ff81947528d2ed011760c47e7a09a9b29062148e81d7507fc4e60'
109109
assert installed_path / f'{clshash}/dummy_dataset.py' == builder_cls.code_path
110110
assert 'kaggle' in builder_cls.code_path.parts
111111
assert issubclass(builder_cls, dataset_builder.DatasetBuilder)

‎tensorflow_datasets/core/dataset_builders/croissant_builder.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from collections.abc import Mapping, Sequence
4040
import datetime
4141
import json
42-
from typing import Any
42+
from typing import Any, cast
4343

4444
from etils import enp
4545
from etils import epath
@@ -110,7 +110,7 @@ def array_datatype_converter(
110110
if field.data_type in dtype_mapping:
111111
field_dtype = dtype_mapping[field.data_type]
112112
elif enp.lazy.is_np_dtype(field.data_type):
113-
field_dtype = field.data_type
113+
field_dtype = cast(type_utils.TfdsDType, field.data_type)
114114

115115
description = croissant_utils.extract_localized_string(
116116
field.description, language=language, field_name='description'
@@ -191,7 +191,7 @@ def datatype_converter(
191191
elif field_data_type in dtype_mapping:
192192
feature = dtype_mapping[field_data_type]
193193
elif enp.lazy.is_np_dtype(field_data_type):
194-
feature = field_data_type
194+
feature = cast(type_utils.TfdsDType, field_data_type)
195195
# We return a text feature for date-time features (mlc.DataType.DATE,
196196
# mlc.DataType.DATETIME, and mlc.DataType.TIME).
197197
elif field_data_type == pd.Timestamp or field_data_type == datetime.time:

‎tensorflow_datasets/core/dataset_info.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ def _nest_to_proto(nest: Nest) -> dataset_info_pb2.SupervisedKeys.Nest:
10071007
for item in nest:
10081008
proto.tuple.items.append(_nest_to_proto(item))
10091009
elif nest_type is dict:
1010-
nest = {key: _nest_to_proto(value) for key, value in nest.items()} # pyrefly: ignore[bad-assignment]
1010+
nest = {key: _nest_to_proto(value) for key, value in nest.items()} # pyrefly: ignore[bad-assignment, missing-attribute]
10111011
proto.dict.CopyFrom(dataset_info_pb2.SupervisedKeys.Dict(dict=nest)) # pyrefly: ignore[bad-argument-type]
10121012
elif nest_type is str:
10131013
proto.feature_key = nest # pyrefly: ignore[bad-assignment]

‎tensorflow_datasets/core/download/download_manager.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def register_checksums(self):
348348
def _record_url_infos(self):
349349
"""Store in file when recorded size/checksum of downloaded files."""
350350
checksums.save_url_infos(
351-
self._register_checksums_path,
351+
self._register_checksums_path, # pyrefly: ignore[bad-argument-type]
352352
self._recorded_url_infos,
353353
)
354354

@@ -575,7 +575,7 @@ def callback(dl_result: downloader.DownloadResult) -> epath.Path:
575575
resource_lib.write_info_file(
576576
url=url,
577577
path=dst_path,
578-
dataset_name=self._dataset_name,
578+
dataset_name=self._dataset_name, # pyrefly: ignore[bad-argument-type]
579579
original_fname=dl_path.name,
580580
url_info=dl_url_info,
581581
)

‎tensorflow_datasets/core/download/downloader.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _get_filename(response: Response) -> str:
128128
if filename:
129129
return filename
130130
# Otherwise, fallback on extracting the name from the url.
131-
return _basename_from_url(response.url)
131+
return _basename_from_url(response.url) # pyrefly: ignore[bad-argument-type]
132132

133133

134134
def _process_gdrive_confirmation(original_url: str, contents: str) -> str:
@@ -345,7 +345,7 @@ def _open_with_requests(
345345
) -> Iterator[tuple[Response, Iterable[bytes]]]:
346346
"""Open url with request."""
347347
with requests.Session() as session:
348-
retries = requests.packages.urllib3.util.retry.Retry(
348+
retries = requests.packages.urllib3.util.retry.Retry( # pyrefly: ignore[missing-attribute]
349349
total=MAX_RETRIES,
350350
backoff_factor=0.2,
351351
status_forcelist=[500, 502, 503, 504],

‎tensorflow_datasets/core/download/extractor.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def iter_tar(arch_f, stream=False):
184184
read_type = 'r' + ('|' if stream else ':') + '*'
185185

186186
with _open_or_pass(arch_f) as fobj:
187-
tar = tarfile.open(mode=read_type, fileobj=fobj)
187+
tar = tarfile.open(mode=read_type, fileobj=fobj) # pyrefly: ignore[no-matching-overload]
188188
for member in tar:
189189
if stream and (member.islnk() or member.issym()):
190190
# Links cannot be dereferenced in stream mode.

‎tensorflow_datasets/core/download/resource.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ def _sanitize_url(url: str, max_length: int) -> tuple[str, str]:
130130
Returns:
131131
Sanitized and shorted url, file extension.
132132
"""
133-
url = urllib.parse.urlparse(url)
134-
netloc = url.netloc
133+
url = urllib.parse.urlparse(url) # pyrefly: ignore[bad-assignment]
134+
netloc = url.netloc # pyrefly: ignore[missing-attribute]
135135
for prefix in _NETLOC_COMMON_PREFIXES:
136136
if netloc.startswith(prefix):
137137
netloc = netloc[len(prefix) :]
138138
for suffix in _NETLOC_COMMON_SUFFIXES:
139139
if netloc.endswith(suffix):
140140
netloc = netloc[: -len(suffix)]
141-
url = f'{netloc}{url.path}{url.params}{url.query}'
141+
url = f'{netloc}{url.path}{url.params}{url.query}' # pyrefly: ignore[missing-attribute]
142142
# Get the extension:
143143
for ext in _KNOWN_EXTENSIONS:
144144
if url.endswith(ext):
@@ -184,8 +184,8 @@ def get_dl_fname(url: str, checksum: str | None = None) -> str:
184184
"""
185185
if not checksum:
186186
checksum = checksums_lib.sha256(url)
187-
checksum = base64.urlsafe_b64encode(_decode_hex(checksum))
188-
checksum = checksum.decode()[:-1]
187+
checksum = base64.urlsafe_b64encode(_decode_hex(checksum)) # pyrefly: ignore[bad-assignment]
188+
checksum = checksum.decode()[:-1] # pyrefly: ignore[missing-attribute]
189189
name, extension = _sanitize_url(url, max_length=46)
190190
return f'{name}{checksum}{extension}'
191191

‎tensorflow_datasets/core/lazy_imports_lib.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def langdetect(cls):
103103
def librosa(cls):
104104
return _try_import("librosa")
105105

106+
@utils.classproperty
107+
@classmethod
108+
def lmdb(cls):
109+
return _try_import("lmdb")
110+
106111
@utils.classproperty
107112
@classmethod
108113
def lxml(cls):

‎tensorflow_datasets/core/read_only_builder.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def get_split_dict(builder_dir, dataset_info_proto) -> splits_lib.SplitDict:
245245

246246
merged_split_dict = splits_lib.SplitDict.merge_multiple([
247247
get_split_dict(builder_dir, dataset_info_proto)
248-
for builder_dir, dataset_info_proto in dataset_infos.items()
248+
for builder_dir, dataset_info_proto in dataset_infos.items() # pyrefly: ignore[missing-attribute]
249249
])
250250

251251
# We create the ReadOnlyBuilder for a random builder_dir and then update the

0 commit comments

Comments
 (0)