tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.26k stars 1.1k forks source link

Importing ABC directly from collections was deprecated from Python 3.4 and will be removed in 3.10 #810

Open tirkarthi opened 4 years ago

tirkarthi commented 4 years ago

Importing ABC directly from collections was deprecated from 3.4 and will be removed in 3.10. Using collections.abc is recommended. Since the project is Python 3 only it doesn't require Python 2/3 shims for the fix.

rg "collections\.(Awaitable|Coroutine|AsyncIterable|AsyncIterator|AsyncGenerator|Hashable|Iterable|Iterator|Generator|Reversible|Sized|Container|Callable|Collection|MutableSet|Mapping|MutableMapping|MappingView|KeysView|ItemsView|ValuesView|Sequence|MutableSequence|ByteString)\b"

discussion/fun_mcmc/fun_mcmc_lib.py
291:      args, collections.Sequence) and not mcmc_util.is_namedtuple_like(args):
294:  elif isinstance(args, collections.Mapping):
332:  if not isinstance(ret, collections.Sequence) or len(ret) != 2:
373:  if not isinstance(ret, collections.Sequence) or len(ret) != 2:
434:  if not isinstance(ret, collections.Sequence) or len(ret) != 2:

discussion/nn/variational_base.py
65:  if isinstance(weights, collections.Mapping):

tensorflow_probability/python/distributions/mixture_same_family.py
206:        list(slices) if isinstance(slices, collections.Sequence) else [slices])

tensorflow_probability/python/distributions/distribution_properties_test.py
500:        tuple(slices) if isinstance(slices, collections.Sequence) else

tensorflow_probability/python/distributions/distribution.py
1503:  if (isinstance(x, collections.Sequence) and
1510:  if isinstance(x, collections.Mapping):

tensorflow_probability/python/distributions/joint_distribution_named.py
282:  return hasattr(x, '_asdict') or isinstance(x, collections.Mapping)

tensorflow_probability/python/distributions/independent.py
181:    slices = (tuple(slices) if isinstance(slices, collections.Sequence)

tensorflow_probability/python/internal/nest_util.py
78:  return (isinstance(args, collections.Sequence) and
84:  return isinstance(args, collections.Mapping) and not _force_leaf(args)

tensorflow_probability/python/distributions/joint_distribution_sequential.py
232:    if not isinstance(model, collections.Sequence):

tensorflow_probability/python/layers/distribution_layer.py
172:      value_is_seq = isinstance(d.dtype, collections.Sequence)

tensorflow_probability/python/distributions/internal/slicing.py
180:  if not isinstance(slices, collections.Sequence):
csuter commented 4 years ago

Thanks @tirkarthi. For the time being, despite not supporting py2 externally, we still need to maintain compatibility for some internal users inside Google. I agree we should eventually take care of this though, once internal py2 users have migrated completely.

ricopicone commented 1 year ago

I'm now getting an error with v 0.14.0 and Python 3.10.

As OP says, it should be updated to collections.abc.Sequence

See also #1656

ricopicone commented 1 year ago

This appears to be fixed in the latest: https://github.com/tensorflow/probability/blob/c9d9dd4e6e5520a75ca8f299420589e9a22485a2/tensorflow_probability/python/layers/distribution_layer.py#L167