Skip to content

Conversation

btat-qc
Copy link

@btat-qc btat-qc commented Oct 3, 2024

For example this enables support for NamedTuples, making return types more clear from pipedag tasks

Checklist

  • Added a docs/source/changelog.md entry
  • Added/updated documentation in docs/source/
  • Added/updated examples in docs/source/examples.md

For example this enables support for NamedTuples, making return types
more clear from pipedag tasks
@btat-qc btat-qc requested a review from a team as a code owner October 3, 2024 13:47
Copy link
Member

@windiana42 windiana42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure your goal is achieved by this change. The NamedTuple is converted to a tuple and loses its names.

We actually have deep_map as a pretty fundamental tool in both pipedag and transform which means it should work quite consistently over a very large code base according to general assumptions. I would expect deep_map(v, lambda x: x) to behave very close to deep_copy for collections (non-collection elements are not copied).

I suggest to explicitly handle NamedTuple and python data-classes to produce exactly the same type after the copy than it was before.

y = _deep_map_list(x, fn, memo)
elif cls == tuple:
elif isinstance(x, tuple):
Copy link
Member

@windiana42 windiana42 Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@btat-qc we talked about extensions like this in deep_map before. The question is what the expected behavior should be. deep_map(v, lambda x: x) should be very close to a deep copy without changing anything. With the change you proposed, the NamedTuple would be converted to a tuple if I am not mistaken.
I would suggest to explicitly handle NamedTuples and data classes here to guarantee that they are deep copied to the same type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - that makes sense! Thanks I'll think about how to solve this and add some tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants