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

Non roundtrippable sequence subclasses raise error in apply_to_collection #249

Open
ap-- opened this issue Mar 29, 2024 · 0 comments
Open
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ap--
Copy link

ap-- commented Mar 29, 2024

🐛 Bug

Some of our dataloaders use custom Sequence subclasses, that cause errors in apply_to_collection.

The reason for this is, that these classes won't roundtrip, which is assumed by the implementation of apply_to_collection.

# minimal example
class X(list):
    def __init__(self, x):
        super().__init__(range(x))

data = X(4)

assert data == type(data)(list(data))  # is False, because of how class X's constructor is implemented
                                       # but this is how apply_to_collection handles Sequences

The above is assumed implicitly here:

out = []
for d in data:
v = _apply_to_collection_slow(
d,
dtype,
function,
*args,
wrong_dtype=wrong_dtype,
include_none=include_none,
allow_frozen=allow_frozen,
**kwargs,
)
if include_none or v is not None:
out.append(v)
return elem_type(*out) if is_namedtuple_ else elem_type(out)

To Reproduce

See example above.

Expected behavior

If an instance of a sequence subclass can't roundtrip it should just be passed through.

Additional context

N/A

Cheers,
Andreas

@ap-- ap-- added bug Something isn't working help wanted Extra attention is needed labels Mar 29, 2024
@Borda Borda changed the title Non roundtrippable sequence subclasses raise error in apply_to_collection Non roundtrippable sequence subclasses raise error in apply_to_collection Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant