nebius/SWE-bench-extra huggingface dataset:
Repository: fnl/syntok

Issue:
Bug in not-contraction handling code
Hi,

Thanks for the great library! I think I ran into a weird edge-case wrt not-contraction handling code. If I use the following example:
```python
from syntok.tokenizer import Tokenizer

tok = Tokenizer(replace_not_contraction=False)
tok.split("n't")
```

The output is `[<Token '' : "n't" @ 1>]`. Something is going wrong in the offset calculation there, that 1 should be a 0... The real example this came from is a sentence in the AIDA dataset, `" Falling share prices in New York do n't hurt Mexico as long as it happens gradually , as earlier this week`.

I see the same with "don't": `[<Token '' : 'do' @ 0>, <Token '' : "n't" @ 3>]`, that 3 should be 2 no?

Would love to hear your thoughts, not sure how to fix this neatly yet.

Comments:

Patch:
diff --git a/syntok/tokenizer.py b/syntok/tokenizer.py
index e27a705..edb3f7f 100644
--- a/syntok/tokenizer.py
+++ b/syntok/tokenizer.py
@@ -221,7 +221,7 @@ class Tokenizer:
                     yield Token(prefix, word[remainder:mo.start() - 1], offset + remainder)
                     prefix = ""
 
-                yield Token(prefix, "not" if self.replace_not_contraction else 'n' + mo.group(0), offset + mo.start())
+                yield Token(prefix, "not" if self.replace_not_contraction else 'n' + mo.group(0), offset + mo.start() - 1)
                 return ""
 
             yield Token(prefix, word[remainder:mo.start()], offset + remainder)


Test patch:
diff --git a/syntok/tokenizer_test.py b/syntok/tokenizer_test.py
index e40a032..dbb3cbe 100644
--- a/syntok/tokenizer_test.py
+++ b/syntok/tokenizer_test.py
@@ -91,6 +91,23 @@ class TestTokenizer(TestCase):
         self.assertListEqual(s(result), ["\U0001F64C", ".", "A"])
         self.assertListEqual([t.offset for t in result], [0, 1, 2])  # requires Py3.3+
 
+    def test_apostrophe_offset_without_replace_not_contraction(self):
+        # NOTE: in this case nothing is replaced, so the offsets should remain identical
+        # to those in the original text
+        text = "don't"
+        self.tokenizer = Tokenizer(replace_not_contraction=False)
+        result = self.tokenizer.split(text)
+        self.assertListEqual([t.offset for t in result], [0, 2])
+
+    def test_apostrophe_offset_with_replace_not_contraction(self):
+        # NOTE: in this case, "n't" is replaced with "not", so a space is introduced.
+        # e.g. "don't" -> "do not", "can't" -> "can not"
+        text = "don't"
+        self.tokenizer = Tokenizer(replace_not_contraction=True)
+        result = self.tokenizer.split(text)
+        self.assertListEqual([t.offset for t in result], [0, 2])
+        self.assertListEqual([t.value for t in result], ["do", "not"])
+
 
 class TestToText(TestCase):
Repository: frictionlessdata/frictionless-py

Issue:
Query(limit_rows=0) doesn't limit rows
# Overview

From here - https://github.com/frictionlessdata/frictionless-py/issues/516. Also the same must be for limit_fields


Comments:

Patch:
diff --git a/frictionless/query.py b/frictionless/query.py
index 3315f852..247992c2 100644
--- a/frictionless/query.py
+++ b/frictionless/query.py
@@ -170,11 +170,11 @@ class Query(Metadata):
         "properties": {
             "pickFields": {"type": "array"},
             "skipFields": {"type": "array"},
-            "limitFields": {"type": "number"},
-            "offsetFields": {"type": "number"},
+            "limitFields": {"type": "number", "minimum": 1},
+            "offsetFields": {"type": "number", "minimum": 1},
             "pickRows": {"type": "array"},
             "skipRows": {"type": "array"},
-            "limitRows": {"type": "number"},
-            "offsetRows": {"type": "number"},
+            "limitRows": {"type": "number", "minimum": 1},
+            "offsetRows": {"type": "number", "minimum": 1},
         },
     }


Test patch:
diff --git a/tests/test_table.py b/tests/test_table.py
index 97d23601..f269c50c 100644
--- a/tests/test_table.py
+++ b/tests/test_table.py
@@ -851,6 +851,50 @@ def test_table_limit_offset_rows():
         assert table.read_data() == [["3", "c"], ["4", "d"]]
 
 
+def test_table_limit_fields_error_zero_issue_521():
+    source = "data/long.csv"
+    query = Query(limit_fields=0)
+    table = Table(source, query=query)
+    with pytest.raises(exceptions.FrictionlessException) as excinfo:
+        table.open()
+    error = excinfo.value.error
+    assert error.code == "query-error"
+    assert error.note.count('minimum of 1" at "limitFields')
+
+
+def test_table_offset_fields_error_zero_issue_521():
+    source = "data/long.csv"
+    query = Query(offset_fields=0)
+    table = Table(source, query=query)
+    with pytest.raises(exceptions.FrictionlessException) as excinfo:
+        table.open()
+    error = excinfo.value.error
+    assert error.code == "query-error"
+    assert error.note.count('minimum of 1" at "offsetFields')
+
+
+def test_table_limit_rows_error_zero_issue_521():
+    source = "data/long.csv"
+    query = Query(limit_rows=0)
+    table = Table(source, query=query)
+    with pytest.raises(exceptions.FrictionlessException) as excinfo:
+        table.open()
+    error = excinfo.value.error
+    assert error.code == "query-error"
+    assert error.note.count('minimum of 1" at "limitRows')
+
+
+def test_table_offset_rows_error_zero_issue_521():
+    source = "data/long.csv"
+    query = Query(offset_rows=0)
+    table = Table(source, query=query)
+    with pytest.raises(exceptions.FrictionlessException) as excinfo:
+        table.open()
+    error = excinfo.value.error
+    assert error.code == "query-error"
+    assert error.note.count('minimum of 1" at "offsetRows')
+
+
 # Header
Repository: frictionlessdata/frictionless-py

Issue:
Resource names coming from 'infer' should not retain uppercase characters
# Overview

In working on a dataset where some of the filenames contain uppercase characters, I see that those characters are retained in the resource names when one processes them with `infer`. 

For example, `RAW_input_stream_1.csv` will be given a resource name of `RAW_input_stream_1`. This violates the JSONschema, which allows only lowercase letters: `^([-a-z0-9._/])+$`

---

Please preserve this line to notify @roll (lead of this repository)


Comments:

Patch:
diff --git a/data/Table With Data.csv b/data/Table With Data.csv
new file mode 100644
index 00000000..6d09540e
--- /dev/null
+++ b/data/Table With Data.csv
@@ -0,0 +1,3 @@
+id,name
+1,english
+2,中国人
diff --git a/frictionless/helpers.py b/frictionless/helpers.py
index 97445639..67885215 100644
--- a/frictionless/helpers.py
+++ b/frictionless/helpers.py
@@ -9,6 +9,7 @@ import chardet
 import tempfile
 import datetime
 import stringcase
+from slugify import slugify
 from inspect import signature
 from importlib import import_module
 from urllib.parse import urlparse, parse_qs
@@ -136,13 +137,14 @@ def compile_regex(items):
         return result
 
 
-# TODO: use slugify
 def detect_name(source):
+    name = "memory"
     if isinstance(source, str) and "\n" not in source:
-        return os.path.splitext(os.path.basename(source))[0]
-    if isinstance(source, list) and source and isinstance(source[0], str):
-        return os.path.splitext(os.path.basename(source[0]))[0]
-    return "memory"
+        name = os.path.splitext(os.path.basename(source))[0]
+    elif isinstance(source, list) and source and isinstance(source[0], str):
+        name = os.path.splitext(os.path.basename(source[0]))[0]
+    name = slugify(name).lower()
+    return name
 
 
 def detect_basepath(descriptor):


Test patch:
diff --git a/tests/test_resource.py b/tests/test_resource.py
index d85951fa..6cbed497 100644
--- a/tests/test_resource.py
+++ b/tests/test_resource.py
@@ -606,6 +606,13 @@ def test_resource_infer_from_path():
     assert resource.path == "data/table.csv"
 
 
+def test_resource_infer_not_slugified_name_issue_531():
+    resource = Resource()
+    resource.infer("data/Table With Data.csv")
+    assert resource.metadata_valid
+    assert resource.name == "table-with-data"
+
+
 # Import/Export
Repository: fronzbot/blinkpy

Issue:
Battery percentage reported is incorrect
**Describe the bug**
The current way of calculating battery percentage is completely incorrect (I don't really know what I was thinking when I implemented it).  It takes current battery voltage divided by what the voltage should be when full....which is not even close to the correct calculation.

**Possible solution**
I'm not sure we have any good hooks to calculate battery percentage, so we may just have to use the standard "OK" or "Replace" keywords, which suck but it is what it is.  We can still, perhaps, report the battery voltage... but I'm not sure how useful that actually is.


Comments:

Patch:
diff --git a/blinkpy/camera.py b/blinkpy/camera.py
index 7b05b93..8b904f5 100644
--- a/blinkpy/camera.py
+++ b/blinkpy/camera.py
@@ -41,6 +41,7 @@ class BlinkCamera():
             'temperature_c': self.temperature_c,
             'temperature_calibrated': self.temperature_calibrated,
             'battery': self.battery,
+            'battery_voltage': self.battery_voltage,
             'thumbnail': self.thumbnail,
             'video': self.clip,
             'motion_enabled': self.motion_enabled,
@@ -54,8 +55,8 @@ class BlinkCamera():
 
     @property
     def battery(self):
-        """Return battery level as percentage."""
-        return round(self.battery_voltage / 180 * 100)
+        """Return battery as string."""
+        return self.battery_state
 
     @property
     def temperature_c(self):


Test patch:
diff --git a/tests/test_cameras.py b/tests/test_cameras.py
index 866a2a0..17f6f64 100644
--- a/tests/test_cameras.py
+++ b/tests/test_cameras.py
@@ -87,7 +87,7 @@ class TestBlinkCameraSetup(unittest.TestCase):
         self.assertEqual(self.camera.network_id, '5678')
         self.assertEqual(self.camera.serial, '12345678')
         self.assertEqual(self.camera.motion_enabled, False)
-        self.assertEqual(self.camera.battery, 50)
+        self.assertEqual(self.camera.battery, 'ok')
         self.assertEqual(self.camera.temperature, 68)
         self.assertEqual(self.camera.temperature_c, 20)
         self.assertEqual(self.camera.temperature_calibrated, 71)
Repository: fronzbot/blinkpy

Issue:
Video download problem - "Unauthorized Access","code":101
I have been using Blinkpy to download videos to my PC for almost a year. Last time that I was able to download the video files was about 4 weeks ago. Today when I was trying to download new video files since my last downloading, I found the sizes of the downloaded video files are all 1kB, obviously something was not right. When I open the video files they just have one line of ASCII text showing below:
{"message":"Unauthorized Access","code":101}
My user name and password should be correct because after the code:
>blink.auth = auth
>blink.start()
No error message is shown. If the password is not correct, the error message 'Login endpoint failed. Try again later.' will be shown. 

Anybody know what is the csuse of this problem? Thank you.



Comments:

Patch:
diff --git a/blinkpy/auth.py b/blinkpy/auth.py
index bc61387..c7e997b 100644
--- a/blinkpy/auth.py
+++ b/blinkpy/auth.py
@@ -58,7 +58,11 @@ class Auth:
         """Return authorization header."""
         if self.token is None:
             return None
-        return {"TOKEN_AUTH": self.token, "user-agent": DEFAULT_USER_AGENT}
+        return {
+            "TOKEN_AUTH": self.token,
+            "user-agent": DEFAULT_USER_AGENT,
+            "content-type": "application/json",
+        }
 
     def create_session(self, opts=None):
         """Create a session for blink communication."""
@@ -227,6 +231,9 @@ class Auth:
             try:
                 json_resp = response.json()
                 blink.available = json_resp["valid"]
+                if not json_resp["valid"]:
+                    _LOGGER.error(f"{json_resp['message']}")
+                    return False
             except (KeyError, TypeError):
                 _LOGGER.error("Did not receive valid response from server.")
                 return False


Test patch:
diff --git a/tests/test_auth.py b/tests/test_auth.py
index c5c082b..45e6cff 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -128,7 +128,11 @@ class TestAuth(unittest.TestCase):
     def test_header(self):
         """Test header data."""
         self.auth.token = "bar"
-        expected_header = {"TOKEN_AUTH": "bar", "user-agent": const.DEFAULT_USER_AGENT}
+        expected_header = {
+            "TOKEN_AUTH": "bar",
+            "user-agent": const.DEFAULT_USER_AGENT,
+            "content-type": "application/json",
+        }
         self.assertDictEqual(self.auth.header, expected_header)
 
     def test_header_no_token(self):