Skip to content

Commit

Permalink
Add support for python 3.11
Browse files Browse the repository at this point in the history
- Using now `pandas.testing` instead of `pandas.utils.testing` to avoid deprecated issues.

- Updated arrays comparison with numpy's
  `np.testing.assert_array_almost_equal`.

- Inference tests updated with new `pandas.RangeIndex` to avoid types
  mismatches on Windows OS.
  • Loading branch information
williamjamir authored and WillianFuks committed Nov 21, 2023
1 parent edc2840 commit 8429e66
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: '3.10'
python-version: '3.11'

- name: Install dependencies
run: |
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/run-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [3.7, 3.8, 3.9, '3.10']
python: [3.7, 3.8, 3.9, '3.10', '3.11']
exclude:
- os: macos-latest
python: 3.7
- os: macos-latest
python: 3.8
- os: macos-latest
python: 3.9
- os: macos-latest
python: '3.10'
- os: windows-latest
python: 3.7
- os: windows-latest
python: 3.8
- os: windows-latest
python: 3.9
- os: windows-latest
python: '3.10'
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -47,20 +51,20 @@ jobs:
TOX_SKIP_ENV: coverage,GHA-coverage

- name: Lint
if: ${{ matrix.python == '3.10' && runner.os == 'Linux'}}
if: ${{ matrix.python == '3.11' && runner.os == 'Linux'}}
run: tox -e lint

- name: isort
if: ${{ matrix.python == '3.10' && runner.os == 'Linux'}}
if: ${{ matrix.python == '3.11' && runner.os == 'Linux'}}
run: tox -e isort-check


- name: Build Coverage
if: ${{ matrix.python == '3.10' && runner.os == 'Linux'}}
if: ${{ matrix.python == '3.11' && runner.os == 'Linux'}}
run: tox -e GHA-coverage

- name: Upload Coveralls
if: ${{ matrix.python == '3.10' && runner.os == 'Linux'}}
if: ${{ matrix.python == '3.11' && runner.os == 'Linux'}}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Please refer to this medium [post](https://towardsdatascience.com/implementing-c

## Requirements

- python{3.7, 3.8, 3.9, 3.10}
- python{3.7, 3.8, 3.9, 3.10, 3.11}
- matplotlib
- jinja2
- tensorflow>=2.10.0
Expand Down
2 changes: 1 addition & 1 deletion causalimpact/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.


__version__ = '0.0.13'
__version__ = '0.0.14'
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Scientific/Engineering',
],
project_urls={
'Source': 'https://github.com/WillianFuks/tfcausalimpact'
},
python_requires='>=3, <3.11',
python_requires='>=3, <3.12',
test_suite='tests'
)
5 changes: 4 additions & 1 deletion tests/test_inferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ def stddev(self):
niter=niter
)

expected_index = np.arange(6)
# by forcing the expected_index to be of type RangeIndex we avoid mismatching
# types on Windows OS.
expected_index = pd.RangeIndex(start=0, stop=6, step=1)

# test complete_preds_means
expec_complete_preds_means = pd.DataFrame(
data=np.array([7, 7, 7, 16, 16, 16]),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import tensorflow as tf
import tensorflow_probability as tfp
from numpy.testing import assert_array_equal
from pandas.util.testing import assert_frame_equal
from pandas.testing import assert_frame_equal

from causalimpact import CausalImpact
from causalimpact.misc import standardize
Expand Down
10 changes: 5 additions & 5 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def test_basic_standardize():
data = pd.DataFrame(data)
result, (mu, sig) = standardize(data)

pd.util.testing.assert_almost_equal(
np.testing.assert_array_almost_equal(
np.zeros(data.shape[1]),
result.mean().values
)

pd.util.testing.assert_almost_equal(
np.testing.assert_array_almost_equal(
np.ones(data.shape[1]),
result.std(ddof=0).values
)
Expand All @@ -48,12 +48,12 @@ def test_standardize_with_integer_column_names():
data = pd.DataFrame(data)
result, (mu, sig) = standardize(data)

pd.util.testing.assert_almost_equal(
np.testing.assert_array_almost_equal(
np.zeros(data.shape[1]),
result.mean().values
)

pd.util.testing.assert_almost_equal(
np.testing.assert_array_almost_equal(
np.ones(data.shape[1]),
result.std(ddof=0).values
)
Expand All @@ -64,7 +64,7 @@ def test_standardize_w_various_distinct_inputs():
test_data = [pd.DataFrame(data, dtype="float") for data in test_data]
for data in test_data:
result, (mu, sig) = standardize(data)
pd.util.testing.assert_frame_equal(unstandardize(result, (mu, sig)), data)
pd.testing.assert_frame_equal(unstandardize(result, (mu, sig)), data)


def test_standardize_raises_single_input():
Expand Down
7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[tox]
envlist =
py{37, 38, 39, 310}-{linux,macos,windows}
py{37, 38, 39, 310, 311}-{linux,macos,windows}
gh-actions-coveralls

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310, lint, isort-check, coverage
3.10: py310
3.11: py311, lint, isort-check, coverage

[gh-actions:env]
PLATFORM =
Expand Down Expand Up @@ -42,7 +43,7 @@ commands =

[testenv:lint]
basepython =
python3.10
python3.11
deps =
flake8
commands =
Expand Down

0 comments on commit 8429e66

Please sign in to comment.