diff --git a/pyrolite/geochem/alteration.py b/pyrolite/geochem/alteration.py index f6b6f922..e6795384 100644 --- a/pyrolite/geochem/alteration.py +++ b/pyrolite/geochem/alteration.py @@ -1,6 +1,7 @@ """ Functions for calcuating indexes of chemical alteration. """ + import pandas as pd from ..util.log import Handle diff --git a/pyrolite/geochem/ind.py b/pyrolite/geochem/ind.py index 29d4fdc6..6243d852 100644 --- a/pyrolite/geochem/ind.py +++ b/pyrolite/geochem/ind.py @@ -6,6 +6,7 @@ ------ * Incompatibility indexes for spider plot ordering. """ + import re import numpy as np @@ -254,9 +255,11 @@ def simple_oxides(cation, output="string"): # for 3.6+, could use f'{cation}{1}O{c//2}', f'{cation}{2}O{c}' oxides = [ - str(cation) + str(1) + "O" + str(c // 2) - if not c % 2 - else str(cation) + str(2) + "O" + str(c) + ( + str(cation) + str(1) + "O" + str(c // 2) + if not c % 2 + else str(cation) + str(2) + "O" + str(c) + ) for c in ions ] oxides = [pt.formula(ox) for ox in oxides] @@ -291,7 +294,7 @@ def get_cations(component: str, exclude=[], total_suffix="T"): exclude += ["O"] atms = pt.formula(component).atoms - cations = [el for el in atms.keys() if not el.__str__() in exclude] + cations = [el for el in atms.keys() if el.__str__() not in exclude] return cations @@ -398,7 +401,7 @@ def get_ionic_radii( variant=[], source="shannon", pauling=True, - **kwargs + **kwargs, ): """ Function to obtain ionic radii for a given ion and coordination [#ref_1]_ @@ -464,7 +467,7 @@ def get_ionic_radii( variant=variant, source=source, pauling=pauling, - **kwargs + **kwargs, ) for e in element ] diff --git a/pyrolite/geochem/norm.py b/pyrolite/geochem/norm.py index d2ea359e..adf898b4 100644 --- a/pyrolite/geochem/norm.py +++ b/pyrolite/geochem/norm.py @@ -1,6 +1,7 @@ """ Reference compostitions and compositional normalisation. """ + import json from pathlib import Path diff --git a/pyrolite/geochem/transform.py b/pyrolite/geochem/transform.py index bc88aac0..0443556f 100644 --- a/pyrolite/geochem/transform.py +++ b/pyrolite/geochem/transform.py @@ -2,6 +2,8 @@ Functions for converting, transforming and parameterizing geochemical data. """ +from collections import Counter + import numpy as np import pandas as pd import periodictable as pt @@ -12,13 +14,7 @@ from ..util.meta import update_docstring_references from ..util.text import remove_suffix, titlecase from ..util.types import iscollection -from .ind import ( - _common_elements, - _common_oxides, - get_cations, - get_ionic_radii, - simple_oxides, -) +from .ind import _common_elements, _common_oxides, get_cations, simple_oxides from .norm import Composition, get_reference_composition logger = Handle(__name__) @@ -102,7 +98,7 @@ def devolatilise( :class:`pandas.DataFrame` Transformed dataframe. """ - keep = [i for i in df.columns if not i in exclude] + keep = [i for i in df.columns if i not in exclude] if renorm: return renormalise(df.loc[:, keep]) else: @@ -141,7 +137,7 @@ def oxide_conversion(oxin, oxout, molecular=False): # Assertion of simple oxide assert (len(in_els) == len(out_els)) & (len(in_els) == 1) assert in_els == out_els # Need to be dealing with the same element! - except: + except AssertionError: raise ValueError("Incompatible compounds: {} --> {}".format(in_els, out_els)) # Moles of product vs. moles of reactant cation_coefficient = list(inatoms.values())[0] / list(outatoms.values())[0] @@ -342,7 +338,7 @@ def aggregate_element( for t in targetnames: if t not in _df: - _df[t] = 0. # avoid missing column errors + _df[t] = 0.0 # avoid missing column errors coeff = np.array(coeff) if coeff.ndim == 2: @@ -603,7 +599,7 @@ def lambda_lnREE( norm_df.loc[(norm_df <= 0.0).any(axis=1), :] = np.nan # remove zero or below norm_df.loc[:, ree] = np.log(norm_df.loc[:, ree]) - if not (sigmas is None): + if sigmas is not None: if isinstance(sigmas, pd.Series): # convert this to an array sigmas = sigmas[ree].values @@ -707,7 +703,7 @@ def convert_chemistry( # and speciated components #################################################################################### output_compositional = [ - i for i in to if i not in coupled_sets + noncomp + new_ratios + i for i in to if i not in (coupled_sets + noncomp + new_ratios) ] # check that these are all unique components assert len(set(output_compositional)) == len( @@ -753,6 +749,16 @@ def convert_chemistry( **kwargs, ) + # TODO: warning for duplication should also be crossed over into speciated components above.. + _duplicated_cations = [ + str(k) + for k, v in Counter( # get the first cation in each component, and count duplicates + [get_cations(t, total_suffix=total_suffix)[0] for t in output_compositional] + ).items() + if v > 1 + ] + if _duplicated_cations: + logger.warning("Cations duplicated in compositional components: {}. The output retains this duplication!".format(','.join(_duplicated_cations))) # Aggregate the singular compositional items, then get new columns for item in output_compositional: df = aggregate_element(df, to=item, logdata=logdata, molecular=molecular) @@ -788,3 +794,5 @@ def convert_chemistry( else: logger.debug("Recalculation Done. Data not renormalised.") return df.loc[:, output_columns] + logger.debug("Recalculation Done. Data not renormalised.") + return df.loc[:, output_columns] diff --git a/pyrolite/mineral/lattice.py b/pyrolite/mineral/lattice.py index 5693823a..3850ab5c 100644 --- a/pyrolite/mineral/lattice.py +++ b/pyrolite/mineral/lattice.py @@ -27,6 +27,7 @@ doi: {hazen1979} """ + import numpy as np from ..util.log import Handle diff --git a/pyrolite/mineral/mindb.py b/pyrolite/mineral/mindb.py index 32bfe35c..16387c4b 100644 --- a/pyrolite/mineral/mindb.py +++ b/pyrolite/mineral/mindb.py @@ -6,6 +6,7 @@ Accessing and modifying the database across multiple with multiple threads/processes *could* result in database corruption (e.g. through repeated truncation etc). """ + import functools from pathlib import Path diff --git a/pyrolite/mineral/normative.py b/pyrolite/mineral/normative.py index 6a82317e..04dd4062 100644 --- a/pyrolite/mineral/normative.py +++ b/pyrolite/mineral/normative.py @@ -7,6 +7,7 @@ from ..comp.codata import close, renormalise from ..geochem.transform import convert_chemistry, to_molecular +from ..util.classification import TAS from ..util.log import Handle from ..util.pd import to_frame from ..util.units import scale @@ -201,8 +202,6 @@ def endmember_decompose( # CIPW Norm and Related functions ################################################################################ -from ..util.classification import TAS - # fuctions which map to Fe2O3/FeO ratios. _MiddlemostTASRatios = dict( F=lambda t, x: 0.4 if x[1] > 10 else 0.3, diff --git a/pyrolite/mineral/sites.py b/pyrolite/mineral/sites.py index b487debd..4f5e67c2 100644 --- a/pyrolite/mineral/sites.py +++ b/pyrolite/mineral/sites.py @@ -85,7 +85,7 @@ def __init__( affinities={"Si{4+}": 0, "Al{3+}": 1, "Fe{3+}": 2}, *args, mode="cation", - **kwargs + **kwargs, ): super().__init__(name, coordination, *args, affinities=affinities, **kwargs) diff --git a/pyrolite/util/math.py b/pyrolite/util/math.py index c98b19eb..cd104192 100644 --- a/pyrolite/util/math.py +++ b/pyrolite/util/math.py @@ -424,7 +424,8 @@ def signify_digit(n, unc=None, leeway=0, low_filter=True): if round_to <= 0: fmt = int else: - fmt = lambda x: x + def fmt(x): + return x sig_n = round(n, round_to) if low_filter and sig_n == 0.0: return np.nan @@ -604,12 +605,12 @@ def solve_ratios(*eqs, evaluate=True): Solve a ternary system (top-left-right) given two constraints on two ratios, which together describe intersecting lines/a point. """ - t, l, r = sympy.symbols("t l r") + t, L, r = sympy.symbols("t l r") def to_sympy(t): # rearrange to have =0 equvalent expressions return sympy.sympify("-".join(t.split("="))) result = sympy.solve( - [to_sympy(e) for e in eqs] + [to_sympy("t + l + r = 1")], (t, l, r) + [to_sympy(e) for e in eqs] + [to_sympy("t + l + r = 1")], (t, L, r) ) return list(result.values()) diff --git a/pyrolite/util/resampling.py b/pyrolite/util/resampling.py index cf08618e..8074b7b4 100644 --- a/pyrolite/util/resampling.py +++ b/pyrolite/util/resampling.py @@ -403,7 +403,7 @@ def _metric_name(metric): msg = "Gaussian Process boostrapping not yet implemented." raise NotImplementedError(msg) else: - msg = "Bootstrap method {} not recognised.".format(boostrap_method) + msg = "Bootstrap method {} not recognised.".format(bootstrap_method) raise NotImplementedError(msg) # whether to independently estimate metric values for individual categories? diff --git a/test/comp/comp_aggregate.py b/test/comp/comp_aggregate.py index f1ed674c..b2e98b55 100644 --- a/test/comp/comp_aggregate.py +++ b/test/comp/comp_aggregate.py @@ -1,9 +1,18 @@ -import logging import unittest import numpy as np - -from pyrolite.comp.aggregate import * +import pandas as pd + +from pyrolite.comp.aggregate import ( + compositional_mean, + cross_ratios, + get_full_column, + nan_weighted_compositional_mean, + nan_weighted_mean, + np_cross_ratios, + standardise_aggregate, + weights_from_array, +) from pyrolite.util.synthetic import normal_frame diff --git a/test/comp/comp_codata.py b/test/comp/comp_codata.py index 6784d5fb..6b2653ea 100644 --- a/test/comp/comp_codata.py +++ b/test/comp/comp_codata.py @@ -1,8 +1,23 @@ import unittest import numpy as np - -from pyrolite.comp.codata import * +import pandas as pd + +from pyrolite.comp.codata import ( + ALR, + CLR, + ILR, + boxcox, + close, + get_ILR_labels, + inverse_ALR, + inverse_boxcox, + inverse_CLR, + inverse_ILR, + inverse_sphere, + renormalise, + sphere, +) from pyrolite.util.synthetic import normal_frame diff --git a/test/comp/comp_impute.py b/test/comp/comp_impute.py index 899cf536..6b01c4ed 100644 --- a/test/comp/comp_impute.py +++ b/test/comp/comp_impute.py @@ -1,17 +1,10 @@ import unittest import numpy as np -import pandas as pd -from pyrolite.comp.aggregate import np_cross_ratios -from pyrolite.comp.impute import EMCOMP, _little_sweep, _multisweep, _reg_sweep +from pyrolite.comp.impute import EMCOMP, _little_sweep, _multisweep from pyrolite.util.math import augmented_covariance_matrix -from pyrolite.util.synthetic import ( - normal_frame, - normal_series, - random_composition, - random_cov_matrix, -) +from pyrolite.util.synthetic import random_composition, random_cov_matrix class TestRegSweep(unittest.TestCase): diff --git a/test/geochem/geochem_alteration.py b/test/geochem/geochem_alteration.py index 709751fb..8c8d083f 100644 --- a/test/geochem/geochem_alteration.py +++ b/test/geochem/geochem_alteration.py @@ -1,8 +1,18 @@ import unittest import numpy as np +import pandas as pd -from pyrolite.geochem.alteration import * +from pyrolite.geochem.alteration import ( + CCPI, + CIA, + CIW, + PIA, + SAR, + WIP, + IshikawaAltIndex, + SiTiIndex, +) class TestAlterationIndicies(unittest.TestCase): @@ -56,4 +66,4 @@ def test_CCPI_default(self): if __name__ == "__main__": - unittest.main() + unittest.main() \ No newline at end of file diff --git a/test/geochem/geochem_ind.py b/test/geochem/geochem_ind.py index 4e2f288a..87929848 100644 --- a/test/geochem/geochem_ind.py +++ b/test/geochem/geochem_ind.py @@ -1,6 +1,18 @@ import unittest -from pyrolite.geochem.ind import * +import periodictable as pt + +from pyrolite.geochem.ind import ( + REE, + REY, + by_incompatibility, + by_number, + common_elements, + common_oxides, + get_cations, + get_ionic_radii, + simple_oxides, +) class TestGetCations(unittest.TestCase): diff --git a/test/geochem/geochem_isotope.py b/test/geochem/geochem_isotope.py index e678066e..c6a6ff4f 100644 --- a/test/geochem/geochem_isotope.py +++ b/test/geochem/geochem_isotope.py @@ -5,5 +5,4 @@ class TestDeadtimeCorrection(unittest.TestCase): def test_default(self): - pass deadtime_correction(10000, 20) diff --git a/test/geochem/geochem_norm.py b/test/geochem/geochem_norm.py index 61a1368e..78ea7b39 100644 --- a/test/geochem/geochem_norm.py +++ b/test/geochem/geochem_norm.py @@ -1,8 +1,5 @@ import unittest -import numpy as np - -import pyrolite from pyrolite.geochem.norm import ( Composition, all_reference_compositions, @@ -11,8 +8,6 @@ update_database, ) from pyrolite.util.general import remove_tempdir, temp_path -from pyrolite.util.meta import pyrolite_datafolder -from pyrolite.util.synthetic import normal_frame class TestComposition(unittest.TestCase): diff --git a/test/geochem/geochem_parse.py b/test/geochem/geochem_parse.py index 9f97f8a7..eb33d543 100644 --- a/test/geochem/geochem_parse.py +++ b/test/geochem/geochem_parse.py @@ -4,7 +4,12 @@ import pandas as pd from pyrolite.geochem.ind import REE -from pyrolite.geochem.parse import * +from pyrolite.geochem.parse import ( + check_multiple_cation_inclusion, + ischem, + repr_isotope_ratio, + tochem, +) class TestIsChem(unittest.TestCase): diff --git a/test/geochem/geochem_pyrochem.py b/test/geochem/geochem_pyrochem.py index e91db243..ce516c90 100644 --- a/test/geochem/geochem_pyrochem.py +++ b/test/geochem/geochem_pyrochem.py @@ -6,9 +6,7 @@ import pyrolite.geochem from pyrolite.comp.codata import renormalise from pyrolite.geochem.norm import get_reference_composition -from pyrolite.util.synthetic import normal_frame, normal_series - -# [print("# " + i) for i in dir(df.pyrochem) if "__" not in i and not i.startswith("_")] +from pyrolite.util.synthetic import normal_frame class TestPyrochem(unittest.TestCase): diff --git a/test/geochem/geochem_transform.py b/test/geochem/geochem_transform.py index 5d6d24c6..509816a9 100644 --- a/test/geochem/geochem_transform.py +++ b/test/geochem/geochem_transform.py @@ -2,7 +2,7 @@ import numpy as np -from pyrolite.geochem.ind import REE +from pyrolite.geochem.ind import REE, get_ionic_radii from pyrolite.geochem.norm import get_reference_composition from pyrolite.geochem.transform import * from pyrolite.util.lambdas import orthogonal_polynomial_constants diff --git a/test/mineral/mineral_mindb.py b/test/mineral/mineral_mindb.py index 9776f3f7..2b3dc72b 100644 --- a/test/mineral/mineral_mindb.py +++ b/test/mineral/mineral_mindb.py @@ -46,7 +46,7 @@ def test_get_olivine(self): self.assertIsInstance(out, pd.DataFrame) @unittest.expectedFailure - def test_get_olivine(self): + def test_get_tourmaline(self): out = get_mineral_group("tourmaline") self.assertIsInstance(out, pd.DataFrame) diff --git a/test/mineral/mineral_normative.py b/test/mineral/mineral_normative.py index 72d172be..0e995c92 100644 --- a/test/mineral/mineral_normative.py +++ b/test/mineral/mineral_normative.py @@ -3,14 +3,11 @@ import numpy as np import pandas as pd -from pyrolite.mineral.normative import ( +from pyrolite.mineral.normative import ( # MiddlemostOxRatio, _aggregate_components, _update_molecular_masses, CIPW_norm, LeMaitre_Fe_correction, LeMaitreOxRatio, Middlemost_Fe_correction, - MiddlemostOxRatio, - _aggregate_components, - _update_molecular_masses, endmember_decompose, unmix, ) diff --git a/test/mineral/mineral_sites.py b/test/mineral/mineral_sites.py index 569f69ff..de3c01b0 100644 --- a/test/mineral/mineral_sites.py +++ b/test/mineral/mineral_sites.py @@ -1,6 +1,6 @@ import unittest -from pyrolite.mineral.sites import * +from pyrolite.mineral.sites import AX, IX, MX, OX, TX, VX, Site class TestSites(unittest.TestCase): diff --git a/test/mineral/mineral_template.py b/test/mineral/mineral_template.py index b1bba1be..d2dd3ab0 100644 --- a/test/mineral/mineral_template.py +++ b/test/mineral/mineral_template.py @@ -1,7 +1,11 @@ import unittest -from pyrolite.mineral.sites import * -from pyrolite.mineral.template import * +import numpy as np +import pandas as pd +import periodictable as pt + +from pyrolite.mineral.sites import MX, OX, TX +from pyrolite.mineral.template import OLIVINE, PYROXENE, Mineral, MineralTemplate class TestMineralTemplate(unittest.TestCase): diff --git a/test/mineral/mineral_transform.py b/test/mineral/mineral_transform.py index 27cc043b..f504fafc 100644 --- a/test/mineral/mineral_transform.py +++ b/test/mineral/mineral_transform.py @@ -1,6 +1,13 @@ import unittest -from pyrolite.mineral.transform import * +import pandas as pd +import periodictable as pt + +from pyrolite.mineral.transform import ( + formula_to_elemental, + merge_formulae, + recalc_cations, +) class TestFormula2Elemental(unittest.TestCase): diff --git a/test/plot/plot_biplot.py b/test/plot/plot_biplot.py index 99fc36e8..578710f1 100644 --- a/test/plot/plot_biplot.py +++ b/test/plot/plot_biplot.py @@ -1,13 +1,8 @@ import logging import unittest -import matplotlib.axes -import matplotlib.pyplot as plt -import numpy as np -import pandas as pd - -from pyrolite.data.Aitchison import * -from pyrolite.plot.biplot import * +from pyrolite.data.Aitchison import load_hongite +from pyrolite.plot.biplot import compositional_biplot logger = logging.getLogger(__name__) diff --git a/test/plot/plot_color.py b/test/plot/plot_color.py index 1dc9d4af..89f04a37 100644 --- a/test/plot/plot_color.py +++ b/test/plot/plot_color.py @@ -3,7 +3,7 @@ import matplotlib.colors import numpy as np -from pyrolite.plot.color import * +from pyrolite.plot.color import get_cmode, process_color class TestProcessColor(unittest.TestCase): diff --git a/test/plot/plot_parallel.py b/test/plot/plot_parallel.py index 0372eba2..d8685268 100644 --- a/test/plot/plot_parallel.py +++ b/test/plot/plot_parallel.py @@ -1,9 +1,6 @@ import unittest import matplotlib.axes -import matplotlib.pyplot as plt -import numpy as np -import pandas as pd import pyrolite.data.Aitchison from pyrolite.plot.parallel import parallel diff --git a/test/plot/plot_pyroplot.py b/test/plot/plot_pyroplot.py index 507b7d1c..40af003b 100644 --- a/test/plot/plot_pyroplot.py +++ b/test/plot/plot_pyroplot.py @@ -5,11 +5,9 @@ import matplotlib.pyplot as plt import mpltern.ternary import numpy as np -import pandas as pd -from numpy.random import multivariate_normal from pyrolite.geochem import REE -from pyrolite.plot import density, pyroplot, spider +from pyrolite.plot import pyroplot from pyrolite.util.synthetic import normal_frame logger = logging.getLogger(__name__) diff --git a/test/plot/plot_spider.py b/test/plot/plot_spider.py index cc3704cd..a82c61b0 100644 --- a/test/plot/plot_spider.py +++ b/test/plot/plot_spider.py @@ -4,7 +4,6 @@ import matplotlib.axes import matplotlib.pyplot as plt import numpy as np -import pandas as pd from pyrolite.geochem import REE from pyrolite.plot.spider import REE_v_radii, spider diff --git a/test/plot/plot_stem.py b/test/plot/plot_stem.py index 1f524fb2..fb27c45e 100644 --- a/test/plot/plot_stem.py +++ b/test/plot/plot_stem.py @@ -4,7 +4,6 @@ import matplotlib.axes import matplotlib.pyplot as plt import numpy as np -import pandas as pd from pyrolite.plot.stem import stem diff --git a/test/util/util_env.py b/test/util/util_env.py index b80fa035..9441f1f4 100644 --- a/test/util/util_env.py +++ b/test/util/util_env.py @@ -1,5 +1,4 @@ import os -import sys import unittest from pyrolite.util.env import validate_update_envvar, validate_value @@ -10,7 +9,8 @@ def setUp(self): self.value = 10 def test_single_validator(self): - v = lambda x: x > 0 + def v(x): + return x > 0 expect = True self.assertTrue(validate_value(self.value, v) is expect) diff --git a/test/util/util_general.py b/test/util/util_general.py index 927b7c29..741f5084 100644 --- a/test/util/util_general.py +++ b/test/util/util_general.py @@ -1,11 +1,8 @@ import unittest -from pathlib import Path -from pyrolite.util.general import ( +from pyrolite.util.general import ( # copy_file, remove_tempdir Timewith, - copy_file, flatten_dict, - remove_tempdir, swap_item, temp_path, ) diff --git a/test/util/util_log.py b/test/util/util_log.py index a17a00e6..73dfd3b0 100644 --- a/test/util/util_log.py +++ b/test/util/util_log.py @@ -3,7 +3,7 @@ import unittest from io import StringIO -import pyrolite.plot # for logging checks +import pyrolite.plot # for logging checks # noqa: F401 from pyrolite.util.log import Handle, ToLogger, stream_log @@ -77,14 +77,16 @@ def test_set_level(self): logger = Handle("pyrolite", level=level) self.assertTrue(logger.level == val) + class TestToLogger(unittest.TestCase): def test_default(self): - logger= Handle(__name__, level='DEBUG') + logger = Handle(__name__, level="DEBUG") - with ToLogger(logger, 'INFO') as f: - f.write('Logging output from stream.') + with ToLogger(logger, "INFO") as f: + f.write("Logging output from stream.") f.flush() + if __name__ == "__main__": unittest.main() diff --git a/test/util/util_math.py b/test/util/util_math.py index 12735343..45993cc7 100644 --- a/test/util/util_math.py +++ b/test/util/util_math.py @@ -4,7 +4,26 @@ import pandas as pd from sympy import tensorcontraction -from pyrolite.util.math import * +from pyrolite.util.math import ( + augmented_covariance_matrix, + equal_within_significance, + grid_from_ranges, + helmert_basis, + interpolate_line, + is_numeric, + isclose, + linrng_, + linspc_, + logrng_, + logspc_, + most_precise, + nancov, + on_finite, + round_sig, + significant_figures, + signify_digit, + symbolic_helmert_basis, +) from pyrolite.util.synthetic import random_cov_matrix diff --git a/test/util/util_meta.py b/test/util/util_meta.py index 6b0bfb30..ede5a271 100644 --- a/test/util/util_meta.py +++ b/test/util/util_meta.py @@ -1,4 +1,3 @@ -import sys import unittest from pathlib import Path diff --git a/test/util/util_multip.py b/test/util/util_multip.py index 73d3ae97..6a105b10 100644 --- a/test/util/util_multip.py +++ b/test/util/util_multip.py @@ -1,9 +1,6 @@ import platform import unittest -import numpy as np -import pandas as pd - from pyrolite.util.multip import combine_choices, func_wrapper, multiprocess @@ -49,7 +46,8 @@ def test_construct(self): @unittest.skipIf( - platform.system() in ["Windows", 'Darwin'], "Bug with multiprocessing testing on Windows" + platform.system() in ["Windows", "Darwin"], + "Bug with multiprocessing testing on Windows", ) class TestMultiprocess(unittest.TestCase): """Tests the multiprocess utility function.""" diff --git a/test/util/util_pd.py b/test/util/util_pd.py index f43792c1..135cd97e 100644 --- a/test/util/util_pd.py +++ b/test/util/util_pd.py @@ -1,14 +1,21 @@ -import os -import time import unittest -from pathlib import Path import numpy as np import pandas as pd from pyrolite.util.general import remove_tempdir, temp_path from pyrolite.util.meta import subkwargs -from pyrolite.util.pd import * +from pyrolite.util.pd import ( + accumulate, + concat_columns, + df_from_csvs, + outliers, + read_table, + to_frame, + to_numeric, + to_ser, + uniques_from_concat, +) from pyrolite.util.synthetic import normal_frame, normal_series @@ -137,7 +144,7 @@ def test_error_methods(self): with self.subTest(method=method): try: result = to_numeric(df, errors=method) - self.assertTrue(method in [ "coerce"]) + self.assertTrue(method in ["coerce"]) self.assertTrue(pd.isnull(result.loc[0, "SiO2"])) except ValueError: # should raise with can't parse 'low' self.assertTrue(method == "raise") diff --git a/test/util/util_resampling.py b/test/util/util_resampling.py index 0c3e9317..5c59542f 100644 --- a/test/util/util_resampling.py +++ b/test/util/util_resampling.py @@ -4,14 +4,12 @@ import numpy as np import pandas as pd -from pyrolite.util.resampling import ( - _segmented_univariate_distance_matrix, +from pyrolite.util.resampling import ( # _segmented_univariate_distance_matrix add_age_noise, get_spatiotemporal_resampling_weights, spatiotemporal_bootstrap_resample, univariate_distance_matrix, ) -from pyrolite.util.spatial import great_circle_distance from pyrolite.util.synthetic import normal_frame df = normal_frame() diff --git a/test/util/util_spatial.py b/test/util/util_spatial.py index 571d6fe8..98768c3d 100644 --- a/test/util/util_spatial.py +++ b/test/util/util_spatial.py @@ -1,17 +1,21 @@ import unittest -import matplotlib.pyplot as plt import numpy as np -import pandas as pd -try: - import cartopy.crs as ccrs - - HAVE_CARTOPY = True -except ImportError: - HAVE_CARTOPY = False from pyrolite.util.math import isclose # nan-equalling isclose -from pyrolite.util.spatial import * +from pyrolite.util.spatial import ( + NSEW_2_bounds, + great_circle_distance, + levenshtein_distance, + piecewise, + spatiotemporal_split, +) + +# try: +# import cartopy.crs as ccrs +# HAVE_CARTOPY = True +# except ImportError: +# HAVE_CARTOPY = False class TestGreatCircleDistance(unittest.TestCase): diff --git a/test/util/util_synthetic.py b/test/util/util_synthetic.py index 2be7d7f0..5a7b8301 100644 --- a/test/util/util_synthetic.py +++ b/test/util/util_synthetic.py @@ -3,7 +3,11 @@ import numpy as np import pandas as pd -from pyrolite.util.synthetic import * +from pyrolite.util.synthetic import ( + example_spider_data, + random_composition, + random_cov_matrix, +) class TestExampleSpiderData(unittest.TestCase): diff --git a/test/util/util_text.py b/test/util/util_text.py index a205bb33..aa908a6f 100644 --- a/test/util/util_text.py +++ b/test/util/util_text.py @@ -1,9 +1,19 @@ import unittest import numpy as np -import pandas as pd -from pyrolite.util.text import * +from pyrolite.util.text import ( + int_to_alpha, + normalise_whitespace, + parse_entry, + quoted_string, + remove_prefix, + slugify, + split_records, + string_variations, + titlecase, + to_width, +) class TestRemovePrefix(unittest.TestCase): diff --git a/test/util/util_types.py b/test/util/util_types.py index 2eaf4e21..9f915245 100644 --- a/test/util/util_types.py +++ b/test/util/util_types.py @@ -1,9 +1,8 @@ import unittest import numpy as np -import pandas as pd -from pyrolite.util.types import * +from pyrolite.util.types import iscollection class TestIscollection(unittest.TestCase): diff --git a/test/util/util_units.py b/test/util/util_units.py index 9f1663e4..f156156a 100644 --- a/test/util/util_units.py +++ b/test/util/util_units.py @@ -1,10 +1,8 @@ import unittest import numpy as np +import pandas as pd -import pyrolite -from pyrolite.util.synthetic import normal_frame -from pyrolite.util.units import * from pyrolite.util.units import __UNITS__, scale