Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pylint and pickling issue #1743

Merged
merged 19 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions .azure-pipelines/azure-pipelines-external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ jobs:

if [ "$(pymc3.version)" = "github" ]; then
# Pip installation is failing for some reason. This is the same thing
git clone https://github.com/pymc-devs/pymc3
cd pymc3
git checkout v4
cd ..
pip install $PWD/pymc3
# python -m pip --no-cache-dir --log log.txt install git+https://github.com/pymc-devs/pymc3
# cat log.txt
# git clone https://github.com/pymc-devs/pymc3 cd pymc3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can delete the "manual" install method now.

# git checkout main
# cd ..
# pip install $PWD/pymc3
python -m pip --no-cache-dir --log log.txt install git+https://github.com/pymc-devs/pymc3
cat log.txt
else
python -m pip --no-cache-dir install pymc3
fi
Expand Down Expand Up @@ -132,25 +131,26 @@ jobs:
absolufy-imports $(find arviz -name '*.py') --never
displayName: 'Use relative imports'

- script: |
python -m mypy .
displayName: 'mypy'

- script: |
python -m typing_copilot.cli tighten --error-if-can-tighten
displayName: 'typing_copilot'

- script: |
python -m typing_copilot.cli tighten
condition: failed()
displayName: 'update mypy.ini with typing_copilot'

- task: PublishBuildArtifacts@1
condition: failed()
inputs:
pathtoPublish: 'mypy.ini'
artifactName: 'mypy.ini'
displayName: 'Upload updated mypy.ini'
# Disable temporarily until we find a fix
# - script: |
# python -m mypy .
# displayName: 'mypy'
#
# - script: |
# python -m typing_copilot.cli tighten --error-if-can-tighten
# displayName: 'typing_copilot'
#
# - script: |
# python -m typing_copilot.cli tighten
# condition: failed()
# displayName: 'update mypy.ini with typing_copilot'
#
# - task: PublishBuildArtifacts@1
# condition: failed()
# inputs:
# pathtoPublish: 'mypy.ini'
# artifactName: 'mypy.ini'
# displayName: 'Upload updated mypy.ini'

- script: |
pytest arviz/tests/helpers.py
Expand Down
8 changes: 6 additions & 2 deletions arviz/data/inference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def groups(self) -> List[str]:
class InferenceDataValuesView(ValuesView[xr.Dataset]):
"""ValuesView implementation for InferenceData, to allow it to implement Mapping."""

def __init__(self, parent: "InferenceData") -> None:
def __init__(
self, parent: "InferenceData"
) -> None: # pylint: disable=super-init-not-called
"""Create a new InferenceDataValuesView from an InferenceData object."""
self.parent = parent

Expand Down Expand Up @@ -275,7 +277,9 @@ def values(self) -> "InferenceData.InferenceDataValuesView":
class InferenceDataItemsView(ItemsView[str, xr.Dataset]):
"""ItemsView implementation for InferenceData, to allow it to implement Mapping."""

def __init__(self, parent: "InferenceData") -> None:
def __init__(
self, parent: "InferenceData"
) -> None: # pylint: disable=super-init-not-called
"""Create a new InferenceDataItemsView from an InferenceData object."""
self.parent = parent

Expand Down
4 changes: 3 additions & 1 deletion arviz/data/io_pyro.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def arbitrary_element(dct):

observations = {}
if self.model is not None:
trace = pyro.poutine.trace(self.model).get_trace(*self._args, **self._kwargs)
trace = pyro.poutine.trace(self.model).get_trace( # pylint: disable=not-callable
*self._args, **self._kwargs
)
observations = {
name: site["value"].cpu()
for name, site in trace.nodes.items()
Expand Down
8 changes: 4 additions & 4 deletions arviz/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import importlib
import logging
import os
import pickle
import sys
from typing import Any, Dict, List, Optional, Tuple, Union

import cloudpickle
import numpy as np
import pytest
from _pytest.outcomes import Skipped
Expand Down Expand Up @@ -591,13 +591,13 @@ def load_cached_models(eight_schools_data, draws, chains, libs=None):
with gzip.open(path, "wb") as buff:
try:
_log.info("Generating and caching %s", fname)
pickle.dump(func(eight_schools_data, draws, chains), buff)
cloudpickle.dump(func(eight_schools_data, draws, chains), buff)
except AttributeError as err:
raise AttributeError(f"Failed chaching {library_name}") from err
raise AttributeError(f"Failed caching {library_name}") from err

with gzip.open(path, "rb") as buff:
_log.info("Loading %s from cache", fname)
models[library.__name__] = pickle.load(buff)
models[library.__name__] = cloudpickle.load(buff)

return models

Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pytest-cov
black ; python_version >= '3.6'
typing_copilot ; python_version >= '3.7'
mypy<0.800
cloudpickle