nebius/SWE-bench-extra huggingface dataset:
Repository: wearewhys/magnivore

Issue:
Lexicon.factor should check the type of the values
Lexicon.factor should check the values types or errors will happen

Comments:

Patch:
diff --git a/magnivore/Lexicon.py b/magnivore/Lexicon.py
index f9fa08d..84ae7a2 100644
--- a/magnivore/Lexicon.py
+++ b/magnivore/Lexicon.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 import re
+from decimal import Decimal
 from functools import reduce
 
 from .Tracker import Tracker
@@ -38,7 +39,8 @@ class Lexicon:
         The factor rule multiplies the value by a factor.
         """
         value = cls._dot_reduce(rule['from'], target)
-        return value * rule['factor']
+        original_type = type(value)
+        return original_type(Decimal(value) * Decimal(rule['factor']))
 
     @classmethod
     def format(cls, rule, target):


Test patch:
diff --git a/tests/unit/Lexicon.py b/tests/unit/Lexicon.py
index 4f8e888..f1c85d6 100644
--- a/tests/unit/Lexicon.py
+++ b/tests/unit/Lexicon.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 import re
+from decimal import Decimal
 from unittest.mock import MagicMock
 
 from magnivore.Lexicon import Lexicon
@@ -48,17 +49,20 @@ def test_lexicon_transform(target):
     assert result == rule['transform'][target.temperature]
 
 
-@mark.parametrize('from_data, target', [
-    ('value', MagicMock(value=100)),
-    ('related.value', MagicMock(related=MagicMock(value=100)))
+@mark.parametrize('from_data, target, expected', [
+    ('value', MagicMock(value=100), 50),
+    ('value', MagicMock(value=Decimal(100)), Decimal(50)),
+    ('value', MagicMock(value=100.0), 50.0),
+    ('related.value', MagicMock(related=MagicMock(value=100)), 50)
 ])
-def test_lexicon_factor(from_data, target):
+def test_lexicon_factor(from_data, target, expected):
     rule = {
         'from': from_data,
         'factor': 0.5
     }
     result = Lexicon.factor(rule, target)
-    assert result == 50
+    assert result == expected
+    assert type(result) == type(expected)
 
 
 @mark.parametrize('from_data, format, expected', [
Repository: wearewhys/magnivore

Issue:
Add possibility to specify whether to round up or down in factor

Comments:

Patch:
diff --git a/magnivore/Lexicon.py b/magnivore/Lexicon.py
index 84ae7a2..acf038b 100644
--- a/magnivore/Lexicon.py
+++ b/magnivore/Lexicon.py
@@ -2,6 +2,7 @@
 import re
 from decimal import Decimal
 from functools import reduce
+from math import ceil, floor
 
 from .Tracker import Tracker
 
@@ -40,7 +41,12 @@ class Lexicon:
         """
         value = cls._dot_reduce(rule['from'], target)
         original_type = type(value)
-        return original_type(Decimal(value) * Decimal(rule['factor']))
+        result = Decimal(value) * Decimal(rule['factor'])
+        if 'round' in rule:
+            if rule['round'] == 'up':
+                return original_type(ceil(result))
+            return original_type(floor(result))
+        return original_type(result)
 
     @classmethod
     def format(cls, rule, target):


Test patch:
diff --git a/tests/unit/Lexicon.py b/tests/unit/Lexicon.py
index f1c85d6..3af833c 100644
--- a/tests/unit/Lexicon.py
+++ b/tests/unit/Lexicon.py
@@ -65,6 +65,19 @@ def test_lexicon_factor(from_data, target, expected):
     assert type(result) == type(expected)
 
 
+@mark.parametrize('rounding, expected', [
+    ('down', 47),
+    ('up', 48)
+])
+def test_lexicon_factor_round(rounding, expected):
+    rule = {
+        'from': 'value',
+        'round': rounding,
+        'factor': 0.5
+    }
+    assert Lexicon.factor(rule, MagicMock(value=95)) == expected
+
+
 @mark.parametrize('from_data, format, expected', [
     ('birthyear', '{}-0-0', '1992-0-0'),
     (['birthyear', 'birthmonth'], '{}-{}-0', '1992-9-0')
Repository: wearewhys/magnivore

Issue:
Add ability to specify selected columns
It should be possible to specify the columns to be selected in when retrieving items. This is necessary as it would allow to retrieve aggregated sets e.g. count queries

Comments:

Patch:
diff --git a/magnivore/Targets.py b/magnivore/Targets.py
index c2aa61c..27ce660 100644
--- a/magnivore/Targets.py
+++ b/magnivore/Targets.py
@@ -66,6 +66,16 @@ class Targets:
             return query.join(model, 'LEFT OUTER', on=expression)
         return query.join(model, on=expression)
 
+    def _apply_pick(self, query, join):
+        model = self.source_models[join['table']]
+        selects = []
+        for column, value in join['picks'].items():
+            if value is True:
+                selects.append(getattr(model, column))
+            elif value == 'sum':
+                selects.append(fn.Sum(getattr(model, column)))
+        return query.select(*selects)
+
     def get(self, joins, limit=None, offset=0):
         """
         Retrieves the targets for the given joins
@@ -76,6 +86,7 @@ class Targets:
         aggregations = []
         conditions = []
         models = []
+        picks = []
         for join in joins:
             models.append(self.source_models[join['table']])
             if 'conditions' in join:
@@ -84,7 +95,14 @@ class Targets:
             if 'aggregation' in join:
                 aggregations.append(join)
 
-        query = models[0].select(*models)
+            if 'picks' in join:
+                picks.append(join)
+
+        query = models[0]
+        if picks == []:
+            query = query.select(*models)
+        for pick in picks:
+            query = self._apply_pick(query, pick)
 
         joins.pop(0)
         for join in joins:


Test patch:
diff --git a/tests/unit/Targets.py b/tests/unit/Targets.py
index a0668e5..159af9c 100644
--- a/tests/unit/Targets.py
+++ b/tests/unit/Targets.py
@@ -193,6 +193,24 @@ def test_get_aggregations_eq(mocker, targets, joins, nodes, nodes_query):
     assert nodes_query.join().group_by().having().execute.call_count == 1
 
 
+def test_get_picks(targets, joins, nodes, nodes_query):
+    joins[0]['picks'] = {
+        'field': True
+    }
+    targets.get(joins)
+    nodes.select.assert_called_with(nodes.field)
+    assert nodes_query.join().execute.call_count == 1
+
+
+def test_get_picks_sum(targets, joins, nodes, nodes_query):
+    joins[0]['picks'] = {
+        'field': 'sum'
+    }
+    targets.get(joins)
+    nodes.select.assert_called_with(fn.Sum(nodes.field))
+    assert nodes_query.join().execute.call_count == 1
+
+
 def test_get_log_query(targets, joins, nodes_query, logger):
     targets.get(joins)
     calls = [call.logger.log('get-targets', nodes_query.join())]