pyxem / kikuchipy

Toolbox for analysis of electron backscatter diffraction (EBSD) patterns
https://kikuchipy.org
GNU General Public License v3.0
81 stars 29 forks source link

Python 3.9 support #343

Closed hakonanes closed 3 years ago

hakonanes commented 3 years ago

Should make sure everything is compatible with Python 3.9 before releasing v0.3.3 on conda-forge stating that it is Python 3.9 compatible (https://github.com/conda-forge/kikuchipy-feedstock/pull/12).

hakonanes commented 3 years ago

Apart from test failures due to outdated use of newest versions of Matplotlib and dask, the tests pass OK with Python 3.9 on my Ubuntu 20.04. These errors can be fixed in an update to master, but shouldn't hinder us in claiming that kikuchipy v0.3.3 supports Python 3.9.

(kp-dev39)(python3.9-support)[/home/hakon/kode/kikuchipy]
> pytest --pyargs kikuchipy
========================================== test session starts ==========================================
platform linux -- Python 3.9.2, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/hakon/kode/kikuchipy, configfile: setup.cfg
plugins: cov-2.11.1
collected 747 items                                                                                     

kikuchipy/crystallography/tests/test_crystallographic_computations.py .............               [  1%]
kikuchipy/crystallography/tests/test_crystallographic_matrices.py ......                          [  2%]
kikuchipy/data/tests/test_data.py ...........                                                     [  4%]
kikuchipy/detectors/tests/test_calibration.py ........                                            [  5%]
kikuchipy/detectors/tests/test_ebsd_detector.py ................................................. [ 11%]
.........FFF.......                                                                               [ 14%]
kikuchipy/draw/tests/test_colors.py .                                                             [ 14%]
kikuchipy/draw/tests/test_markers.py .....................                                        [ 17%]
kikuchipy/filters/tests/test_fft_barnes.py ...................                                    [ 19%]
kikuchipy/filters/tests/test_window.py .....................................................      [ 26%]
kikuchipy/generators/tests/test_ebsd_simulation_generator.py ..............................       [ 30%]
kikuchipy/generators/tests/test_virtual_bse_generator.py ..........................               [ 34%]
kikuchipy/indexing/tests/test_merge_crystal_maps.py .......................                       [ 37%]
kikuchipy/indexing/tests/test_orientation_similarity_map.py ...                                   [ 37%]
kikuchipy/indexing/tests/test_pattern_matching.py ..........                                      [ 39%]
kikuchipy/indexing/tests/test_similarity_metrics.py .................                             [ 41%]
kikuchipy/indexing/tests/test_static_pattern_matching.py ...............                          [ 43%]
kikuchipy/io/plugins/tests/test_emsoft_ebsd.py ........                                           [ 44%]
kikuchipy/io/plugins/tests/test_emsoft_ebsd_masterpattern.py ...................                  [ 46%]
kikuchipy/io/plugins/tests/test_h5ebsd.py ..................F.........                            [ 50%]
kikuchipy/io/plugins/tests/test_nordif.py ...........F......                                      [ 53%]
kikuchipy/io/plugins/tests/test_nordif_calibration_patterns.py ....                               [ 53%]
kikuchipy/io/tests/test_io.py ............                                                        [ 55%]
kikuchipy/io/tests/test_util.py .....                                                             [ 55%]
kikuchipy/pattern/tests/test_chunk.py ..............................................              [ 62%]
kikuchipy/pattern/tests/test_correlate.py ..                                                      [ 62%]
kikuchipy/pattern/tests/test_pattern.py .........................................                 [ 67%]
kikuchipy/projections/tests/test_ebsd_projections.py ....                                         [ 68%]
kikuchipy/projections/tests/test_gnomonic_projection.py ..                                        [ 68%]
kikuchipy/projections/tests/test_hesse_normal_form.py ....                                        [ 69%]
kikuchipy/projections/tests/test_lambert_projection.py .......                                    [ 70%]
kikuchipy/projections/tests/test_spherical_projection.py .                                        [ 70%]
kikuchipy/signals/tests/test_ebsd.py ............................................................ [ 78%]
............................................................                                      [ 86%]
kikuchipy/signals/tests/test_ebsd_masterpattern.py .................                              [ 88%]
kikuchipy/signals/tests/test_virtual_bse_image.py ..                                              [ 88%]
kikuchipy/signals/util/tests/test_dask.py .........                                               [ 90%]
kikuchipy/signals/util/tests/test_metadata.py ...                                                 [ 90%]
kikuchipy/simulations/tests/test_features.py ......................................               [ 95%]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py ................................. [100%]

=============================================== FAILURES ================================================
_________________________ TestEBSDDetector.test_plot_pc_kwargs[detector0-None] __________________________

self = <kikuchipy.detectors.tests.test_ebsd_detector.TestEBSDDetector object at 0x7f18f14a5460>
detector = EBSDDetector (60, 60), px_size 70 um, binning 8, tilt 0, pc (0.421, 0.221, 0.505)
pc_kwargs = {'facecolor': 'gold'}

    @pytest.mark.parametrize(
        "pc_kwargs", [None, {"facecolor": "r"}, {"facecolor": "b"}]
    )
    def test_plot_pc_kwargs(self, detector, pc_kwargs):
        """Pass PC kwargs to scatter()."""
        _, ax = detector.plot(
            show_pc=True, pc_kwargs=pc_kwargs, return_fig_ax=True
        )
        if pc_kwargs is None:
            pc_kwargs = {"facecolor": "gold"}
>       assert np.allclose(
            ax.collections[0].get_facecolor().squeeze()[:3],
            mcolors.to_rgb(pc_kwargs["facecolor"]),
        )

kikuchipy/detectors/tests/test_ebsd_detector.py:435: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
<__array_function__ internals>:5: in allclose
    ???
../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2256: in allclose
    res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
<__array_function__ internals>:5: in isclose
    ???
../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2365: in isclose
    return within_tol(x, y, atol, rtol)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

x = array([], shape=(0, 4), dtype=float64), y = array([1.        , 0.84313725, 0.        ]), atol = 1e-08
rtol = 1e-05

    def within_tol(x, y, atol, rtol):
        with errstate(invalid='ignore'):
>           return less_equal(abs(x-y), atol + rtol * abs(y))
E           ValueError: operands could not be broadcast together with shapes (0,4) (3,)

../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2346: ValueError
______________________ TestEBSDDetector.test_plot_pc_kwargs[detector0-pc_kwargs1] _______________________

self = <kikuchipy.detectors.tests.test_ebsd_detector.TestEBSDDetector object at 0x7f18f1f28d00>
detector = EBSDDetector (60, 60), px_size 70 um, binning 8, tilt 0, pc (0.421, 0.221, 0.505)
pc_kwargs = {'edgecolor': 'k', 'facecolor': 'r', 'marker': '*', 's': 300}

    @pytest.mark.parametrize(
        "pc_kwargs", [None, {"facecolor": "r"}, {"facecolor": "b"}]
    )
    def test_plot_pc_kwargs(self, detector, pc_kwargs):
        """Pass PC kwargs to scatter()."""
        _, ax = detector.plot(
            show_pc=True, pc_kwargs=pc_kwargs, return_fig_ax=True
        )
        if pc_kwargs is None:
            pc_kwargs = {"facecolor": "gold"}
>       assert np.allclose(
            ax.collections[0].get_facecolor().squeeze()[:3],
            mcolors.to_rgb(pc_kwargs["facecolor"]),
        )

kikuchipy/detectors/tests/test_ebsd_detector.py:435: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
<__array_function__ internals>:5: in allclose
    ???
../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2256: in allclose
    res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
<__array_function__ internals>:5: in isclose
    ???
../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2365: in isclose
    return within_tol(x, y, atol, rtol)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

x = array([], shape=(0, 4), dtype=float64), y = array([1., 0., 0.]), atol = 1e-08, rtol = 1e-05

    def within_tol(x, y, atol, rtol):
        with errstate(invalid='ignore'):
>           return less_equal(abs(x-y), atol + rtol * abs(y))
E           ValueError: operands could not be broadcast together with shapes (0,4) (3,)

../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2346: ValueError
______________________ TestEBSDDetector.test_plot_pc_kwargs[detector0-pc_kwargs2] _______________________

self = <kikuchipy.detectors.tests.test_ebsd_detector.TestEBSDDetector object at 0x7f18f1ffd220>
detector = EBSDDetector (60, 60), px_size 70 um, binning 8, tilt 0, pc (0.421, 0.221, 0.505)
pc_kwargs = {'edgecolor': 'k', 'facecolor': 'b', 'marker': '*', 's': 300}

    @pytest.mark.parametrize(
        "pc_kwargs", [None, {"facecolor": "r"}, {"facecolor": "b"}]
    )
    def test_plot_pc_kwargs(self, detector, pc_kwargs):
        """Pass PC kwargs to scatter()."""
        _, ax = detector.plot(
            show_pc=True, pc_kwargs=pc_kwargs, return_fig_ax=True
        )
        if pc_kwargs is None:
            pc_kwargs = {"facecolor": "gold"}
>       assert np.allclose(
            ax.collections[0].get_facecolor().squeeze()[:3],
            mcolors.to_rgb(pc_kwargs["facecolor"]),
        )

kikuchipy/detectors/tests/test_ebsd_detector.py:435: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
<__array_function__ internals>:5: in allclose
    ???
../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2256: in allclose
    res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
<__array_function__ internals>:5: in isclose
    ???
../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2365: in isclose
    return within_tol(x, y, atol, rtol)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

x = array([], shape=(0, 4), dtype=float64), y = array([0., 0., 1.]), atol = 1e-08, rtol = 1e-05

    def within_tol(x, y, atol, rtol):
        with errstate(invalid='ignore'):
>           return less_equal(abs(x-y), atol + rtol * abs(y))
E           ValueError: operands could not be broadcast together with shapes (0,4) (3,)

../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/numpy/core/numeric.py:2346: ValueError
_____________________________________ Testh5ebsd.test_load_readonly _____________________________________

self = <kikuchipy.io.plugins.tests.test_h5ebsd.Testh5ebsd object at 0x7f18f2201850>

    def test_load_readonly(self):
        s = load(KIKUCHIPY_FILE, lazy=True)
        k = next(
            filter(
                lambda x: isinstance(x, str) and x.startswith("array-original"),
                s.data.dask.keys(),
            )
        )
        mm = s.data.dask[k]
        assert isinstance(mm, Dataset)
        with pytest.raises(NotImplementedError):
>           s.data[:] = 23
E           Failed: DID NOT RAISE <class 'NotImplementedError'>

/home/hakon/kode/kikuchipy/kikuchipy/io/plugins/tests/test_h5ebsd.py:309: Failed
_____________________________________ TestNORDIF.test_load_readonly _____________________________________

self = <kikuchipy.io.plugins.tests.test_nordif.TestNORDIF object at 0x7f18f146b730>

    def test_load_readonly(self):
        s = load(PATTERN_FILE, lazy=True)
        k = next(
            filter(
                lambda x: isinstance(x, str) and x.startswith("array-original"),
                s.data.dask.keys(),
            )
        )
        mm = s.data.dask[k]
        assert isinstance(mm, np.memmap)
        assert not mm.flags["WRITEABLE"]
        with pytest.raises(NotImplementedError):
>           s.data[:] = 23
E           Failed: DID NOT RAISE <class 'NotImplementedError'>

/home/hakon/kode/kikuchipy/kikuchipy/io/plugins/tests/test_nordif.py:382: Failed
=========================================== warnings summary ============================================
../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/orix/quaternion/rotation.py:51
  /home/hakon/miniconda3/envs/kp-dev39/lib/python3.9/site-packages/orix/quaternion/rotation.py:51: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    _FLOAT_EPS = np.finfo(np.float).eps  # Used to round values below 1e-16 to zero

kikuchipy/io/plugins/nordif_calibration_patterns.py:121
  /home/hakon/kode/kikuchipy/kikuchipy/io/plugins/nordif_calibration_patterns.py:121: DeprecationWarning: invalid escape sequence \(
    match = re.search("Calibration \((.*)\)", line)

../../miniconda3/envs/kp-dev39/lib/python3.9/site-packages/diffsims/crystallography/reciprocal_lattice_point.py:32
  /home/hakon/miniconda3/envs/kp-dev39/lib/python3.9/site-packages/diffsims/crystallography/reciprocal_lattice_point.py:32: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    _FLOAT_EPS = np.finfo(np.float).eps  # Used to round values below 1e-16 to zero

kikuchipy/detectors/tests/test_calibration.py::TestPCCalibrationMovingScreen::test_plot
  /home/hakon/kode/kikuchipy/kikuchipy/detectors/calibration.py:349: UserWarning: You passed a edgecolor/edgecolors ('k') for an unfilled marker ('*').  Matplotlib is ignoring the edgecolor in favor of the facecolor.  This behavior may change in the future.
    ax[i].scatter(px, py, **pc_kwargs, **scatter_kwargs)

kikuchipy/detectors/tests/test_ebsd_detector.py: 13 warnings
  /home/hakon/kode/kikuchipy/kikuchipy/detectors/ebsd_detector.py:594: UserWarning: You passed a edgecolor/edgecolors ('k') for an unfilled marker ('*').  Matplotlib is ignoring the edgecolor in favor of the facecolor.  This behavior may change in the future.
    ax.scatter(x=pcx, y=pcy, **pc_kwargs)

kikuchipy/signals/tests/test_ebsd_masterpattern.py::TestSimulatedPatternDictionary::test_simulated_patterns_xmap_detector
  /home/hakon/miniconda3/envs/kp-dev39/lib/python3.9/site-packages/orix/quaternion/rotation.py:309: RuntimeWarning: invalid value encountered in true_divide
    np.divide(b * d - a * c, chi), np.divide(-a * b - c * d, chi)

kikuchipy/signals/tests/test_ebsd_masterpattern.py::TestSimulatedPatternDictionary::test_simulated_patterns_xmap_detector
  /home/hakon/miniconda3/envs/kp-dev39/lib/python3.9/site-packages/orix/quaternion/rotation.py:313: RuntimeWarning: invalid value encountered in true_divide
    np.divide(a * c + b * d, chi), np.divide(c * d - a * b, chi)

kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_zone_axes_as_markers[nickel_rlp0-detector0-nav_shape0]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_zone_axes_as_markers[nickel_rlp0-detector0-nav_shape1]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_zone_axes_as_markers[nickel_rlp0-detector0-nav_shape2]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_zone_axes_as_markers[nickel_rlp0-detector0-nav_shape3]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_as_markers[nickel_rlp0-detector0]
  /home/hakon/miniconda3/envs/kp-dev39/lib/python3.9/site-packages/hyperspy/drawing/_markers/point.py:98: UserWarning: You passed a edgecolor/edgecolors ('k') for an unfilled marker ('o').  Matplotlib is ignoring the edgecolor in favor of the facecolor.  This behavior may change in the future.
    self.marker = self.ax.scatter(self.get_data_position('x1'),

kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_pc_as_markers[nickel_rlp0-detector0-nav_shape0]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_pc_as_markers[nickel_rlp0-detector0-nav_shape1]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_pc_as_markers[nickel_rlp0-detector0-nav_shape2]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_pc_as_markers[nickel_rlp0-detector0-nav_shape3]
kikuchipy/simulations/tests/test_geometrical_ebsd_simulation.py::TestGeometricalEBSDSimulation::test_as_markers[nickel_rlp0-detector0]
  /home/hakon/miniconda3/envs/kp-dev39/lib/python3.9/site-packages/hyperspy/drawing/_markers/point.py:98: UserWarning: You passed a edgecolor/edgecolors ('k') for an unfilled marker ('*').  Matplotlib is ignoring the edgecolor in favor of the facecolor.  This behavior may change in the future.
    self.marker = self.ax.scatter(self.get_data_position('x1'),

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================== short test summary info ========================================
FAILED kikuchipy/detectors/tests/test_ebsd_detector.py::TestEBSDDetector::test_plot_pc_kwargs[detector0-None]
FAILED kikuchipy/detectors/tests/test_ebsd_detector.py::TestEBSDDetector::test_plot_pc_kwargs[detector0-pc_kwargs1]
FAILED kikuchipy/detectors/tests/test_ebsd_detector.py::TestEBSDDetector::test_plot_pc_kwargs[detector0-pc_kwargs2]
FAILED kikuchipy/io/plugins/tests/test_h5ebsd.py::Testh5ebsd::test_load_readonly - Failed: DID NOT RAI...
FAILED kikuchipy/io/plugins/tests/test_nordif.py::TestNORDIF::test_load_readonly - Failed: DID NOT RAI...
========================= 5 failed, 742 passed, 29 warnings in 64.15s (0:01:04) =========================