You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/03/10 02:38:36 UTC

[GitHub] [beam] udim commented on a change in pull request #14156: [BEAM-11929] Rely on py3.6+ dictionary ordering in beam.Row

udim commented on a change in pull request #14156:
URL: https://github.com/apache/beam/pull/14156#discussion_r590946586



##########
File path: sdks/python/apache_beam/pvalue.py
##########
@@ -666,15 +666,14 @@ def as_dict(self):
     return dict(self.__dict__)
 
   def __iter__(self):
-    for _, value in sorted(self.__dict__.items()):
+    for _, value in self.__dict__.items():
       yield value
 
   def __repr__(self):
-    return 'Row(%s)' % ', '.join(
-        '%s=%r' % kv for kv in sorted(self.__dict__.items()))
+    return 'Row(%s)' % ', '.join('%s=%r' % kv for kv in self.__dict__.items())
 
   def __hash__(self):
-    return hash(type(sorted(self.__dict__.items())))
+    return hash(type(self.__dict__.items()))
 
   def __eq__(self, other):
     return type(self) == type(other) and self.__dict__ == other.__dict__

Review comment:
       Comparing dicts ignores order. Is that that's intentional?
   ```
   >>> {1:2, 3:4} == {1:2, 3:4}
   True
   >>> {1:2, 3:4} == {3:4, 1:2}
   True
   ```

##########
File path: sdks/python/apache_beam/pvalue.py
##########
@@ -666,15 +666,14 @@ def as_dict(self):
     return dict(self.__dict__)
 
   def __iter__(self):
-    for _, value in sorted(self.__dict__.items()):
+    for _, value in self.__dict__.items():
       yield value
 
   def __repr__(self):
-    return 'Row(%s)' % ', '.join(
-        '%s=%r' % kv for kv in sorted(self.__dict__.items()))
+    return 'Row(%s)' % ', '.join('%s=%r' % kv for kv in self.__dict__.items())
 
   def __hash__(self):
-    return hash(type(sorted(self.__dict__.items())))
+    return hash(type(self.__dict__.items()))

Review comment:
       I tried running this interactively but got the same hash:
   ```
   >>> hash(type({}.items()))
   5913863196444
   >>> hash(type({1:2}.items()))
   5913863196444
   ```
   
   Is it working as intended?
   
   I guess this is technically okay according to the docs, but probably not what you wanted: `The only required property is that objects which compare equal have the same hash value`.
   [ref](https://docs.python.org/3/reference/datamodel.html#object.__hash__)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org