Repository: awslabs/gluonts

Issue:
Cannot Run examples in a MacOs and Python3.7
## Description
Hi,

~~I just installed using `pip` command showed in the documentation and, using one of the examples in a jupyter notebook, when I do an import:
`from gluonts.dataset.repository.datasets import get_dataset, dataset_recipes`
I got an error.~~
I found that the issue is the new version of pydantic. The new version 1.5 (And quite possible the 1.4 as well) causes the issue below.

## To Reproduce
To reproduce, just try to import:
```python
from gluonts.dataset.repository.datasets import get_dataset, dataset_recipes
```
Also, the jupyter notebook from https://gluon-ts.mxnet.io/examples/basic_forecasting_tutorial/tutorial.html causes the same error.

## Error message or code output
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-f1a9ed5569ee> in <module>
----> 1 from gluonts.dataset.repository.datasets import get_dataset, dataset_recipes
      2 from gluonts.dataset.util import to_pandas

/usr/local/lib/python3.7/site-packages/gluonts/dataset/repository/datasets.py in <module>
     17 from pathlib import Path
     18 
---> 19 from gluonts.dataset.artificial import ConstantDataset
     20 from gluonts.dataset.common import TrainDatasets, load_datasets
     21 from gluonts.dataset.repository._artificial import generate_artificial_dataset

/usr/local/lib/python3.7/site-packages/gluonts/dataset/artificial/__init__.py in <module>
     13 
     14 # Relative imports
---> 15 from ._base import (
     16     ArtificialDataset,
     17     ConstantDataset,

/usr/local/lib/python3.7/site-packages/gluonts/dataset/artificial/_base.py in <module>
     22 
     23 # First-party imports
---> 24 from gluonts.dataset.artificial.recipe import (
     25     BinaryHolidays,
     26     BinaryMarkovChain,

/usr/local/lib/python3.7/site-packages/gluonts/dataset/artificial/recipe.py in <module>
     34 # First-party imports
     35 from gluonts.core.component import validated
---> 36 from gluonts.dataset.common import DataEntry
     37 
     38 ValueOrCallable = Union[Any, Callable]

/usr/local/lib/python3.7/site-packages/gluonts/dataset/common.py in <module>
     40 from gluonts.core.exception import GluonTSDataError
     41 from gluonts.dataset import jsonl, util
---> 42 from gluonts.dataset.stat import (
     43     DatasetStatistics,
     44     calculate_dataset_statistics,

/usr/local/lib/python3.7/site-packages/gluonts/dataset/stat.py in <module>
     27 
     28 
---> 29 class ScaleHistogram:
     30     """
     31     Scale histogram of a timeseries dataset

/usr/local/lib/python3.7/site-packages/gluonts/dataset/stat.py in ScaleHistogram()
     49         bin_counts: Optional[dict] = None,
     50         empty_target_count: int = 0,
---> 51     ) -> None:
     52         self._base = base
     53         self.bin_counts = defaultdict(

/usr/local/lib/python3.7/site-packages/gluonts/core/component.py in validator(init)
    396                 model_name=f"{init_clsnme}Model",
    397                 __config__=BaseValidatedInitializerModel.Config,
--> 398                 **init_fields,
    399             )
    400         else:

/usr/local/lib/python3.7/site-packages/pydantic/main.cpython-37m-darwin.so in pydantic.main.create_model()

TypeError: create_model() takes exactly 1 positional argument (0 given)
```

## Environment
python - Python 3.7.6
pip - 20.0.2
gluon-ts - the official 0.4.2 and also the master branch
MacOs - Mojave 10.14.6
Jupyter notebook - 6.0.3
```
>>> import pydantic; print(pydantic.VERSION)
1.5
```


Discussion:
Pydantic 1.4 seems to be fine, but i encountered the same error with version 1.5.
@joaoTray would constraining the pydantic requirement to <=1.4 be a solution for you? Or do you strictly require 1.5?
Hi,

The 1.4 will be fine.
I will use this version for now.

Many thanks,
Joao

On Sun, 19 Apr 2020, 08:44 Lorenzo Stella, <notifications@github.com> wrote:

> @joaoTray <https://github.com/joaoTray> would constraining the pydantic
> requirement to <=1.4 be a solution for you? Or do you strictly require 1.5?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/awslabs/gluon-ts/issues/767#issuecomment-616068434>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AMR2JKT2HID44DMNIJA74XTRNKTXRANCNFSM4MLQO5EQ>
> .
>


Resolving patch:
diff --git a/src/gluonts/core/component.py b/src/gluonts/core/component.py
--- a/src/gluonts/core/component.py
+++ b/src/gluonts/core/component.py
@@ -393,15 +393,13 @@ def validator(init):
 
         if base_model is None:
             PydanticModel = create_model(
-                model_name=f"{init_clsnme}Model",
+                f"{init_clsnme}Model",
                 __config__=BaseValidatedInitializerModel.Config,
                 **init_fields,
             )
         else:
             PydanticModel = create_model(
-                model_name=f"{init_clsnme}Model",
-                __base__=base_model,
-                **init_fields,
+                f"{init_clsnme}Model", __base__=base_model, **init_fields
             )
 
         def validated_repr(self) -> str:


Test patch: