internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mlcommons/GaNDLF

Issue:
[FEATURE] add the nadam optimizer
### Is your feature request related to a problem? Please describe.
The nadam optimizer incorporates nestrov momentum into the Adam optimizer, thus providing potentially better solutions: https://openreview.net/forum?id=OM0jvwB8jIp57ZJjtNEZ 

### Describe the solution you'd like
PyTorch has this [[ref](https://pytorch.org/docs/stable/generated/torch.optim.NAdam.html)], and it would be good to expose the api through the configuration definition. 

### Describe alternatives you've considered
N. A. 

### Additional context
N. A. 



Discussion:

Resolving patch:
diff --git a/GANDLF/metrics/segmentation.py b/GANDLF/metrics/segmentation.py
--- a/GANDLF/metrics/segmentation.py
+++ b/GANDLF/metrics/segmentation.py
@@ -272,8 +272,9 @@ def get_sensitivity_and_specificity(result_array, target_array):
     if per_label:
         return torch.tensor(sensitivity_per_label), torch.tensor(specificity_per_label)
     else:
-        return torch.tensor(sensitivity / avg_counter), torch.tensor(
-            specificity / avg_counter
+        return (
+            torch.tensor(sensitivity / avg_counter),
+            torch.tensor(specificity / avg_counter),
         )
 
 
diff --git a/GANDLF/optimizers/__init__.py b/GANDLF/optimizers/__init__.py
--- a/GANDLF/optimizers/__init__.py
+++ b/GANDLF/optimizers/__init__.py
@@ -10,6 +10,7 @@
     adagrad,
     rmsprop,
     radam,
+    nadam,
 )
 
 from .wrap_monai import novograd_wrapper
@@ -27,6 +28,7 @@
     "rmsprop": rmsprop,
     "radam": radam,
     "novograd": novograd_wrapper,
+    "nadam": nadam,
 }
 
 
diff --git a/GANDLF/optimizers/wrap_torch.py b/GANDLF/optimizers/wrap_torch.py
--- a/GANDLF/optimizers/wrap_torch.py
+++ b/GANDLF/optimizers/wrap_torch.py
@@ -10,6 +10,7 @@
     Adagrad,
     RMSprop,
     RAdam,
+    NAdam,
 )
 
 
@@ -245,3 +246,24 @@ def radam(parameters):
         weight_decay=parameters["optimizer"].get("weight_decay", 3e-05),
         foreach=parameters["optimizer"].get("foreach", None),
     )
+
+
+def nadam(parameters):
+    """
+    Creates a NAdam optimizer from the PyTorch `torch.optim` module using the input parameters.
+
+    Args:
+        parameters (dict): A dictionary containing the input parameters for the optimizer.
+
+    Returns:
+        optimizer (torch.optim.NAdam): A NAdam optimizer.
+    """
+    # Create the optimizer using the input parameters
+    return NAdam(
+        parameters["model_parameters"],
+        lr=parameters.get("learning_rate"),
+        betas=parameters["optimizer"].get("betas", (0.9, 0.999)),
+        eps=parameters["optimizer"].get("eps", 1e-8),
+        weight_decay=parameters["optimizer"].get("weight_decay", 3e-05),
+        foreach=parameters["optimizer"].get("foreach", None),
+    )


Test patch:
Repository: MAKENTNU/web

Issue:
Fix delete permissions for course registration



Discussion:

Resolving patch:
diff --git a/make_queue/views/admin/course.py b/make_queue/views/admin/course.py
--- a/make_queue/views/admin/course.py
+++ b/make_queue/views/admin/course.py
@@ -58,7 +58,7 @@ def get_success_url(self):
 class DeleteRegistrationView(PermissionRequiredMixin, DeleteView):
     model = Printer3DCourse
     permission_required = (
-        "make_queue.delete_printer3d_course",
+        "make_queue.delete_printer3dcourse",
     )
 
     def get_success_url(self):


Test patch:
Repository: pydantic/pydantic

Issue:
Missing HISTORY.rst
pydantic installs fine from pip but via a dependency in setup.py it fails with a missing HISTORY.rst due to your long_description in setup.py. Basically, you need a MANIFEST.in that includes that file.

```
Processing pydantic-0.6.2.tar.gz
Writing /var/folders/4j/00jv8sg138n61hsj6ppf60pm0000gn/T/easy_install-o7rp3h7o/pydantic-0.6.2/setup.cfg
Running pydantic-0.6.2/setup.py -q bdist_egg --dist-dir /var/folders/4j/00jv8sg138n61hsj6ppf60pm0000gn/T/easy_install-o7rp3h7o/pydantic-0.6.2/egg-dist-tmp-7bd8a1a8
error: [Errno 2] No such file or directory: '/private/var/folders/4j/00jv8sg138n61hsj6ppf60pm0000gn/T/easy_install-o7rp3h7o/pydantic-0.6.2/HISTORY.rst'
```


Discussion:
No need for MANIFEST.in, I believe manifest is depricated. 

It can be added to `setup.py`.
or even better just catch the error so those two files don't need to be included in the 99% of cases where the wheel is used.

Resolving patch:
diff --git a/pydantic/version.py b/pydantic/version.py
--- a/pydantic/version.py
+++ b/pydantic/version.py
@@ -2,4 +2,4 @@
 
 __all__ = ['VERSION']
 
-VERSION = StrictVersion('0.6.2')
+VERSION = StrictVersion('0.6.3')
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -2,12 +2,15 @@
 from pathlib import Path
 from setuptools import setup
 
+description = 'Data validation and settings management using python 3.6 type hinting'
 THIS_DIR = Path(__file__).resolve().parent
-long_description = (
-    THIS_DIR.joinpath('README.rst').read_text() +
-    '\n\n' +
-    THIS_DIR.joinpath('HISTORY.rst').read_text()
-)
+try:
+    long_description = '\n\n'.join([
+        THIS_DIR.joinpath('README.rst').read_text(),
+        THIS_DIR.joinpath('HISTORY.rst').read_text()
+    ])
+except FileNotFoundError:
+    long_description = description + '.\n\nSee https://pydantic-docs.helpmanual.io/ for documentation.'
 
 # avoid loading the package before requirements are installed:
 version = SourceFileLoader('version', 'pydantic/version.py').load_module()
@@ -15,7 +18,7 @@
 setup(
     name='pydantic',
     version=str(version.VERSION),
-    description='Data validation and settings management using python 3.6 type hinting',
+    description=description,
     long_description=long_description,
     classifiers=[
         'Development Status :: 4 - Beta',


Test patch:
Repository: pydantic/pydantic

Issue:
validator config error message is wrong
> Validators defined with incorrect fields: xxx (use check_fields=**True -> False** if you're inheriting from the model and intended this)


Discussion:

Resolving patch:
diff --git a/pydantic/main.py b/pydantic/main.py
--- a/pydantic/main.py
+++ b/pydantic/main.py
@@ -68,7 +68,7 @@ def check_for_unused(self):
         if unused_validators:
             fn = ', '.join(unused_validators)
             raise ConfigError(f"Validators defined with incorrect fields: {fn} "
-                              f"(use check_fields=True if you're inheriting from the model and intended this)")
+                              f"(use check_fields=False if you're inheriting from the model and intended this)")
 
 
 def _extract_validators(namespace):
diff --git a/pydantic/version.py b/pydantic/version.py
--- a/pydantic/version.py
+++ b/pydantic/version.py
@@ -2,4 +2,4 @@
 
 __all__ = ['VERSION']
 
-VERSION = StrictVersion('0.9.1')
+VERSION = StrictVersion('0.10.0')


Test patch:
diff --git a/tests/test_validators.py b/tests/test_validators.py
--- a/tests/test_validators.py
+++ b/tests/test_validators.py
@@ -328,7 +328,7 @@ class Model(BaseModel):
             def check_b(cls, v):
                 return v
     assert str(exc_info.value) == ("Validators defined with incorrect fields: check_b "
-                                   "(use check_fields=True if you're inheriting from the model and intended this)")
+                                   "(use check_fields=False if you're inheriting from the model and intended this)")
 
 
 def test_validate_parent():
Repository: pydantic/pydantic

Issue:
Date annotation is parsed inconsistently depending on input data.
#  Bug
I've tried  compare two date fields of pydantic model's instances.
But I got: `TypeError: can't compare datetime.datetime to datetime.date`

I figured out that its a bug when parsing field annotated as  date providing a datetime value.

Since one of my instances is created from data stored in persistence (which is  typed as "datetime") and the other instance is created from a CSV, the first is treated as a datetime and the other is treated as date.

For bugs/questions:
* OS: **Linux 64-bit **
* Python version `import sys; print(sys.version)`: **3.7.1 (default, Oct 22 2018, 10:41:28)  [GCC 8.2.1 20180831]**
* Pydantic version `import pydantic; print(pydantic.VERSION)`: **0.14**

```py
from datetime import date, datetime

from pydantic import BaseModel


class DateRange(BaseModel):
    dt_start: date
    dt_finish: date



data = DateRange(dt_start=datetime(2017,11, 7, 12, 14), dt_finish=datetime(2017,11, 26, 12, 14))
data_ = DateRange(dt_start='2017-01-01', dt_finish='2018-01-01')

print(type(data.dt_finish), type(data.dt_start))
print(type(data_.dt_finish), type(data_.dt_start))
...
```



Discussion:
thanks for reporting, I'll fix.

Resolving patch:
diff --git a/pydantic/datetime_parse.py b/pydantic/datetime_parse.py
--- a/pydantic/datetime_parse.py
+++ b/pydantic/datetime_parse.py
@@ -90,7 +90,10 @@ def parse_date(value: Union[date, StrIntFloat]) -> date:
     Raise ValueError if the input isn't well formatted.
     """
     if isinstance(value, date):
-        return value
+        if isinstance(value, datetime):
+            return value.date()
+        else:
+            return value
 
     number = get_numeric(value)
     if number is not None:
diff --git a/pydantic/version.py b/pydantic/version.py
--- a/pydantic/version.py
+++ b/pydantic/version.py
@@ -2,4 +2,4 @@
 
 __all__ = ['VERSION']
 
-VERSION = StrictVersion('0.14')
+VERSION = StrictVersion('0.15a1')


Test patch:
diff --git a/tests/test_datetime_parse.py b/tests/test_datetime_parse.py
--- a/tests/test_datetime_parse.py
+++ b/tests/test_datetime_parse.py
@@ -30,6 +30,7 @@ def create_tz(minutes):
         ('2012-04-23', date(2012, 4, 23)),
         ('2012-4-9', date(2012, 4, 9)),
         (date(2012, 4, 9), date(2012, 4, 9)),
+        (datetime(2012, 4, 9, 12, 15), date(2012, 4, 9)),
         # Invalid inputs
         ('x20120423', errors.DateError),
         ('2012-04-56', errors.DateError),
Repository: pydantic/pydantic

Issue:
Better PyObject import errors
Should include the error from the inner exception.



Discussion:
eg. errors like `ModuleNotFoundError`

Resolving patch:
diff --git a/pydantic/errors.py b/pydantic/errors.py
--- a/pydantic/errors.py
+++ b/pydantic/errors.py
@@ -109,7 +109,7 @@ class PathNotADirectoryError(_PathValueError):
 
 
 class PyObjectError(PydanticTypeError):
-    msg_template = 'ensure this value contains valid import path'
+    msg_template = 'ensure this value contains valid import path: {error_message}'
 
 
 class ListError(PydanticTypeError):
diff --git a/pydantic/types.py b/pydantic/types.py
--- a/pydantic/types.py
+++ b/pydantic/types.py
@@ -6,7 +6,7 @@
 from uuid import UUID
 
 from . import errors
-from .utils import change_exception, import_string, make_dsn, url_regex_generator, validate_email
+from .utils import import_string, make_dsn, url_regex_generator, validate_email
 from .validators import (
     anystr_length_validator,
     anystr_strip_whitespace,
@@ -221,8 +221,10 @@ def get_validators(cls):
     @classmethod
     def validate(cls, value):
         if value is not None:
-            with change_exception(errors.PyObjectError, ImportError):
+            try:
                 return import_string(value)
+            except ImportError as e:
+                raise errors.PyObjectError(error_message=str(e))
 
 
 class DSN(str):


Test patch:
diff --git a/tests/test_types.py b/tests/test_types.py
--- a/tests/test_types.py
+++ b/tests/test_types.py
@@ -111,10 +111,27 @@ class PyObjectModel(BaseModel):
 
     m = PyObjectModel()
     assert m.module == os.path
+
     with pytest.raises(ValidationError) as exc_info:
         PyObjectModel(module='foobar')
     assert exc_info.value.errors() == [
-        {'loc': ('module',), 'msg': 'ensure this value contains valid import path', 'type': 'type_error.pyobject'}
+        {
+            'loc': ('module',),
+            'msg': 'ensure this value contains valid import path: ' '"foobar" doesn\'t look like a module path',
+            'type': 'type_error.pyobject',
+            'ctx': {'error_message': '"foobar" doesn\'t look like a module path'},
+        }
+    ]
+
+    with pytest.raises(ValidationError) as exc_info:
+        PyObjectModel(module='os.missing')
+    assert exc_info.value.errors() == [
+        {
+            'loc': ('module',),
+            'msg': 'ensure this value contains valid import path: ' 'Module "os" does not define a "missing" attribute',
+            'type': 'type_error.pyobject',
+            'ctx': {'error_message': 'Module "os" does not define a "missing" attribute'},
+        }
     ]
Repository: pydantic/pydantic

Issue:
Include a PEP 561 marker file
# Feature Request

Hi,

The new version 0.19 has improved typing support which is great, but looks like it doesn't work out of the box. I had similar problems as described in #245 , but after adding the installation to MYPYPATH it works fine.

I think a PEP 561 marker file `py.typed` should be added so that tools like mypy can utilize the inline type information without any configuration. Reading mypy docs looks like there is a downside that `zip_safe` must be disabled for this.

https://mypy.readthedocs.io/en/latest/installed_packages.html
https://www.python.org/dev/peps/pep-0561/
Include a PEP 561 marker file
# Feature Request

Hi,

The new version 0.19 has improved typing support which is great, but looks like it doesn't work out of the box. I had similar problems as described in #245 , but after adding the installation to MYPYPATH it works fine.

I think a PEP 561 marker file `py.typed` should be added so that tools like mypy can utilize the inline type information without any configuration. Reading mypy docs looks like there is a downside that `zip_safe` must be disabled for this.

https://mypy.readthedocs.io/en/latest/installed_packages.html
https://www.python.org/dev/peps/pep-0561/


Discussion:
Very annoying about the `zip_safe` thing, but I guess no choice.

PR welcome.
Very annoying about the `zip_safe` thing, but I guess no choice.

PR welcome.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -68,8 +68,9 @@ def extra(self):
     url='https://github.com/samuelcolvin/pydantic',
     license='MIT',
     packages=['pydantic'],
+    package_data={'pydantic': ['py.typed']},
     python_requires='>=3.6',
-    zip_safe=True,
+    zip_safe=False,  # https://mypy.readthedocs.io/en/latest/installed_packages.html
     install_requires=[
         'dataclasses>=0.6;python_version<"3.7"'
     ],


Test patch:
Repository: pydantic/pydantic

Issue:
submodel validation doesn't check the model is of the correct type
https://github.com/samuelcolvin/pydantic/blob/7cd423aa3e763352b0d87c7fe1fce41f417807fe/pydantic/main.py#L410-L417

as of #389 I think any model will be permitted to a submodel field.


Discussion:

Resolving patch:
diff --git a/pydantic/main.py b/pydantic/main.py
--- a/pydantic/main.py
+++ b/pydantic/main.py
@@ -417,11 +417,11 @@ def __get_validators__(cls) -> 'CallableGenerator':
     def validate(cls: Type['Model'], value: Union['DictStrAny', 'Model']) -> 'Model':
         if isinstance(value, dict):
             return cls(**value)
-        elif isinstance(value, BaseModel):
+        elif isinstance(value, cls):
             return value.copy()
         else:
             with change_exception(DictError, TypeError, ValueError):
-                return cls(**dict(value))
+                return cls(**dict(value))  # type: ignore
 
     def _process_values(self, input_data: Any) -> 'DictStrAny':
         # (casting here is slow so use ignore)
diff --git a/pydantic/version.py b/pydantic/version.py
--- a/pydantic/version.py
+++ b/pydantic/version.py
@@ -2,4 +2,4 @@
 
 __all__ = ['VERSION']
 
-VERSION = StrictVersion('0.20.0')
+VERSION = StrictVersion('0.20.1')


Test patch:
diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py
--- a/tests/test_edge_cases.py
+++ b/tests/test_edge_cases.py
@@ -848,3 +848,22 @@ class Child(Mixin, Parent):
     assert Parent.__config__.extra is Extra.forbid
     assert Mixin.__config__.extra is Extra.ignore
     assert Child.__config__.extra is Extra.forbid
+
+
+def test_submodel_different_type():
+    class Foo(BaseModel):
+        a: int
+
+    class Bar(BaseModel):
+        b: int
+
+    class Spam(BaseModel):
+        c: Foo
+
+    assert Spam(c={'a': '123'}).dict() == {'c': {'a': 123}}
+    with pytest.raises(ValidationError):
+        Spam(c={'b': '123'})
+
+    assert Spam(c=Foo(a='123')).dict() == {'c': {'a': 123}}
+    with pytest.raises(ValidationError):
+        Spam(c=Bar(b='123'))
Repository: pydantic/pydantic

Issue:
`.dict(by_alias=True)` throws an exception when trying to call with extra keys
<!-- Questions, Feature Requests, and Bug Reports are all welcome -->
<!-- delete as applicable: -->
# Bug

* OS: Mac OS
* Python version: 
```
3.7.2 (default, Mar 19 2019, 17:39:18) 
[Clang 10.0.0 (clang-1000.11.45.5)]
```
* Pydantic version: 0.23

I'm trying to use extra columns for my model. And I expected `.dict(by_alias=True)` to return dict for my model with alias, but I received an exception. I think this is because `get_key` is using `self.fields` that doesn't include extra keys.
```py
from pydantic import Schema, Extra, BaseModel, BaseConfig


class ModelTest(BaseModel):
    a: str = Schema(None, alias='b')

    class Config(BaseConfig):
        extra = Extra.allow


if __name__ == '__main__':
        m = ModelTest(extra_column='extra')
        print(m.extra_column)  # extra
        print(m.dict())  # {'a': None, 'extra_column': 'extra'}
        print(m.dict(by_alias=True))  # error
```

```
Traceback (most recent call last):
  File "...", line 41, in ...
    print(m.dict(by_alias=True))  # error
  File ".../python3.7/site-packages/pydantic/main.py", line 282, in dict
    get_key(k): v for k, v in self._iter(by_alias=by_alias, skip_defaults=skip_defaults)
  File ".../python3.7/site-packages/pydantic/main.py", line 282, in <dictcomp>
    get_key(k): v for k, v in self._iter(by_alias=by_alias, skip_defaults=skip_defaults)
  File ".../python3.7/site-packages/pydantic/main.py", line 293, in <lambda>
    return lambda fields, key: fields[key].alias
KeyError: 'extra_column'
```


Discussion:
thanks for reporting, fix shouldn't be too hard. PR welcome or I'll fix in a week or so.

Resolving patch:
diff --git a/pydantic/main.py b/pydantic/main.py
--- a/pydantic/main.py
+++ b/pydantic/main.py
@@ -289,7 +289,7 @@ def dict(
 
     def _get_key_factory(self, by_alias: bool) -> Callable[..., str]:
         if by_alias:
-            return lambda fields, key: fields[key].alias
+            return lambda fields, key: fields[key].alias if key in fields else key
 
         return lambda _, key: key
 


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -3,7 +3,7 @@
 
 import pytest
 
-from pydantic import BaseModel, Extra, NoneBytes, NoneStr, Required, ValidationError, constr
+from pydantic import BaseModel, Extra, NoneBytes, NoneStr, Required, Schema, ValidationError, constr
 
 
 def test_success():
@@ -576,3 +576,15 @@ class MyModel(BaseModel):
     assert "json" in dir(m)
     assert "attribute_a" in dir(m)
     assert "attribute_b" in dir(m)
+
+
+def test_dict_with_extra_keys():
+    class MyModel(BaseModel):
+        a: str = Schema(None, alias='alias_a')
+
+        class Config:
+            extra = Extra.allow
+
+    m = MyModel(extra_key='extra')
+    assert m.dict() == {'a': None, 'extra_key': 'extra'}
+    assert m.dict(by_alias=True) == {'alias_a': None, 'extra_key': 'extra'}
Repository: pydantic/pydantic

Issue:
Behaviour of keep_untouched is unclear in docs
# Bug

* Python version `import sys; print(sys.version)`: 3.7.3
* Pydantic version `import pydantic; print(pydantic.VERSION)`: 0.32.2

The `keep_untouched` attribute on a model's Config affects the behaviour for properties' **values**, not their **type annotations**. This is unclear, and is also made particularly misleading by the wording of [this error message](https://github.com/samuelcolvin/pydantic/blob/master/pydantic/validators.py#L572):
```
RuntimeError: no validator found for {type_} see `keep_untouched` or `arbitrary_types_allowed` in Config
```
These should both be improved, and perhaps the config attribute's name should also be changed?


Discussion:
I agree the name isn't that clear, but I think it's too late to change.

Happy to accept a PR to update the documentation, or even update the error message if we can do it asap.

Resolving patch:
diff --git a/pydantic/validators.py b/pydantic/validators.py
--- a/pydantic/validators.py
+++ b/pydantic/validators.py
@@ -568,9 +568,7 @@ def find_validators(  # noqa: C901 (ignore complexity)
     if config.arbitrary_types_allowed:
         yield make_arbitrary_type_validator(type_)
     else:
-        raise RuntimeError(
-            f'no validator found for {type_} see `keep_untouched` or `arbitrary_types_allowed` in Config'
-        )
+        raise RuntimeError(f'no validator found for {type_}, see `arbitrary_types_allowed` in Config')
 
 
 def _find_supertype(type_: AnyType) -> Optional[AnyType]:


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -951,7 +951,7 @@ def class_name(cls) -> str:
 
     assert str(e.value) == (
         "no validator found for <class 'tests.test_main.test_custom_types_fail_without_keep_untouched.<locals>."
-        "_ClassPropertyDescriptor'> see `keep_untouched` or `arbitrary_types_allowed` in Config"
+        "_ClassPropertyDescriptor'>, see `arbitrary_types_allowed` in Config"
     )
 
     class Model(BaseModel):