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

Add support for Python 3.12 #167

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 10 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,28 @@ jobs:
channel-priority: "strict"
envfile: ".github/environment-ci.yml"

- os: ubuntu-latest
python-version: "3.12"
channel-priority: "strict"
envfile: ".github/environment-ci.yml"

- os: macos-latest
python-version: "3.11"
python-version: "3.12"
channel-priority: "strict"
envfile: ".github/environment-ci.yml"

- os: windows-latest
python-version: "3.11"
python-version: "3.12"
channel-priority: "strict"
envfile: ".github/environment-ci.yml"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true

- name: Cache conda
uses: actions/cache@v3
uses: actions/cache@v4
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
Expand All @@ -72,7 +77,7 @@ jobs:
key: ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles( matrix.envfile ) }}

- name: Install Conda environment
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
channel-priority: "flexible"
envfile: ".github/environment-lint.yml"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache conda
uses: actions/cache@v3
uses: actions/cache@v4
env:
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles( matrix.envfile ) }}
- name: Install conda environmnent
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: false
python-version: ${{ matrix.python-version }}
Expand Down
20 changes: 7 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# pescador documentation build configuration file, created by
# sphinx-quickstart on Fri Apr 3 10:03:34 2015.
Expand Down Expand Up @@ -83,19 +82,14 @@
master_doc = 'index'

# General information about the project.
project = u'pescador'
authors = u'Pescador development team'
copyright = u'2016, {}'.format(authors)
project = 'pescador'
authors = 'Pescador development team'
copyright = f'2016, {authors}'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
import six

if six.PY3:
from unittest.mock import MagicMock as Mock
else:
from mock import Mock
from unittest.mock import MagicMock as Mock

MOCK_MODULES = ['numpy', 'scipy',
'joblib.parallel', 'joblib._parallel_backends', 'joblib',
Expand Down Expand Up @@ -261,7 +255,7 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'pescador.tex', u'pescador Documentation',
('index', 'pescador.tex', 'pescador Documentation',
authors),
]

Expand Down Expand Up @@ -291,7 +285,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pescador', u'pescador Documentation',
('index', 'pescador', 'pescador Documentation',
[authors], 1)
]

Expand All @@ -305,7 +299,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'pescador', u'pescador Documentation',
('index', 'pescador', 'pescador Documentation',
authors, 'pescador', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
matplotlib
numpydoc>=0.6
six
sphinx
sphinx-gallery
sphinx_rtd_theme
8 changes: 3 additions & 5 deletions examples/frameworks/keras_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
===============
A Keras Example
Expand All @@ -14,7 +13,6 @@
# Setup and Definitions
##############################################

from __future__ import print_function
import datetime
import keras
from keras.datasets import mnist
Expand Down Expand Up @@ -204,7 +202,7 @@ def additive_noise(stream, key='X', scale=1e-1):

model = build_model(input_shape)
try:
print("Start time: {}".format(datetime.datetime.now()))
print(f"Start time: {datetime.datetime.now()}")
model.fit_generator(
pescador.tuples(batches, 'X', 'y'),
steps_per_epoch=steps_per_epoch,
Expand All @@ -214,7 +212,7 @@ def additive_noise(stream, key='X', scale=1e-1):
except KeyboardInterrupt:
print("Stopping early")
finally:
print("Finished: {}".format(datetime.datetime.now()))
print(f"Finished: {datetime.datetime.now()}")
scores = model.evaluate(X_test, Y_test, verbose=0)
for val, name in zip(scores, model.metrics_names):
print('Test {}: {:0.4f}'.format(name, val))
print(f'Test {name}: {val:0.4f}')
1 change: 0 additions & 1 deletion examples/mux/chain_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! -*- coding: utf-8 -*-
"""
=====================================
Using ChainMux for repeatable streams
Expand Down
1 change: 0 additions & 1 deletion examples/mux/epoch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! -*- coding: utf-8 -*-
"""
Using cycle mode to create data epochs
======================================
Expand Down
1 change: 0 additions & 1 deletion examples/mux/mux_files_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
=================================
Muxing Multiple Datasets Together
Expand Down
2 changes: 0 additions & 2 deletions examples/mux/shuffle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! -*- coding: utf-8 -*-
"""
Hierarchical sampling with ShuffledMux
======================================
Expand Down Expand Up @@ -26,7 +25,6 @@
# Code source: Brian McFee
# License: BSD 3 Clause

from __future__ import print_function
import pescador

#####################
Expand Down
1 change: 0 additions & 1 deletion examples/zmq_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
==================
Parallel streaming
Expand Down
5 changes: 2 additions & 3 deletions pescador/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .exceptions import PescadorError


class Streamer(object):
class Streamer:
"""A wrapper class for recycling iterables and generator functions, i.e.
streamers.

Expand Down Expand Up @@ -259,8 +259,7 @@ def __call__(self, max_iter=None, cycle=False):
else:
gen = self.iterate(max_iter=max_iter)

for obj in gen:
yield obj
yield from gen

def __iter__(self):
"""Wrap the iterator interface"""
Expand Down
1 change: 0 additions & 1 deletion pescador/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""Exception classes for pescador"""


Expand Down
9 changes: 4 additions & 5 deletions pescador/mux.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""\
Defines the interface and several varieties of *mux*. A *mux* is
a `Streamer` which wraps N other `Streamer` objects, and at every step yields a
Expand Down Expand Up @@ -346,7 +345,7 @@ def __init__(
self.rate = rate
self.prune_empty_streams = prune_empty_streams

super(StochasticMux, self).__init__(streamers, random_state=random_state)
super().__init__(streamers, random_state=random_state)

if not self.n_streams:
raise PescadorError("Cannot mux an empty collection")
Expand Down Expand Up @@ -565,7 +564,7 @@ def __init__(self, streamers, weights=None, random_state=None):
If None, the random number generator is the RandomState instance
used by np.random.
"""
super(ShuffledMux, self).__init__(streamers, random_state=random_state)
super().__init__(streamers, random_state=random_state)

if not self.n_streams:
raise PescadorError("Cannot mux an empty collection")
Expand Down Expand Up @@ -711,7 +710,7 @@ def __init__(self, streamers, mode="exhaustive", random_state=None):
used by `np.random.`
"""
self.mode = mode
super(RoundRobinMux, self).__init__(streamers, random_state=random_state)
super().__init__(streamers, random_state=random_state)

if not self.n_streams:
raise PescadorError("Cannot mux an empty collection")
Expand Down Expand Up @@ -886,7 +885,7 @@ def __init__(self, streamers, mode="exhaustive", random_state=None):
# if inspect.isgeneratorfunction(streamers):
# streamers = core.Streamer(streamers)

super(ChainMux, self).__init__(streamers, random_state=random_state)
super().__init__(streamers, random_state=random_state)

if mode not in ["exhaustive", "cycle"]:
raise PescadorError(f"Invalid ChainMux mode '{mode}'")
Expand Down
3 changes: 1 addition & 2 deletions pescador/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""Deprecation utilities"""

import inspect
Expand All @@ -11,7 +10,7 @@
from .exceptions import PescadorError


class Deprecated(object):
class Deprecated:
"""A dummy class to catch usage of deprecated variable names"""

def __repr__(self):
Expand Down
1 change: 0 additions & 1 deletion pescador/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Version info"""

short_version = "3.0"
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12

[options]
packages = find:
Expand Down
4 changes: 1 addition & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
'''Test the streamer object for reusable iterators'''
from __future__ import print_function
import copy
import pytest

Expand Down Expand Up @@ -278,8 +277,7 @@ def test_decorator():

@pescador.streamable
def my_generator(n):
for i in range(n):
yield i
yield from range(n)

s = my_generator(5)
assert isinstance(s, pescador.Streamer)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_mux.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This makes '/' do in python2 what you expect in python3.
from __future__ import division

import pytest

Expand All @@ -17,8 +16,7 @@

def _cycle(values):
while True:
for v in values:
yield v
yield from values


def _choice(vals, seed=11111):
Expand Down