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

Import ABC from collections.abc for Python 3.10 compatibility #746

Merged
merged 2 commits into from
Apr 14, 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
4 changes: 2 additions & 2 deletions petastorm/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Predicates for petastorm
"""
import abc
import collections
import collections.abc
import hashlib
import numpy as np
import six
Expand Down Expand Up @@ -66,7 +66,7 @@ def get_fields(self):
return {self._predicate_field}

def do_include(self, values):
if not isinstance(values[self._predicate_field], collections.Iterable):
if not isinstance(values[self._predicate_field], collections.abc.Iterable):
raise ValueError('Predicate field should have iterable type')
return any(np.in1d(values[self._predicate_field], self._inclusion_values))

Expand Down
6 changes: 3 additions & 3 deletions petastorm/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import collections
import collections.abc
import decimal
# Must import pyarrow before torch. See: https://github.com/uber/petastorm/blob/master/docs/troubleshoot.rst
import re
Expand Down Expand Up @@ -84,11 +84,11 @@ def decimal_friendly_collate(batch):

if isinstance(batch[0], decimal.Decimal):
return batch
elif isinstance(batch[0], collections.Mapping):
elif isinstance(batch[0], collections.abc.Mapping):
return {key: decimal_friendly_collate([d[key] for d in batch]) for key in batch[0]}
elif isinstance(batch[0], _string_classes):
return batch
elif isinstance(batch[0], collections.Sequence):
elif isinstance(batch[0], collections.abc.Sequence):
transposed = zip(*batch)
return [decimal_friendly_collate(samples) for samples in transposed]
else:
Expand Down
6 changes: 3 additions & 3 deletions petastorm/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import collections
import collections.abc
import logging
import warnings

Expand Down Expand Up @@ -395,7 +395,7 @@ def __init__(self, pyarrow_filesystem, dataset_path, schema_fields=None,
# c. partition: used to get a subset of data for distributed training
# 4. Create a rowgroup ventilator object
# 5. Start workers pool
if not (isinstance(schema_fields, collections.Iterable) or isinstance(schema_fields, NGram)
if not (isinstance(schema_fields, collections.abc.Iterable) or isinstance(schema_fields, NGram)
or schema_fields is None):
raise ValueError('Fields must be either None, an iterable collection of Unischema fields '
'or an NGram object.')
Expand Down Expand Up @@ -431,7 +431,7 @@ def __init__(self, pyarrow_filesystem, dataset_path, schema_fields=None,
if self.ngram:
fields = self.ngram.get_field_names_at_all_timesteps()
else:
fields = schema_fields if isinstance(schema_fields, collections.Iterable) else None
fields = schema_fields if isinstance(schema_fields, collections.abc.Iterable) else None

storage_schema = stored_schema.create_schema_view(fields) if fields else stored_schema
if len(storage_schema.fields) == 0:
Expand Down