ernie-research/MEnvData-SWE huggingface dataset:
Repository: Instagram/LibCST (Python)

Issue:
`ScopeProvider` breaks on accessing an attribute returned by a function.
@zsol I'm pretty sure https://github.com/Instagram/LibCST/commit/477a03e3a822fe9b87ef8d891351192325837818 broke this - it worked the commit before that.

Repro:
```python
import libcst as cst

wrapper = cst.metadata.MetadataWrapper(cst.parse_module('foo().bar'))
scopes = set(wrapper.resolve(cst.metadata.ScopeProvider).values())
```

Result:
```
ValueError: Unexpected name value in import: Call(
    func=Name(
        value='super',
        lpar=[],
        rpar=[],
    ),
    args=[],
    lpar=[],
    rpar=[],
    whitespace_after_func=SimpleWhitespace(
        value='',
    ),
    whitespace_before_args=SimpleWhitespace(
        value='',
    ),
)
```


Discussion:
Thanks for reporting this and included a simple reproduce.
We'll make sure fixing it before releasing the next version.
Based on the example, the Unexpected name should be `Name(value="foo")` instead of `Name(value="super")`.
Apologies, I completely missed this. There's a fix up now.



Patch:
diff --git a/libcst/metadata/scope_provider.py b/libcst/metadata/scope_provider.py
index 296da70de..3d02f0343 100644
--- a/libcst/metadata/scope_provider.py
+++ b/libcst/metadata/scope_provider.py
@@ -601,7 +601,8 @@ def _gen_dotted_names(
     else:
         value = node.value
         if not isinstance(value, (cst.Attribute, cst.Name)):
-            raise ValueError(f"Unexpected name value in import: {value}")
+            # this is not an import
+            return
         name_values = iter(_gen_dotted_names(value))
         (next_name, next_node) = next(name_values)
         yield (f"{next_name}.{node.attr.value}", node)
@@ -818,7 +819,8 @@ def infer_accesses(self) -> None:
                     if name in access.scope:
                         access.node = node
                         break
-                assert name is not None
+                if name is None:
+                    continue
             else:
                 name = ensure_type(access.node, cst.Name).value
             scope_name_accesses[(access.scope, name)].add(access)


Test patch:
diff --git a/libcst/metadata/tests/test_scope_provider.py b/libcst/metadata/tests/test_scope_provider.py
index f9d164621..b7cdb2a99 100644
--- a/libcst/metadata/tests/test_scope_provider.py
+++ b/libcst/metadata/tests/test_scope_provider.py
@@ -1064,6 +1064,13 @@ def test_contains_is_read_only(self) -> None:
                     list(scope.parent._accesses.items()), before_parent_accesses
                 )
 
+    def test_attribute_of_function_call(self) -> None:
+        get_scope_metadata_provider("foo().bar")
+
+    def test_self(self) -> None:
+        with open(__file__) as f:
+            get_scope_metadata_provider(f.read())
+
     def test_get_qualified_names_for_is_read_only(self) -> None:
         m, scopes = get_scope_metadata_provider(
             """
Repository: certbot/certbot (Python)

Issue:
`acme` module's `client._revoke` sends incorrect `ContentType` header.
[ACME draft-10, section 6.2](https://tools.ietf.org/html/draft-ietf-acme-acme-10#section-6.2) explicitly requires POSTs be sent with a `Content-Type` of `application/jose+json`: 

> Because client requests in ACME carry JWS objects in the Flattened
> JSON Serialization, they must have the "Content-Type" header field
> set to "application/jose+json".  If a request does not meet this
> requirement, then the server MUST return a response with status code
> 415 (Unsupported Media Type).

The good news is that Certbot & the `acme` module already do this in 99.99% of cases :tada: :+1: :balloon: 

The bad news is that `client._revoke` overrides the default (correct) `ContentType` with `none`: https://github.com/certbot/certbot/blob/77fdb4d7d6194989dcc775f2e0ad81b6147c2359/acme/acme/client.py#L231

This will make revocation requests fail in a world where this restriction is enforced (See https://github.com/letsencrypt/boulder/pull/3532) 

There doesn't seem to be a reason to want to override `ContentType` in this case so I believe the fix is to change `_revoke` to use the default.

Thanks!


Discussion:

Patch:
diff --git a/acme/acme/client.py b/acme/acme/client.py
index d52c82a5cb4..9e2478afe4f 100644
--- a/acme/acme/client.py
+++ b/acme/acme/client.py
@@ -227,8 +227,7 @@ def _revoke(self, cert, rsn, url):
         response = self._post(url,
                               messages.Revocation(
                                 certificate=cert,
-                                reason=rsn),
-                                content_type=None)
+                                reason=rsn))
         if response.status_code != http_client.OK:
             raise errors.ClientError(
                 'Successful revocation must return HTTP OK status')


Test patch:
diff --git a/acme/acme/client_test.py b/acme/acme/client_test.py
index a0c27e74fab..00b9e19dd06 100644
--- a/acme/acme/client_test.py
+++ b/acme/acme/client_test.py
@@ -635,8 +635,7 @@ def test_fetch_chain_too_many(self):  # recursive
     def test_revoke(self):
         self.client.revoke(self.certr.body, self.rsn)
         self.net.post.assert_called_once_with(
-            self.directory[messages.Revocation], mock.ANY, content_type=None,
-            acme_version=1)
+            self.directory[messages.Revocation], mock.ANY, acme_version=1)
 
     def test_revocation_payload(self):
         obj = messages.Revocation(certificate=self.certr.body, reason=self.rsn)
@@ -776,8 +775,7 @@ def test_finalize_order_timeout(self):
     def test_revoke(self):
         self.client.revoke(messages_test.CERT, self.rsn)
         self.net.post.assert_called_once_with(
-            self.directory["revokeCert"], mock.ANY, content_type=None,
-            acme_version=2)
+            self.directory["revokeCert"], mock.ANY, acme_version=2)
 
 
 class MockJSONDeSerializable(jose.JSONDeSerializable):
Repository: ansible/ansible-runner (Python)

Issue:
Different data passed to status_handler plugin vs kwargs
Hi,

As you can see from my PR, I'm using `ansible.runner.run(status_handler=my_handler)`. I noticed that [Runner.status_callback](https://github.com/ansible/ansible-runner/blob/ce3c90f97fc7c7e7bdc6a53494503b9a907875c0/ansible_runner/runner.py#L76) passes different "data" to `status_handler` defined via **kwargs** vs `status_handler` defined in **plugins**.
Basically, plugins get a dict with *status* and *runner_ident*, opposed to the "kwargs-status_handler" that only gets the status.
Is there any reasoning behind? For me this looks odd, I'd like to get the runner-ident, too. 

If you agree to change this, I could create another PR if you like.


Discussion:
What PR are you referring to? I'm fine with adding the ident if you need it in there.
Sorry, I'm referring to https://github.com/ansible/ansible-runner/pull/140.

I created a PR with a proposed solution.



Patch:
diff --git a/ansible_runner/runner.py b/ansible_runner/runner.py
index 23b711b67..2e8a6cfdd 100644
--- a/ansible_runner/runner.py
+++ b/ansible_runner/runner.py
@@ -71,12 +71,11 @@ def event_callback(self, event_data):
 
     def status_callback(self, status):
         self.status = status
+        status_data = dict(status=status, runner_ident=str(self.config.ident))
         for plugin in ansible_runner.plugins:
-            ansible_runner.plugins[plugin].status_handler(self.config,
-                                                          dict(status=status,
-                                                               runner_ident=str(self.config.ident)))
+            ansible_runner.plugins[plugin].status_handler(self.config, status_data)
         if self.status_handler is not None:
-            self.status_handler(status)
+            self.status_handler(status_data)
 
     def run(self):
         '''


Test patch:
diff --git a/test/unit/test_runner.py b/test/unit/test_runner.py
index c527ab6d4..1ac3c67ae 100644
--- a/test/unit/test_runner.py
+++ b/test/unit/test_runner.py
@@ -109,5 +109,5 @@ def test_status_callback_interface(rc):
     runner.status_handler = mock.Mock()
     runner.status_callback("running")
     assert runner.status_handler.call_count == 1
-    runner.status_handler.assert_called_with('running')
+    runner.status_handler.assert_called_with(dict(status='running', runner_ident=str(rc.ident)))
     assert runner.status == 'running'
Repository: conan-io/conan (Python)

Issue:
tools.environment_append raises if tries to unset variable which was never set
after #4224, I may use the following code, for instance, to ensure variable is not set:
```
with environment_append({'CONAN_BASH_PATH': None}):
    pass
```
however, it raises if `CONAN_BASH_PATH` is not set (prior to the environment_append invocation):
```
Traceback (most recent call last):
  File "C:\bincrafters\conan\conans\test\unittests\client\tools\os_info\osinfo_test.py", line 39, in test_windows
    with environment_append(new_env):
  File "c:\users\sse4\appdata\local\programs\python\python36\lib\contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "C:\bincrafters\conan\conans\client\tools\env.py", line 57, in environment_append
    os.environ.pop(var)
  File "c:\users\sse4\appdata\local\programs\python\python36\lib\_collections_abc.py", line 795, in pop
    value = self[key]
  File "c:\users\sse4\appdata\local\programs\python\python36\lib\os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'CONAN_BASH_PATH'
```
I would expect `tools.environment_append` to be no op in such case, otherwise, it requires additional logic to workaround this behavior.

To help us debug your issue please explain:

- [ ] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [ ] I've specified the Conan version, operating system version and any tool that can be relevant.
- [ ] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.




Discussion:

Patch:
diff --git a/conans/client/tools/env.py b/conans/client/tools/env.py
index 079f549fd12..2584065ddbb 100644
--- a/conans/client/tools/env.py
+++ b/conans/client/tools/env.py
@@ -54,7 +54,7 @@ def environment_append(env_vars):
         old_env = dict(os.environ)
         os.environ.update(env_vars)
         for var in unset_vars:
-            os.environ.pop(var)
+            os.environ.pop(var, None)
         try:
             yield
         finally:


Test patch:
diff --git a/conans/test/unittests/client/tools/test_env.py b/conans/test/unittests/client/tools/test_env.py
index 2fcc1c1c82e..556139e306e 100644
--- a/conans/test/unittests/client/tools/test_env.py
+++ b/conans/test/unittests/client/tools/test_env.py
@@ -46,3 +46,9 @@ def test_environment_append_unsetting_all_variables(self):
                               'env_var2': 'value2'}),\
              env.environment_append({'env_var1': None}):
                 self.assertNotIn('env_var1', os.environ)
+
+    def test_environment_append_unsetting_non_existing_variables(self):
+        with mock.patch.dict('os.environ',
+                             {'env_var2': 'value2'}),\
+             env.environment_append({'env_var1': None}):
+                self.assertNotIn('env_var1', os.environ)
Repository: dask/dask (Python)

Issue:
len(ddf) produces "RecursionError: maximum recursion depth exceeded" (v2.14.0)
Using version **'2.14.0'**

**Reproducible minimal test case:**

```import dask

frames = [dask.dataframe.from_pandas(chunk, npartitions=1) for chunk in 
                pd.read_csv('https://raw.githubusercontent.com/darenr/public_datasets/master/bank.csv', 
                     iterator=True, 
                     chunksize=15000)]

ddf = dask.dataframe.concat(frames, axis=1)
len(ddf)
```
**full error:**

```---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<timed exec> in <module>

~/opt/miniconda3/envs/python3.6.7/lib/python3.6/site-packages/dask/dataframe/core.py in __len__(self)
   3348             return super().__len__()
   3349         else:
-> 3350             return len(s)
   3351 
   3352     @property

... last 1 frames repeated, from the frame below ...

~/opt/miniconda3/envs/python3.6.7/lib/python3.6/site-packages/dask/dataframe/core.py in __len__(self)
   3348             return super().__len__()
   3349         else:
-> 3350             return len(s)
   3351 
   3352     @property

RecursionError: maximum recursion depth exceeded```


**Interestingly ddf.shape is of type** ```(Delayed('int-f847a38a-2a28-49ed-a185-dc6a7a195575'), 68)``` 


Discussion:
Thanks for raising an issue @darenr. There's a PR which contains a fix for this over in https://github.com/dask/dask/pull/6111. 

Also, is it possible you want to `axis=0` when concatenating? 



Patch:
diff --git a/dask/dataframe/core.py b/dask/dataframe/core.py
index 98c984b1a4f..0c5aeba5041 100644
--- a/dask/dataframe/core.py
+++ b/dask/dataframe/core.py
@@ -3359,7 +3359,7 @@ def iloc(self):
 
     def __len__(self):
         try:
-            s = self[self.columns[0]]
+            s = self.iloc[:, 0]
         except IndexError:
             return super().__len__()
         else:


Test patch:
diff --git a/dask/dataframe/tests/test_dataframe.py b/dask/dataframe/tests/test_dataframe.py
index 48d789b712b..b6fb7bdd7e8 100644
--- a/dask/dataframe/tests/test_dataframe.py
+++ b/dask/dataframe/tests/test_dataframe.py
@@ -1062,6 +1062,8 @@ def test_len():
     assert len(d.a) == len(full.a)
     assert len(dd.from_pandas(pd.DataFrame(), npartitions=1)) == 0
     assert len(dd.from_pandas(pd.DataFrame(columns=[1, 2]), npartitions=1)) == 0
+    # Regression test for https://github.com/dask/dask/issues/6110
+    assert len(dd.from_pandas(pd.DataFrame(columns=["foo", "foo"]), npartitions=1)) == 0
 
 
 def test_size():
Repository: joke2k/faker (Python)

Issue:
Norwegian ssn returns the wrong format for the date part 
SSN for no_NO returns the wrong format of the date part.

### Steps to reproduce

As @cloveras pointed out:
Using December 31 1999 as the date of birth (YYYYMMDD):
ssn('19991231','M')

This results in SSNs like these:
99123145123
99123108724
99123127532

### Expected behavior

The correct format is DDMMYY.

### Actual behavior

These start with the date of birth in YYMMDD format.



Discussion:

Patch:
diff --git a/faker/providers/ssn/no_NO/__init__.py b/faker/providers/ssn/no_NO/__init__.py
index 207831b809..2f171d422b 100644
--- a/faker/providers/ssn/no_NO/__init__.py
+++ b/faker/providers/ssn/no_NO/__init__.py
@@ -71,7 +71,7 @@ def ssn(self, dob=None, gender=None):
                 gender_num = self.generator.random.choice((0, 2, 4, 6, 8))
             elif gender == 'M':
                 gender_num = self.generator.random.choice((1, 3, 5, 7, 9))
-            pnr = birthday.strftime('%y%m%d') + suffix.zfill(2) + str(gender_num)
+            pnr = birthday.strftime('%d%m%y') + suffix.zfill(2) + str(gender_num)
             pnr_nums = [int(ch) for ch in pnr]
             k1 = checksum(Provider.scale1, pnr_nums)
             k2 = checksum(Provider.scale2, pnr_nums + [k1])


Test patch:
diff --git a/tests/providers/test_ssn.py b/tests/providers/test_ssn.py
index abf33e6314..11d88cca4b 100644
--- a/tests/providers/test_ssn.py
+++ b/tests/providers/test_ssn.py
@@ -180,9 +180,11 @@ def test_no_NO_ssn(self):
             self.assertEqual(len(ssn), 11)
 
     def test_no_NO_ssn_dob_passed(self):
-        date_of_birth = '20010203'
-        ssn = self.factory.ssn(dob=date_of_birth)
-        self.assertEqual(ssn[:6], date_of_birth[2:])
+        test_data = [('20010203', '030201'),
+                     ('19991231', '311299')]
+        for date_of_birth, expected_dob_part in test_data:
+            ssn = self.factory.ssn(dob=date_of_birth)
+            self.assertEqual(ssn[:6], expected_dob_part)
 
     def test_no_NO_ssn_invalid_dob_passed(self):
         with self.assertRaises(ValueError):
Repository: joke2k/faker (Python)

Issue:
Random sentence of length 1 fails
* Faker version: 5.5.0
* OS: Ubuntu 20.04.1

Creating a random sentence of length 1 fails because it attempts to titleize the first word of the sentence, but `random_choices`  is returning a tuple which is immutable. 

This also occurs sometimes with 2 or 3 length sentences, although I presume that under the hood they are randomly selecting sentences of length 1.

This works as expected in Faker version 5.4.1.

### Steps to reproduce

```
>>> import faker
>>> thing = faker.Faker()
>>> print(thing.sentence(1))
```

### Expected behavior

A random titleized word is printed with a fullstop

### Actual behavior

```
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "~/.../venv/lib/python3.6/site-packages/faker/providers/lorem/__init__.py", line 86, in sentence
    words[0] = words[0].title()
TypeError: 'tuple' object does not support item assignment
```



Discussion:
Hi, Thank you for the report @DanielHarrisSeequent !

I've made a Pull Request with a fix. It should be released today, pending CI :)
Cheers
@fcurella Hi I was just about to report this and a fix - FWIW I think the real issue is here: https://github.com/joke2k/faker/blob/acdfc155099722414be5e46103ad09c3bf19c58b/faker/utils/distribution.py#L64 where a tuple is returned erroneously



Patch:
diff --git a/faker/providers/lorem/__init__.py b/faker/providers/lorem/__init__.py
index cc17fa4723..42c4030f93 100644
--- a/faker/providers/lorem/__init__.py
+++ b/faker/providers/lorem/__init__.py
@@ -22,7 +22,7 @@ class Provider(BaseProvider):
     sentence_punctuation = '.'
 
     def words(self, nb=3, ext_word_list=None, unique=False):
-        """Generate a list of words.
+        """Generate a tuple of words.
 
         The ``nb`` argument controls the number of words in the resulting list,
         and if ``ext_word_list`` is provided, words from that list will be used
@@ -82,7 +82,7 @@ def sentence(self, nb_words=6, variable_nb_words=True, ext_word_list=None):
         if variable_nb_words:
             nb_words = self.randomize_nb_elements(nb_words, min=1)
 
-        words = self.words(nb=nb_words, ext_word_list=ext_word_list)
+        words = list(self.words(nb=nb_words, ext_word_list=ext_word_list))
         words[0] = words[0].title()
 
         return self.word_connector.join(words) + self.sentence_punctuation


Test patch:
diff --git a/tests/providers/test_lorem.py b/tests/providers/test_lorem.py
index 7ba59859c7..be45e8b5f0 100644
--- a/tests/providers/test_lorem.py
+++ b/tests/providers/test_lorem.py
@@ -88,6 +88,10 @@ def test_sentences(self, faker, num_samples):
                 words = sentence.lower().replace('.', '').split()
                 assert all(isinstance(word, str) and word in self.custom_word_list for word in words)
 
+    def test_sentence_single_word(self, faker):
+        word = faker.sentence(1)
+        assert str.isupper(word[0])
+
     def test_paragraph_no_sentences(self, faker, num_samples):
         for _ in range(num_samples):
             assert faker.paragraph(0) == ''
Repository: dbt-labs/dbt-core (Python)

Issue:
Postgres character columns are not treated as string types
## Issue

### Issue description
dbt does not treat character types as string types, and therefore leaves out the length portion of the `character` column type when building columns. This happens during Archival (and likely incremental models when expanding types) on Postgres.

### Results
dbt should treat `character` as a string type, as with `varchar` and `text`.

### System information
The output of `dbt --version`:
```
0.12.x
```

### Steps to reproduce
Archive a table on Postgres with a column of type `character(36)`. dbt will recreate this column with type `character` with no size specified.


This issue was created from the description of https://github.com/fishtown-analytics/dbt/pull/1191


Discussion:

Patch:
diff --git a/dbt/schema.py b/dbt/schema.py
index 3a34903a867..f4b75e7b6a1 100644
--- a/dbt/schema.py
+++ b/dbt/schema.py
@@ -45,7 +45,7 @@ def data_type(self):
             return self.dtype
 
     def is_string(self):
-        return self.dtype.lower() in ['text', 'character varying']
+        return self.dtype.lower() in ['text', 'character varying', 'character']
 
     def is_numeric(self):
         return self.dtype.lower() in ['numeric', 'number']


Test patch:
diff --git a/test/unit/test_schema.py b/test/unit/test_schema.py
index a7c3d94fff0..6c065a422d7 100644
--- a/test/unit/test_schema.py
+++ b/test/unit/test_schema.py
@@ -2,6 +2,17 @@
 
 import dbt.schema
 
+class TestStringType(unittest.TestCase):
+
+    def test__character_type(self):
+        col = dbt.schema.Column(
+            'fieldname',
+            'character',
+            char_size=10
+        )
+
+        self.assertEqual(col.data_type, 'character varying(10)')
+
 
 class TestNumericType(unittest.TestCase):
Repository: fonttools/fonttools (Python)

Issue:
[name] addMultilingualName fails with one-character names
This bug seems to have been introduced between 4.10 and 4.11. @justvanrossum I think you changed something there?

```python
from fontTools.ttLib.tables._n_a_m_e import table__n_a_m_e

t = table__n_a_m_e()

t.addMultilingualName({"en": "A"})
t.addMultilingualName({"en": "B"})
```

Traceback:
```
Traceback (most recent call last):
  File "./test.py", line 8, in <module>
    t.addMultilingualName({"en": "B"})
  File "/Users/kuti/Quellen/fonttools-github/Lib/fontTools/ttLib/tables/_n_a_m_e.py", line 273, in addMultilingualName
    names, windows=windows, mac=mac, minNameID=minNameID)
  File "/Users/kuti/Quellen/fonttools-github/Lib/fontTools/ttLib/tables/_n_a_m_e.py", line 229, in findMultilingualName
    key = (name.toUnicode(), name.platformID,
  File "/Users/kuti/Quellen/fonttools-github/Lib/fontTools/ttLib/tables/_n_a_m_e.py", line 456, in toUnicode
    string = b'\0' + string
TypeError: can't concat str to bytes
```


Discussion:
Confirmed. Yes, that indeed seems to be a regression introduced with my changes. Looking into it.
Actually, it's not 100% a regression, the following fails in 4.10.0 as well:
```python
from fontTools.ttLib import newTable
t = newTable("name")
nameID = t.addMultilingualName({"en": "A"})
rec = t.getName(nameID, 3, 1)
print(rec.toUnicode())
```
Ah yes, I see, it just happened that the new method (findMultiLingualName) triggers the bug.
Thanks for reporting! This is a pretty old bug, probably about as old as Python 3 support in fonttools.



Patch:
diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e.py b/Lib/fontTools/ttLib/tables/_n_a_m_e.py
index a973fe3c92..4bb9024bac 100644
--- a/Lib/fontTools/ttLib/tables/_n_a_m_e.py
+++ b/Lib/fontTools/ttLib/tables/_n_a_m_e.py
@@ -441,7 +441,7 @@ def isascii(b):
 		encoding = self.getEncoding()
 		string = self.string
 
-		if encoding == 'utf_16_be' and len(string) % 2 == 1:
+		if isinstance(string, bytes) and encoding == 'utf_16_be' and len(string) % 2 == 1:
 			# Recover badly encoded UTF-16 strings that have an odd number of bytes:
 			# - If the last byte is zero, drop it.  Otherwise,
 			# - If all the odd bytes are zero and all the even bytes are ASCII,


Test patch:
diff --git a/Tests/ttLib/tables/_n_a_m_e_test.py b/Tests/ttLib/tables/_n_a_m_e_test.py
index a12c1ade58..bc4aab2f13 100644
--- a/Tests/ttLib/tables/_n_a_m_e_test.py
+++ b/Tests/ttLib/tables/_n_a_m_e_test.py
@@ -345,6 +345,11 @@ def test_toUnicode_UnicodeDecodeError(self):
 		self.assertEqual("utf_16_be", name.getEncoding())
 		self.assertRaises(UnicodeDecodeError, name.toUnicode)
 
+	def test_toUnicode_singleChar(self):
+		# https://github.com/fonttools/fonttools/issues/1997
+		name = makeName("A", 256, 3, 1, 0x409)
+		self.assertEqual(name.toUnicode(), "A")
+
 	def toXML(self, name):
 		writer = XMLWriter(BytesIO())
 		name.toXML(writer, ttFont=None)
Repository: dask/dask (Python)

Issue:
std function returns NaN for long floats
Calling `.groupby().std()` on a dataframe with long floating point numbers returns NaNs and a warning. This occurs because internally the variance is calculated as a (small) negative number.

Seems to be a resurfacing of https://github.com/dask/dask/issues/4233

```
import pandas as pd
import dask.dataframe as dd

values = [-0.00179999999 for _ in range(10)]
ids = [1 for _ in range(5)] + [2 for _ in range(5)]

# Returns 0s as expected
df = pd.DataFrame({'ids': ids, 'values':values})
df.groupby("ids").values.std()

# Returns NaNs and a warning
ddf = dd.from_pandas(df, npartitions=2)
ddf.groupby("ids").values.std().compute()
```
The following is returned:

```
/Users/tom/anaconda3/envs/example/lib/python3.7/site-packages/pandas/core/series.py:856: RuntimeWarning: invalid value encountered in sqrt
  result = getattr(ufunc, method)(*inputs, **kwargs)
ids
1   NaN
2   NaN
Name: values, dtype: float64
```

Not totally sure if this is a bug or just the limits of floating point numbers, but would be interested to hear your thoughts.


Discussion:
Thank you for the excellent bug report @tjperr and especially for the minimal reproducible example.

My guess is that this is due to numeric instability.  Done naively, the calculation of std is prone to small errors rounding errors.  We have a much more advanced algorithm in dask.array that we also use for full series objects, which is more robust, but never did the work to extend this to dask dataframe in the groupby case (which complicates things).  I can see a couple of paths forward here:

1.  Someone could implement the full stable calculation of moments for groupby aggregations.  My guess is that this would take someone with some mathematical ability a couple of weeks.
2.  We could accept the numeric instability, but add a quick rounding to zero if the variance is zero.

I've implemented option 2 in https://github.com/dask/dask/pull/5728



Patch:
diff --git a/dask/dataframe/groupby.py b/dask/dataframe/groupby.py
index e870225f202..eae981e56ba 100644
--- a/dask/dataframe/groupby.py
+++ b/dask/dataframe/groupby.py
@@ -332,6 +332,7 @@ def _var_agg(g, levels, ddof):
     result /= div
     result[(n - ddof) == 0] = np.nan
     assert is_dataframe_like(result)
+    result[result < 0] = 0  # avoid rounding errors that take us to zero
     return result
 
 


Test patch:
diff --git a/dask/dataframe/tests/test_groupby.py b/dask/dataframe/tests/test_groupby.py
index 73992d010f0..5dad375ff72 100644
--- a/dask/dataframe/tests/test_groupby.py
+++ b/dask/dataframe/tests/test_groupby.py
@@ -2286,3 +2286,13 @@ def test_groupby_dropna_cudf(dropna, by):
         dask_result.index.name = cudf_result.index.name
 
     assert_eq(dask_result, cudf_result)
+
+
+def test_rounding_negative_var():
+    x = [-0.00179999999 for _ in range(10)]
+    ids = [1 for _ in range(5)] + [2 for _ in range(5)]
+
+    df = pd.DataFrame({"ids": ids, "x": x})
+
+    ddf = dd.from_pandas(df, npartitions=2)
+    assert_eq(ddf.groupby("ids").x.std(), df.groupby("ids").x.std())
Repository: fsspec/filesystem_spec (Python)

Issue:
API mismatch between mapping and implementations
the [`delitems`](https://github.com/intake/filesystem_spec/blob/master/fsspec/mapping.py#L113) method in `FSMap` expects the underlying filesystem to have an `rm` method that accepts a list of strings. However, this behavior of `FSMap` appears to be untested, and if tested would certainly fail for at least [`LocalFileSystem.rm`](https://github.com/intake/filesystem_spec/blob/master/fsspec/implementations/local.py#L124), which accepts only a single string as input. Would a PR changing the behavior of `LocalFileSystem.rm` + adding tests be welcome? This would help move this Zarr PR forward: https://github.com/zarr-developers/zarr-python/pull/738#issuecomment-849966740


Discussion:
> Would a PR changing the behavior of LocalFileSystem.rm + adding tests be welcome? 

Yes please! 



Patch:
diff --git a/fsspec/implementations/local.py b/fsspec/implementations/local.py
index 69f494941..cdcf619e4 100644
--- a/fsspec/implementations/local.py
+++ b/fsspec/implementations/local.py
@@ -122,14 +122,18 @@ def mv_file(self, path1, path2, **kwargs):
         shutil.move(path1, path2)
 
     def rm(self, path, recursive=False, maxdepth=None):
-        path = self._strip_protocol(path).rstrip("/")
-        if recursive and self.isdir(path):
+        if isinstance(path, str):
+            path = [path]
 
-            if os.path.abspath(path) == os.getcwd():
-                raise ValueError("Cannot delete current working directory")
-            shutil.rmtree(path)
-        else:
-            os.remove(path)
+        for p in path:
+            p = self._strip_protocol(p).rstrip("/")
+            if recursive and self.isdir(p):
+
+                if os.path.abspath(p) == os.getcwd():
+                    raise ValueError("Cannot delete current working directory")
+                shutil.rmtree(p)
+            else:
+                os.remove(p)
 
     def _open(self, path, mode="rb", block_size=None, **kwargs):
         path = self._strip_protocol(path)
@@ -177,7 +181,7 @@ def _isfilestore(self):
 
 
 def make_path_posix(path, sep=os.sep):
-    """ Make path generic """
+    """Make path generic"""
     if isinstance(path, (list, set, tuple)):
         return type(path)(make_path_posix(p) for p in path)
     if "~" in path:


Test patch:
diff --git a/fsspec/implementations/tests/test_local.py b/fsspec/implementations/tests/test_local.py
index faa2be2fa..c900699bd 100644
--- a/fsspec/implementations/tests/test_local.py
+++ b/fsspec/implementations/tests/test_local.py
@@ -399,6 +399,11 @@ def test_file_ops(tmpdir):
     fs.rm(tmpdir + "/afile3", recursive=True)
     assert not fs.exists(tmpdir + "/afile3")
 
+    files = [tmpdir + "/afile4", tmpdir + "/afile5"]
+    [fs.touch(f) for f in files]
+    fs.rm(files)
+    assert all(not fs.exists(f) for f in files)
+
     fs.rm(tmpdir, recursive=True)
     assert not fs.exists(tmpdir)
Repository: joke2k/faker (Python)

Issue:
too long iban generated for pl-PL locale
* Faker version: 9.8.2
* OS: MacOs 12.0.1

IBANs generated for pl_PL locales are 30 characters long. This is too many. Valid PL IBAN should have 28 characters (including country code).

### Steps to reproduce
Generate a Polish IBAN with:
```
from faker import Faker
  fake=Faker('pl-PL')
  print(fake.iban())
```
Copy paste generated string into IBAN Validator at https://www.ibancalculator.com/
### Expected behavior

IBAN should have the correct length and checksum

### Actual behavior

There is an error message that IBAN have too many characters:
"This IBAN cannot be correct because of its length. A Polish IBAN always contains exactly 28 digits and letters ("PL", a 2-digit checksum, and the 24-digit national account number, whose first 8 digits determine the bank and branch). The IBAN you entered is 30 characters long."



Discussion:
Thank you for the report @dziczyzna ! Would you have time to submit a Pull Request?
Hi @fcurella I'm afraid I wouldn't. 



Patch:
diff --git a/faker/providers/bank/pl_PL/__init__.py b/faker/providers/bank/pl_PL/__init__.py
index 9d9b8f647b..9cf6624db9 100644
--- a/faker/providers/bank/pl_PL/__init__.py
+++ b/faker/providers/bank/pl_PL/__init__.py
@@ -4,5 +4,5 @@
 class Provider(BankProvider):
     """Implement bank provider for ``pl_PL`` locale."""
 
-    bban_format = "#" * 26
+    bban_format = "#" * 24
     country_code = "PL"


Test patch:
diff --git a/tests/providers/test_bank.py b/tests/providers/test_bank.py
index b71666d8fe..76d05ee051 100644
--- a/tests/providers/test_bank.py
+++ b/tests/providers/test_bank.py
@@ -73,14 +73,14 @@ class TestPlPl:
 
     def test_bban(self, faker, num_samples):
         for _ in range(num_samples):
-            assert re.fullmatch(r"\d{26}", faker.bban())
+            assert re.fullmatch(r"\d{24}", faker.bban())
 
     def test_iban(self, faker, num_samples):
         for _ in range(num_samples):
             iban = faker.iban()
             assert is_valid_iban(iban)
             assert iban[:2] == PlPlBankProvider.country_code
-            assert re.fullmatch(r"\d{2}\d{26}", iban[2:])
+            assert re.fullmatch(r"\d{2}\d{24}", iban[2:])
 
 
 class TestEnGb:
Repository: joke2k/faker (Python)

Issue:
Bug in `mac_platform_token`
* Faker version: Latest
* OS: Any

`mac_platform_token` generates a MacOS platform token used in user agent strings. However, during https://github.com/joke2k/faker/commit/da1ae11a06a8f64bd4b0f7d1391d7661521e4caf#diff-7d7f34af58b0ae686b413e6ed3463229243aacfb0891fbc544cb951224c5af97L220, looks like it got missing underscore. Now, it generates `Macintosh; PPC Mac OS X 10 6_5` where as it should be `Macintosh; PPC Mac OS X 10_6_5`

### Expected behavior

Output of `mac_platform_token` should be `Macintosh; PPC Mac OS X 10_6_5`

### Actual behavior
`Macintosh; PPC Mac OS X 10 6_5`



Discussion:
Thank you for the report @iamkeyur ! Do you have time to submit a Pull Request?
Sure, I will do that.



Patch:
diff --git a/faker/providers/user_agent/__init__.py b/faker/providers/user_agent/__init__.py
index 2a4c8a7d66..40fe1830cc 100644
--- a/faker/providers/user_agent/__init__.py
+++ b/faker/providers/user_agent/__init__.py
@@ -192,7 +192,7 @@ def linux_platform_token(self):
 
     def mac_platform_token(self):
         """Generate a MacOS platform token used in user agent strings."""
-        return (f'Macintosh; {self.random_element(self.mac_processors)} Mac OS X 10 '
+        return (f'Macintosh; {self.random_element(self.mac_processors)} Mac OS X 10_'
                 f'{self.generator.random.randint(5, 12)}_{self.generator.random.randint(0, 9)}')
 
     def android_platform_token(self):


Test patch:
diff --git a/tests/providers/test_user_agent.py b/tests/providers/test_user_agent.py
index 0e8ab70ce6..cda2fccc3c 100644
--- a/tests/providers/test_user_agent.py
+++ b/tests/providers/test_user_agent.py
@@ -8,6 +8,7 @@ class TestUserAgentProvider:
     num_samples = 1000
     android_token_pattern = re.compile(r'Android (?P<android_version>\d+(?:\.\d){0,2})')
     ios_token_pattern = re.compile(r'^(?P<apple_device>.*?); CPU \1 OS (?P<ios_version>\d+(?:_\d){0,2}) like Mac OS X')
+    mac_token_pattern = re.compile(r'Macintosh; (?P<mac_processor>.*?) Mac OS X 10_([5-9]|1[0-2])_(\d)')
 
     def test_android_platform_token(self, faker, num_samples):
         for _ in range(num_samples):
@@ -19,3 +20,8 @@ def test_ios_platform_token(self, faker, num_samples):
             match = self.ios_token_pattern.fullmatch(faker.ios_platform_token())
             assert match.group('apple_device') in UaProvider.apple_devices
             assert match.group('ios_version').replace('_', '.') in UaProvider.ios_versions
+
+    def test_mac_platform_token(self, faker, num_samples):
+        for _ in range(num_samples):
+            match = self.mac_token_pattern.fullmatch(faker.mac_platform_token())
+            assert match.group('mac_processor') in UaProvider.mac_processors
Repository: HypothesisWorks/hypothesis (Python)

Issue:
Document npst.from_dtype as part of the public API
While it made sense to keep this as an internal function when we only accessed it via `npst.arrays`, the addition of the Pandas extra means it could be independently useful.

- [ ] Add docstring, name to `__all__`, etc.
- [ ] Raise InvalidArgument if it's passed an argument that is not an instance of `np.dtype`


Discussion:

Patch:
diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst
new file mode 100644
index 0000000000..926e5c8cbf
--- /dev/null
+++ b/hypothesis-python/RELEASE.rst
@@ -0,0 +1,6 @@
+RELEASE_TYPE: patch
+
+This patch documents the :func:`~hypothesis.extra.numpy.from_dtype` function,
+which infers a strategy for :class:`numpy:numpy.dtype`s.  This is used in
+:func:`~hypothesis.extra.numpy.arrays`, but can also be used directly when
+creating e.g. Pandas objects.
diff --git a/hypothesis-python/src/hypothesis/extra/numpy.py b/hypothesis-python/src/hypothesis/extra/numpy.py
index e7ea726da0..37c46db5ec 100644
--- a/hypothesis-python/src/hypothesis/extra/numpy.py
+++ b/hypothesis-python/src/hypothesis/extra/numpy.py
@@ -31,6 +31,7 @@
 from hypothesis.internal.compat import hrange, text_type
 from hypothesis.internal.coverage import check_function
 from hypothesis.internal.reflection import proxies
+from hypothesis.internal.validation import check_type
 
 if False:
     from typing import Any, Union, Sequence, Tuple  # noqa
@@ -42,6 +43,8 @@
 @st.defines_strategy_with_reusable_values
 def from_dtype(dtype):
     # type: (np.dtype) -> st.SearchStrategy[Any]
+    """Creates a strategy which can generate any value of the given dtype."""
+    check_type(np.dtype, dtype, 'dtype')
     # Compound datatypes, eg 'f4,f4,f4'
     if dtype.names is not None:
         # mapping np.void.type over a strategy is nonsense, so return now.


Test patch:
diff --git a/hypothesis-python/tests/numpy/test_argument_validation.py b/hypothesis-python/tests/numpy/test_argument_validation.py
index 599201eb9b..6a33f0c2ac 100644
--- a/hypothesis-python/tests/numpy/test_argument_validation.py
+++ b/hypothesis-python/tests/numpy/test_argument_validation.py
@@ -17,6 +17,7 @@
 
 from __future__ import division, print_function, absolute_import
 
+import numpy
 import pytest
 
 import hypothesis.strategies as st
@@ -53,6 +54,10 @@ def e(a, **kwargs):
         e(nps.unsigned_integer_dtypes, endianness=3),
         e(nps.unsigned_integer_dtypes, sizes=()),
         e(nps.unsigned_integer_dtypes, sizes=(3,)),
+        e(nps.from_dtype, dtype='float64'),
+        e(nps.from_dtype, dtype=float),
+        e(nps.from_dtype, dtype=numpy.int8),
+        e(nps.from_dtype, dtype=1),
     ]
 )
 def test_raise_invalid_argument(function, kwargs):
Repository: joke2k/faker (Python)

Issue:
Generating invalid cpf (brazillian ssn)
Faker is generating invalid checksum digits for cpf (brazillian ssn).

### Steps to reproduce

1. Create fake instance using localization "pt_BR"
1. Call fake.cpf()

### Expected behavior

It should generate a valid CPF.

### Actual behavior

It is generating a CPF with invalid checksum digits, in some cases.



Discussion:

Patch:
diff --git a/faker/providers/ssn/pt_BR/__init__.py b/faker/providers/ssn/pt_BR/__init__.py
index 7fcdcda15e..010a703041 100644
--- a/faker/providers/ssn/pt_BR/__init__.py
+++ b/faker/providers/ssn/pt_BR/__init__.py
@@ -5,6 +5,12 @@
 
 
 def checksum(digits):
+    """
+    Returns the checksum of CPF digits.
+    References to the algorithm:
+    https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo
+    https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm
+    """
     s = 0
     p = len(digits) + 1
     for i in range(0, len(digits)):
@@ -13,7 +19,7 @@ def checksum(digits):
 
     reminder = s % 11
     if reminder == 0 or reminder == 1:
-        return 1
+        return 0
     else:
         return 11 - reminder
 


Test patch:
diff --git a/tests/providers/test_ssn.py b/tests/providers/test_ssn.py
index db69201c33..abf33e6314 100644
--- a/tests/providers/test_ssn.py
+++ b/tests/providers/test_ssn.py
@@ -119,7 +119,7 @@ def setUp(self):
 
     def test_pt_BR_ssn_checksum(self):
         self.assertEqual(pt_checksum([8, 8, 2, 8, 2, 1, 6, 5, 2]), 2)
-        self.assertEqual(pt_checksum([8, 8, 2, 8, 2, 1, 6, 5, 2, 2]), 1)
+        self.assertEqual(pt_checksum([8, 8, 2, 8, 2, 1, 6, 5, 2, 2]), 0)
 
     def test_pt_BR_ssn(self):
         for _ in range(100):
Repository: iterative/dvc (Python)

Issue:
logger: still ignoring the context of the progress bar
version: `0.40.0+6408b5`

When trying to push to an SSH with the `ask_password` option set to `True`:
```
# [############                  ] 40% Collecting informationEnter a private key passphrase or a password for host 'localhost' port '22' user 'mroutis':
```

This behavior should be handle at: https://github.com/iterative/dvc/blob/6408b58b8daddc297467453bcd130c07b09cd46b/dvc/logger.py#L134-L140

It should be tested under `tests/unit/test_logger.py`


Discussion:

Patch:
diff --git a/dvc/logger.py b/dvc/logger.py
index 0f428e61dd..1c71a0e4f9 100644
--- a/dvc/logger.py
+++ b/dvc/logger.py
@@ -47,6 +47,9 @@ class ColorFormatter(logging.Formatter):
     )
 
     def format(self, record):
+        if self._is_visible(record):
+            self._progress_aware()
+
         if record.levelname == "INFO":
             return record.msg
 
@@ -75,6 +78,12 @@ def format(self, record):
             msg=record.msg,
         )
 
+    def _current_level(self):
+        return logging.getLogger("dvc").getEffectiveLevel()
+
+    def _is_visible(self, record):
+        return record.levelno >= self._current_level()
+
     def _description(self, message, exception):
         description = ""
 
@@ -117,7 +126,7 @@ def _parse_exc(self, exc_info):
 
         exception = ": ".join(exc_list)
 
-        if logging.getLogger("dvc").getEffectiveLevel() == logging.DEBUG:
+        if self._current_level() == logging.DEBUG:
             stack_trace = (
                 "\n" "{red}{line}{nc}\n" "{stack_trace}" "{red}{line}{nc}"
             ).format(


Test patch:
diff --git a/tests/unit/test_logger.py b/tests/unit/test_logger.py
index 4149d109a8..889fb4d0cc 100644
--- a/tests/unit/test_logger.py
+++ b/tests/unit/test_logger.py
@@ -149,3 +149,33 @@ def test_nested_exceptions(self, caplog):
             )
 
             assert expected == formatter.format(caplog.records[0])
+
+    def test_progress_awareness(self, mock, capsys, caplog):
+        from dvc.progress import progress
+
+        with mock.patch("sys.stdout.isatty", return_value=True):
+            progress.set_n_total(100)
+            progress.update_target("progress", 1, 10)
+
+            # logging an invisible message should not break
+            # the progress bar output
+            with caplog.at_level(logging.INFO, logger="dvc"):
+                debug_record = logging.LogRecord(
+                    name="dvc",
+                    level=logging.DEBUG,
+                    pathname=__name__,
+                    lineno=1,
+                    msg="debug",
+                    args=(),
+                    exc_info=None,
+                )
+
+                formatter.format(debug_record)
+                captured = capsys.readouterr()
+                assert "\n" not in captured.out
+
+            # just when the message is actually visible
+            with caplog.at_level(logging.INFO, logger="dvc"):
+                logger.info("some info")
+                captured = capsys.readouterr()
+                assert "\n" in captured.out
Repository: ipython/ipython (Python)

Issue:
%%writefile can't handle white space in file path/filename
It is as the title suggests. In ipython, I have tried

`%%writefile  "test out.txt"`
`%%writefile  'test out.txt'`
`%%writefile  test out.txt`
`%%writefile  test\ out.txt`

and none gives me the expected behavior. The first one leads to creating a file literally named "test out.txt"  (yes, with quotes). The third one just leads to 

>  unrecognized arguments: out.txt

Is this a bug or am I just missing something obvious? Using IPython 6.5.0 with Python 3.6.5.


Discussion:
This is probably a bug, it shouldn't be too hard to fix, it will just take some time to figure out exactly how to parse the line. 

Here is where the [code of writefile is](https://github.com/ipython/ipython/blob/032cc8c92986762204a801eed36c57822b4a6345/IPython/core/magics/osm.py#L763-L791).

THe parsing is based on argparse.
I've written a simple workaround in #11330. 

All 4 cases work above now.
Yes



Patch:
diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py
index 7e87b973ad2..b3fda954f4b 100644
--- a/IPython/core/magics/osm.py
+++ b/IPython/core/magics/osm.py
@@ -777,8 +777,11 @@ def writefile(self, line, cell):
         The file will be overwritten unless the -a (--append) flag is specified.
         """
         args = magic_arguments.parse_argstring(self.writefile, line)
-        filename = os.path.expanduser(args.filename)
-
+        if re.match(r'[\'*\']|["*"]', args.filename):
+            filename = os.path.expanduser(args.filename[1:-1])
+        else:
+            filename = os.path.expanduser(args.filename)
+            
         if os.path.exists(filename):
             if args.append:
                 print("Appending to %s" % filename)


Test patch:
diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py
index dfeabca1f21..f975076ca1f 100644
--- a/IPython/core/tests/test_magic.py
+++ b/IPython/core/tests/test_magic.py
@@ -27,7 +27,8 @@
 from IPython.testing import decorators as dec
 from IPython.testing import tools as tt
 from IPython.utils.io import capture_output
-from IPython.utils.tempdir import TemporaryDirectory
+from IPython.utils.tempdir import (TemporaryDirectory,
+                                    TemporaryWorkingDirectory)
 from IPython.utils.process import find_cmd
 
 
@@ -797,7 +798,20 @@ def test_file_amend():
             s = f.read()
         nt.assert_in('line1\n', s)
         nt.assert_in('line3\n', s)
-        
+
+def test_file_spaces():
+    """%%file with spaces in filename"""
+    ip = get_ipython()
+    with TemporaryWorkingDirectory() as td:
+        fname = "file name"
+        ip.run_cell_magic("file", '"%s"'%fname, u'\n'.join([
+            'line1',
+            'line2',
+        ]))
+        with open(fname) as f:
+            s = f.read()
+        nt.assert_in('line1\n', s)
+        nt.assert_in('line2', s)
     
 def test_script_config():
     ip = get_ipython()