Github user zasdfgbnm commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18444#discussion_r127814477
  
    --- Diff: python/pyspark/sql/types.py ---
    @@ -938,12 +1023,17 @@ def _infer_type(obj):
                     return MapType(_infer_type(key), _infer_type(value), True)
             else:
                 return MapType(NullType(), NullType(), True)
    -    elif isinstance(obj, (list, array)):
    +    elif isinstance(obj, list):
             for v in obj:
                 if v is not None:
                     return ArrayType(_infer_type(obj[0]), True)
             else:
                 return ArrayType(NullType(), True)
    +    elif isinstance(obj, array):
    +        if obj.typecode in _array_type_mappings:
    --- End diff --
    
    I don't think `i in my_dict` and `i in my_dict.keys()` has much difference 
in performance. A simple test
    ```python
    from random import random,shuffle
    from time import time
    
    N = 10000000
    d = {}
    for i in range(N):
        d[i] = random()
        
    tests = list(range(2*N))
    shuffle(tests)
    
    time1 = time()
    
    dummy = 0
    for i in tests:
        if i in d:
            dummy += 1
            
    time2 = time()
    
    dummy = 0
    for i in tests:
        if i in d.keys():
            dummy += 1
            
    time3 = time()
    
    print(time2-time1)
    print(time3-time2)
    ```
    gives
    ```
    11.389298915863037
    12.333340167999268
    ```
    on my MacBook Pro


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to