Repository: scipy/scipy
File: scipy/io/_mmio.py (Python)

Code before:

        Returns
        -------
        a : ndarray or coo_array or coo_matrix
            Dense or sparse array depending on the matrix format in the
            Matrix Market file.
        """
        stream, close_it = self._open(source)

        try:
            self._parse_header(stream)
            data = self._parse_body(stream)

        finally:
            if close_it:
                stream.close()

        if spmatrix is _NoValue:
            msg = """The default value for `spmatrix` is changing to `False` in v1.19.
                That means the default return type will be a sparse array.
                Unless you use * instead of @, ** for matrix power, or you depend
                on 2D shapes from e.g. `A.sum(axis=0)` it may not matter to you.
                See the spmatrix to sparray migration guide for details.
                https://docs.scipy.org/doc/scipy/reference/sparse.migration_to_sparray.html
                """
            warn(msg, DeprecationWarning, stacklevel=2)
            spmatrix = True

        if spmatrix and isinstance(data, coo_array):
            data = coo_matrix(data)
        return data


    # -------------------------------------------------------------------------
    def write(self, target, a, comment='', field=None, precision=None,
              symmetry=None):
        """
        Writes sparse or dense array `a` to Matrix Market file-like `target`.

        Parameters
        ----------
        target : str or file-like
            Matrix Market filename (extension .mtx) or open file-like object.
        a : array like
            Sparse or dense 2-D array.
        comment : str, optional
            Comments to be prepended to the Matrix Market file.
        field : None or str, optional
            Either 'real', 'complex', 'pattern', or 'integer'.
        precision : None or int, optional
            Number of digits to display for real or complex values.

Review comment (suggestion):
here and elsewhere -- minor comment, but we might want to prefer using `skip_file_prefixes` over manual stack level control now that we are 3.12+? (i.e., gh-24414)

Code after:

        Returns
        -------
        a : ndarray or coo_array or coo_matrix
            Dense or sparse array depending on the matrix format in the
            Matrix Market file.
        """
        stream, close_it = self._open(source)

        try:
            self._parse_header(stream)
            data = self._parse_body(stream)

        finally:
            if close_it:
                stream.close()

        if spmatrix is _NoValue:
            msg = """The default value for `spmatrix` is changing to `False` in v1.20.
             That means the default return type will be a sparse array.
             Unless you use * instead of @, ** for matrix power, or you depend
             on 2D shapes from e.g. `A.sum(axis=0)` it may not matter to you.
             See the spmatrix to sparray migration guide for details.
             https://docs.scipy.org/doc/scipy/reference/sparse.migration_to_sparray.html
             """
            prefixes = (os.path.dirname(__file__),)
            warn(msg, DeprecationWarning, skip_file_prefixes=prefixes)
            spmatrix = True

        if spmatrix and isinstance(data, coo_array):
            data = coo_matrix(data)
        return data


    # -------------------------------------------------------------------------
    def write(self, target, a, comment='', field=None, precision=None,
              symmetry=None):
        """
        Writes sparse or dense array `a` to Matrix Market file-like `target`.

        Parameters
        ----------
        target : str or file-like
            Matrix Market filename (extension .mtx) or open file-like object.
        a : array like
            Sparse or dense 2-D array.
        comment : str, optional
            Comments to be prepended to the Matrix Market file.
        field : None or str, optional
            Either 'real', 'complex', 'pattern', or 'integer'.
        precision : None or int, optional