Skip to content

Commit

Permalink
Merge pull request #476 from StingraySoftware/fix_collections_import
Browse files Browse the repository at this point in the history
Fix deprecated use of Iterable
  • Loading branch information
matteobachetti authored Jun 16, 2020
2 parents 870f122 + e94db86 commit 7ed7615
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions stingray/covariancespectrum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

import collections
from collections.abc import Iterable

import numpy as np

Expand Down Expand Up @@ -419,7 +419,7 @@ def _calculate_std(self, lc):
"""Return std calculated for the possible types of `std`"""
if self.std is None:
std = np.mean(lc)**0.5
elif isinstance(self.std, collections.Iterable):
elif isinstance(self.std, Iterable):
std = np.mean(self.std) # Iterable of numbers
else: # Single float number
std = self.std
Expand Down
3 changes: 3 additions & 0 deletions stingray/deadtime/fad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from ..gti import cross_two_gtis, bin_intervals_from_gtis


__all__ = ["calculate_FAD_correction", "get_periodograms_from_FAD_results"]


def _get_fourier_intv(lc, start_ind, end_ind):
"""Calculate the Fourier transform of a light curve chunk.
Expand Down
8 changes: 4 additions & 4 deletions stingray/gti.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import logging
import warnings
import collections
from collections.abc import Iterable
import copy

from astropy.io import fits
Expand Down Expand Up @@ -251,7 +251,7 @@ def create_gti_mask(time, gtis, safe_interval=None, min_length=0,
gti_mask = np.zeros(len(gtis), dtype=bool)

if safe_interval is not None:
if not isinstance(safe_interval, collections.Iterable):
if not isinstance(safe_interval, Iterable):
safe_interval = np.array([safe_interval, safe_interval])
# These are the gtis that will be returned (filtered!). They are only
# modified by the safe intervals
Expand Down Expand Up @@ -334,7 +334,7 @@ def create_gti_mask_complete(time, gtis, safe_interval=0, min_length=0,

if safe_interval is None:
safe_interval = [0, 0]
elif not isinstance(safe_interval, collections.Iterable):
elif not isinstance(safe_interval, Iterable):
safe_interval = [safe_interval, safe_interval]

newgtis = np.zeros_like(gtis)
Expand Down Expand Up @@ -393,7 +393,7 @@ def create_gti_from_condition(time, condition,

idxs = contiguous_regions(condition)

if not isinstance(safe_interval, collections.Iterable):
if not isinstance(safe_interval, Iterable):
safe_interval = [safe_interval, safe_interval]

dt = assign_value_if_none(dt,
Expand Down
6 changes: 3 additions & 3 deletions stingray/io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


import collections
from collections.abc import Iterable
import logging
import math
import numpy as np
Expand Down Expand Up @@ -276,7 +276,7 @@ def ref_mjd(fits_file, hdu=1):
the reference MJD
"""

if isinstance(fits_file, collections.Iterable) and\
if isinstance(fits_file, Iterable) and\
not is_string(fits_file): # pragma: no cover
fits_file = fits_file[0]
logging.info("opening %s" % fits_file)
Expand Down Expand Up @@ -346,7 +346,7 @@ def split_numbers(number):
Second part of high precision number
"""

if isinstance(number, collections.Iterable):
if isinstance(number, Iterable):
mods = [math.modf(n) for n in number]
number_F = [f for f, _ in mods]
number_I = [i for _, i in mods]
Expand Down
4 changes: 2 additions & 2 deletions stingray/pulse/pulsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import numpy as np
import collections
from collections.abc import Iterable
import warnings
from scipy.optimize import minimize, basinhopping

Expand Down Expand Up @@ -243,7 +243,7 @@ def fold_events(times, *frequency_derivatives, **opts):
ref_time = _default_value_if_no_key(opts, "ref_time", 0)
expocorr = _default_value_if_no_key(opts, "expocorr", False)

if not isinstance(weights, collections.Iterable):
if not isinstance(weights, Iterable):
weights *= np.ones(len(times))

gtis = gtis - ref_time
Expand Down
10 changes: 5 additions & 5 deletions stingray/pulse/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import numpy as np
import collections
from collections.abc import Iterable
from .pulsar import profile_stat, fold_events, z_n, pulse_phase
from ..utils import jit, HAS_NUMBA
from ..utils import contiguous_regions
Expand Down Expand Up @@ -44,7 +44,7 @@ def _folding_search(stat_func, times, frequencies, segment_size=5000,
if use_times:
kwargs_copy = {}
for key in kwargs.keys():
if isinstance(kwargs[key], collections.Iterable) and \
if isinstance(kwargs[key], Iterable) and \
len(kwargs[key]) == len(times):

kwargs_copy[key] = kwargs[key][good]
Expand Down Expand Up @@ -133,7 +133,7 @@ def epoch_folding_search(times, frequencies, nbin=128, segment_size=5000,
stats : array-like
the epoch folding statistics corresponding to each frequency bin.
"""
if expocorr or not HAS_NUMBA or isinstance(weights, collections.Iterable):
if expocorr or not HAS_NUMBA or isinstance(weights, Iterable):
if expocorr and gti is None:
raise ValueError('To calculate exposure correction, you need to'
' specify the GTIs')
Expand Down Expand Up @@ -210,7 +210,7 @@ def z_n_search(times, frequencies, nharm=4, nbin=128, segment_size=5000,
the Z^2_n statistics corresponding to each frequency bin.
"""
phase = np.arange(0, 1, 1 / nbin)
if expocorr or not HAS_NUMBA or isinstance(weights, collections.Iterable):
if expocorr or not HAS_NUMBA or isinstance(weights, Iterable):
if expocorr and gti is None:
raise ValueError('To calculate exposure correction, you need to'
' specify the GTIs')
Expand Down Expand Up @@ -486,7 +486,7 @@ def phaseogram(times, f, nph=128, nt=32, ph0=0, mjdref=None, fdot=0, fddot=0,
allts = \
np.concatenate([times, times]).astype('float64')

if weights is not None and isinstance(weights, collections.Iterable):
if weights is not None and isinstance(weights, Iterable):
if len(weights) != len(times):
raise ValueError('The length of weights must match the length of '
'times')
Expand Down
4 changes: 2 additions & 2 deletions stingray/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import sys
import collections
from collections.abc import Iterable
import numbers
from six import string_types

Expand Down Expand Up @@ -440,7 +440,7 @@ def is_iterable(var):
is_iter : bool
Returns ``True`` if ``var`` is an ``Iterable``, ``False`` otherwise
"""
return isinstance(var, collections.Iterable)
return isinstance(var, Iterable)


def order_list_of_arrays(data, order):
Expand Down

0 comments on commit 7ed7615

Please sign in to comment.