nebius/SWE-bench-extra huggingface dataset:
Repository: sosw/sosw

Issue:
DynamoDB - exception on wrong type in row_mapper
When row_mapper type is of one type (for example 'S'), and real type from DB is of another type (for example 'N')
This exception happens:

<img width="834" alt="Screen Shot 2020-07-08 at 13 59 53" src="https://user-images.githubusercontent.com/11838450/86911422-f7956280-c123-11ea-83cf-d9f207ed3c1c.png">

Options (choose one)
1. Raise informative exception
2. Convert to the expected type if possible

I prefer the 1st option.

Comments:

Patch:
diff --git a/sosw/components/dynamo_db.py b/sosw/components/dynamo_db.py
index ba52847..d7686c6 100644
--- a/sosw/components/dynamo_db.py
+++ b/sosw/components/dynamo_db.py
@@ -261,6 +261,11 @@ class DynamoDbClient:
                 if val_dict:
                     val = val_dict.get(key_type)  # Ex: 1234 or "myvalue"
 
+                    if val is None and key_type not in val_dict:
+                        real_type = list(val_dict.keys())[0]
+                        raise ValueError(f"'{key}' is expected to be of type '{key_type}' in row_mapper, "
+                                         f"but real value is of type '{real_type}'")
+
                     # type_deserializer.deserialize() parses 'N' to `Decimal` type but it cant be parsed to a datetime
                     # so we cast it to either an integer or a float.
                     if key_type == 'N':


Test patch:
diff --git a/sosw/components/test/unit/test_dynamo_db.py b/sosw/components/test/unit/test_dynamo_db.py
index 30dace2..e9022ee 100644
--- a/sosw/components/test/unit/test_dynamo_db.py
+++ b/sosw/components/test/unit/test_dynamo_db.py
@@ -201,6 +201,21 @@ class dynamodb_client_UnitTestCase(unittest.TestCase):
         self.assertDictEqual(res, expected)
 
 
+    def test_dynamo_to_dict__mapping_doesnt_match__raises(self):
+        # If the value type in the DB doesn't match the expected type in row_mapper - raise ValueError
+
+        dynamo_row = {
+            'hash_col':   {'S': 'aaa'}, 'range_col': {'N': '123'},
+            'other_col': {'N': '111'}  # In the row_mapper, other_col is of type 'S'
+        }
+
+        with self.assertRaises(ValueError) as e:
+            dict_row = self.dynamo_client.dynamo_to_dict(dynamo_row)
+
+        self.assertEqual("'other_col' is expected to be of type 'S' in row_mapper, but real value is of type 'N'",
+                         str(e.exception))
+
+
     def test_get_by_query__validates_comparison(self):
         self.assertRaises(AssertionError, self.dynamo_client.get_by_query, keys={'k': '1'},
                           comparisons={'k': 'unsupported'})
Repository: sotetsuk/memozo

Issue:
implement pickle
```py
@m.pickle()
```

Comments:

Patch:
diff --git a/memozo/memozo.py b/memozo/memozo.py
index a67bbe5..e4e3311 100644
--- a/memozo/memozo.py
+++ b/memozo/memozo.py
@@ -76,3 +76,32 @@ class Memozo(object):
             return _wrapper
 
         return wrapper
+
+    def pickle(self, name=None, ext='pickle', protocol=None):
+
+        def wrapper(func):
+            _name = func.__name__ if name is None else name
+
+            @functools.wraps(func)
+            def _wrapper(*args, **kwargs):
+                args = utils.get_bound_args(func, *args, **kwargs)
+                args_str = utils.get_args_str(args)
+                sha1 = utils.get_hash(_name, func.__name__, args_str)
+                file_path = os.path.join(self.base_path, "{}_{}.{}".format(_name, sha1, ext))
+
+                if utils.log_exisits(self.base_path, _name, func.__name__, args_str) and os.path.exists(file_path):
+                    with open(file_path, 'rb') as f:
+                        obj = pickle.load(f)
+                    return obj
+
+                obj = func(*args, **kwargs)
+
+                with open(file_path, 'wb') as f:
+                    pickle.dump(obj, f, protocol=protocol)
+                utils.write(self.base_path, _name, func.__name__, args_str)
+
+                return obj
+
+            return _wrapper
+
+        return wrapper


Test patch:
diff --git a/tests/test_memozo.py b/tests/test_memozo.py
index e224e0a..4c39e59 100644
--- a/tests/test_memozo.py
+++ b/tests/test_memozo.py
@@ -1,6 +1,7 @@
 import os
 import unittest
 import codecs
+import pickle
 
 from memozo import Memozo, utils
 
@@ -115,3 +116,30 @@ class TestMemozoGenerator(unittest.TestCase):
     def test_load_data_from_cache(self):
         # TODO(sotetsuk): WRITE THIS TEST
         pass
+
+
+class TestMemozoPickle(unittest.TestCase):
+
+    def test_no_cache_output(self):
+        base_path = './tests/resources'
+        m = Memozo(base_path)
+
+        @m.pickle('pickle_test', protocol=pickle.HIGHEST_PROTOCOL)
+        def pickle_test_func():
+            return {'a': 3, 'b': 5}
+
+        expected = {'a': 3, 'b': 5}
+        actual = pickle_test_func()
+        self.assertTrue(actual == expected)
+
+        sha1 = utils.get_hash('pickle_test', 'pickle_test_func', '')
+        file_path = os.path.join(base_path, "{}_{}.{}".format('pickle_test', sha1, 'pickle'))
+        os.remove(file_path)
+
+    def test_data_cached_collectly(self):
+        # TODO(sotetsuk): WRITE THIS TEST
+        pass
+
+    def test_load_data_from_cache(self):
+        # TODO(sotetsuk): WRITE THIS TEST
+        pass