code: def make_argument_subquery(arg):
          
          return Subquery.create(arg) if isinstance(arg, (GroupBy, Projection)) or arg.restriction else arg
docs: Decide when a Join argument needs to be wrapped in a subquery