nebius/SWE-bench-extra huggingface dataset:
Repository: heavenshell/py-doq

Issue:
EOF newline is stripped off
Take the following file as an example:
```
# file.py
def f(x):
    pass

```
Notice the last empty line which is *required* by git to diff files properly.

Now, passing this file to doq using this command: `doq -w -f file.py`, produces the following:
```
# file.py
def f(x):
    """f.

    :param x:
    """
    pass
```
Notice that the last line has been stripped

Comments:

Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index dbe033a..fb1bfcc 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -8,7 +8,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        python-version: [3.6, 3.7, 3.8]
+        python-version: [3.6, 3.7, 3.8, 3.9]
 
     steps:
     - uses: actions/checkout@v2
diff --git a/doq/cli.py b/doq/cli.py
index 287e6c5..1d7b7ff 100644
--- a/doq/cli.py
+++ b/doq/cli.py
@@ -226,10 +226,10 @@ def run(args):
 
         if args.write and target['path'] != '<stdin>':
             with open(target['path'], 'w') as f:
-                f.write(output)
+                f.write(output + '\n')
 
         else:
-            sys.stdout.write(output)
+            sys.stdout.write(output + '\n')
 
     return True
 


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 16dffd9..9a3ae16 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -59,7 +59,7 @@ class CliTestCase(TestCase):
                     run(args)
             actual = p.getvalue().split('\n')
             with open(os.path.join(expected_path, file)) as f:
-                expected = f.read().rstrip().split('\n')
+                expected = f.read().split('\n')
 
             self.assertSequenceEqual(expected, actual)
 
@@ -108,7 +108,7 @@ class CliTestCase(TestCase):
                     run(args)
             actual = p.getvalue().split('\n')
             with open(os.path.join(expected_path, file)) as f:
-                expected = f.read().rstrip().split('\n')
+                expected = f.read().split('\n')
 
             self.assertSequenceEqual(expected, actual)
 
@@ -157,7 +157,7 @@ class CliTestCase(TestCase):
                     run(args)
             actual = p.getvalue().split('\n')
             with open(os.path.join(expected_path, file)) as f:
-                expected = f.read().rstrip().split('\n')
+                expected = f.read().split('\n')
 
             self.assertSequenceEqual(expected, actual)
Repository: hgrecco/pint

Issue:
System lister error
When trying to check the available unit systems (as shown in [documentation](https://pint.readthedocs.io/en/0.7.2/systems.html)):
`>>> dir(ureg.sys)`

An error occurs:

> TypeError: **dir**() must return a list, not frozenset

**Python:** 2.7.12 (3.5.2 works fine)
**Pint:** 0.72


Comments:

Patch:
diff --git a/pint/default_en.txt b/pint/default_en.txt
index 807d4ad..391febe 100644
--- a/pint/default_en.txt
+++ b/pint/default_en.txt
@@ -108,7 +108,7 @@ btu = 1.05505585262e3 * joule = Btu = BTU = british_thermal_unit
 electron_volt = 1.60217653e-19 * J = eV
 quadrillion_btu = 10**15 * btu = quad
 thm = 100000 * BTU = therm = EC_therm
-cal = 4.184 * joule = calorie = thermochemical_calorie
+calorie = 4.184 * joule = cal = thermochemical_calorie
 international_steam_table_calorie = 4.1868 * joule
 ton_TNT = 4.184e9 * joule = tTNT
 US_therm = 1.054804e8 * joule
diff --git a/pint/quantity.py b/pint/quantity.py
index 980ff10..16b1dea 100644
--- a/pint/quantity.py
+++ b/pint/quantity.py
@@ -403,9 +403,9 @@ class _Quantity(SharedRegistryObject):
         unit_power = list(q_base._units.items())[0][1]
 
         if unit_power > 0:
-            power = int(math.floor(math.log10(magnitude) / unit_power / 3)) * 3
+            power = int(math.floor(math.log10(abs(magnitude)) / unit_power / 3)) * 3
         else:
-            power = int(math.ceil(math.log10(magnitude) / unit_power / 3)) * 3
+            power = int(math.ceil(math.log10(abs(magnitude)) / unit_power / 3)) * 3
 
         prefix = SI_bases[bisect.bisect_left(SI_powers, power)]
 
diff --git a/pint/systems.py b/pint/systems.py
index e2d5564..e74b6de 100644
--- a/pint/systems.py
+++ b/pint/systems.py
@@ -434,7 +434,7 @@ class Lister(object):
         self.d = d
 
     def __dir__(self):
-        return frozenset(self.d.keys())
+        return list(self.d.keys())
 
     def __getattr__(self, item):
         return self.d[item]


Test patch:
diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py
index fd0a6b1..0a4c18b 100644
--- a/pint/testsuite/test_quantity.py
+++ b/pint/testsuite/test_quantity.py
@@ -123,8 +123,14 @@ class TestQuantity(QuantityTestCase):
         self.assertEqual(q2.magnitude, q2b.magnitude)
         self.assertEqual(q2.units, q2b.units)
 
+        q3 = (-1000.0 * self.ureg('meters')).to_compact()
+        q3b = self.Q_(-1., 'kilometer')
+        self.assertEqual(q3.magnitude, q3b.magnitude)
+        self.assertEqual(q3.units, q3b.units)
+
         self.assertEqual('{0:#.1f}'.format(q1), '{0}'.format(q1b))
         self.assertEqual('{0:#.1f}'.format(q2), '{0}'.format(q2b))
+        self.assertEqual('{0:#.1f}'.format(q3), '{0}'.format(q3b))
 
 
     def test_default_formatting(self):
Repository: hgrecco/pint

Issue:
Concentration Units
Hi, 

Is there any reason concentration units (in particular molarity, mol / L) is not included as a default unit in Pint? It is very easy to define on its own, but it seems well-used enough to warrant inclusion in the defaults list. If there are no objections to adding it, I'm happy to submit a PR doing so.

Comments:

Patch:
diff --git a/.gitignore b/.gitignore
index e39c2e8..545148c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,6 @@ MANIFEST
 
 # WebDAV file system cache files
 .DAV/
+
+# tags files (from ctags)
+tags
diff --git a/pint/default_en.txt b/pint/default_en.txt
index 4035883..fba87d2 100644
--- a/pint/default_en.txt
+++ b/pint/default_en.txt
@@ -72,6 +72,10 @@ cmil = 5.067075e-10 * m ** 2 = circular_mils
 darcy = 9.869233e-13 * m ** 2
 hectare = 100 * are = ha
 
+# Concentration
+[concentration] = [substance] / [volume]
+molar = mol / (1e-3 * m ** 3) = M
+
 # EM
 esu = 1 * erg**0.5 * centimeter**0.5 = statcoulombs = statC = franklin = Fr
 esu_per_second = 1 * esu / second = statampere


Test patch:
diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py
index 3b06fd6..b5c494b 100644
--- a/pint/testsuite/test_issues.py
+++ b/pint/testsuite/test_issues.py
@@ -39,7 +39,6 @@ class TestIssues(QuantityTestCase):
 
     def test_issue29(self):
         ureg = UnitRegistry()
-        ureg.define('molar = mole / liter = M')
         t = 4 * ureg('mM')
         self.assertEqual(t.magnitude, 4)
         self.assertEqual(t._units, UnitsContainer(millimolar=1))
@@ -561,4 +560,4 @@ class TestIssuesNP(QuantityTestCase):
         a = np.asarray([1, 2, 3])
         q = [1, 2, 3] * ureg.dimensionless
         p = (q ** q).m
-        np.testing.assert_array_equal(p, a ** a)
\ No newline at end of file
+        np.testing.assert_array_equal(p, a ** a)
Repository: hgrecco/pint-pandas

Issue:
series.astype(float) not returning series of floats
# Start: series with dimensionless values

```python
import pandas as pd
import pint
import pint_pandas

s0 = pd.Series([1.0, 2.5])
s1 = s0.astype('pint[dimensionless]')

s1
# 0    1.0
# 1    2.5
# dtype: pint[]
```

# Issue: conversion back to floats

```python
s2 = s1.astype(float)
```

Previously, the resulting Series had a `float` data type. Now, the datatype is slightly different, which causes the comparison with `s0` to fail.
```
s2.dtype
# PandasDtype('float64')

pd.testing.assert_series_equal(s0, s2)  #"dtypes are different"
```

Another issue is, that `s2` cannot be converted to a string:

```python
s2
#AttributeError: 'numpy.ndarray' object has no attribute '_formatter'
```

Excuse me as I currently cannot test this with the latest `pandas` version; I've used `2.1` instead. `pint-pandas` `0.5` , and `pint` `0.22`.

Comments:

Patch:
diff --git a/CHANGES b/CHANGES
index 4ce6b16..f896b8e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,7 +4,7 @@ pint-pandas Changelog
 0.6 (unreleased)
 ----------------
 
-- Nothing changed yet.
+- Fix astype issue #196
 
 
 0.5 (2023-09-07)
diff --git a/pint_pandas/pint_array.py b/pint_pandas/pint_array.py
index 7154be5..fcbfe61 100644
--- a/pint_pandas/pint_array.py
+++ b/pint_pandas/pint_array.py
@@ -417,7 +417,9 @@ class PintArray(ExtensionArray, ExtensionOpsMixin):
             return self._to_array_of_quantity(copy=copy)
         if is_string_dtype(dtype):
             return pd.array([str(x) for x in self.quantity], dtype=dtype)
-        return pd.array(self.quantity, dtype, copy)
+        if isinstance(self._data, ExtensionArray):
+            return self._data.astype(dtype, copy=copy)
+        return pd.array(self.quantity.m, dtype, copy)
 
     @property
     def units(self):


Test patch:
diff --git a/pint_pandas/testsuite/test_issues.py b/pint_pandas/testsuite/test_issues.py
index 95d85b2..d8d6ce0 100644
--- a/pint_pandas/testsuite/test_issues.py
+++ b/pint_pandas/testsuite/test_issues.py
@@ -185,3 +185,12 @@ class TestIssue174(BaseExtensionTests):
         expected_2 = pd.Series([3, 12], dtype="pint[m]")
 
         tm.assert_series_equal(col_sum, expected_2)
+
+
+@pytest.mark.parametrize("dtype", [pd.Float64Dtype(), "float"])
+def test_issue_194(dtype):
+    s0 = pd.Series([1.0, 2.5], dtype=dtype)
+    s1 = s0.astype("pint[dimensionless]")
+    s2 = s1.astype(dtype)
+
+    tm.assert_series_equal(s0, s2)