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

Cannot import scipy.linalg.triu #20680

Closed
evemilano opened this issue May 9, 2024 · 8 comments
Closed

Cannot import scipy.linalg.triu #20680

evemilano opened this issue May 9, 2024 · 8 comments
Labels
deprecated Items related to behavior that has been deprecated duplicate Issues that describe the same problem or that are reported multiple times wontfix Not actionable, rejected or unplanned changes

Comments

@evemilano
Copy link

evemilano commented May 9, 2024

Describe your issue.

Where is triu? Why remove stuff and broke other projects???
It's just a boring thing when these things happen.
Maintaining backwards compatibility would be a good thing.

Reproducing Code Example

from langdetect import detect
import time
import pandas as pd
import spacy
import gensim
import os
import numpy as np
import hdbscan
import plotly.graph_objs as go
import nltk
nltk.download('omw')
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
nltk.download('wordnet')
nltk.download('stopwords')
from nltk.stem.snowball import SnowballStemmer
from nltk.tokenize import word_tokenize
from nltk.stem import WordNetLemmatizer
from nltk.stem import PorterStemmer
from nltk.corpus import stopwords
from collections import Counter
from tqdm import tqdm
from datetime import datetime
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
from kneed import KneeLocator
from unidecode import unidecode
import re

Error message

ImportError: cannot import name 'triu' from 'scipy.linalg'

SciPy/NumPy/Python version and system information

scipy 1.13
python 3.12.3
@evemilano evemilano added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label May 9, 2024
@andyfaff andyfaff changed the title BUG: <Please write a comprehensive title after the 'BUG: ' prefix> Cannot import scipy.linalg.triu May 9, 2024
@evemilano
Copy link
Author

evemilano commented May 9, 2024

Other error example:


ImportError Traceback (most recent call last)
Cell In[1], line 20
18 from nltk.corpus import stopwords
19 nltk.download('stopwords')
---> 20 from gensim.models import Doc2Vec
21 from gensim.models.doc2vec import TaggedDocument
22 # Manipolazione del filesystem e JSON

File e:\python\amb\Lib\site-packages\gensim_init_.py:11
7 version = '4.3.2'
9 import logging
---> 11 from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils # noqa:F401
14 logger = logging.getLogger('gensim')
15 if not logger.handlers: # To ensure reload() doesn't add another one

File e:\python\amb\Lib\site-packages\gensim\corpora_init_.py:6
1 """
2 This package contains implementations of various streaming corpus I/O format.
3 """
5 # bring corpus classes directly into package namespace, to save some typing
----> 6 from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes
8 from .mmcorpus import MmCorpus # noqa:F401
9 from .bleicorpus import BleiCorpus # noqa:F401
...
---> 20 from scipy.linalg import get_blas_funcs, triu
21 from scipy.linalg.lapack import get_lapack_funcs
22 from scipy.special import psi # gamma function utils

ImportError: cannot import name 'triu' from 'scipy.linalg' (e:\python\amb\Lib\site-packages\scipy\linalg_init_.py)

@andyfaff
Copy link
Contributor

andyfaff commented May 9, 2024

I appreciate there is frustration when problems are experienced, but please be civil when creating issues.
This is a duplicate of #20402.
triu is deprecated and removed from scipy.linalg. You need to use triu from numpy with:

np.triu

Which package is trying to import scipy.linalg.triu? You should be able to tell from the full stack trace that came with the ImportError.

@andyfaff andyfaff added duplicate Issues that describe the same problem or that are reported multiple times wontfix Not actionable, rejected or unplanned changes deprecated Items related to behavior that has been deprecated and removed defect A clear bug or issue that prevents SciPy from being installed or used as expected labels May 9, 2024
@evemilano
Copy link
Author

evemilano commented May 9, 2024

Hello @andyfaff, why don't you fix an error that has been reported several times and causes problems for many people? You made an upgrade that broke several scripts, can you at least indicate a method to fix it?

@andyfaff
Copy link
Contributor

andyfaff commented May 9, 2024

When scipy deprecates functions it has a policy of emitting DeprecationWarnings for at least two releases before removal, this will be at least a years notice. Therefore downstream package maintainers have adequate time to reconfigure and release new versions that account for the deprecations. Such deprecations are necessary to reduce technical debt whilst still moving forward with new developments.

A workaround would be to use scipy==1.12.

The issue has already been addressed by the downstream package in piskvorky/gensim#3524.

@andyfaff andyfaff closed this as completed May 9, 2024
@lucascolley
Copy link
Member

A workaround would be to use scipy==1.12.

and once gensim releases a version without the bug, you can upgrade gensim and use the latest scipy.

@ilayn
Copy link
Member

ilayn commented May 9, 2024

In this case the warnings were emitted since version 1.11 so downstream packages should pay attention to warnings before blaming us. If you use scipy 1.12 you should see it already if warnings are not silenced

@MowlanicaBilla
Copy link

A workaround would be to use scipy==1.12.

and once gensim releases a version without the bug, you can upgrade gensim and use the latest scipy.

The error still persists with spicy==1.12

@lucascolley
Copy link
Member

lucascolley commented May 27, 2024

The error still persists with spicy==1.12

With which gensim version? To reiterate, the bug is on gensim's side, and the fix (piskvorky/gensim#3524) is milestoned for their 'spring 2024 release'.

EDIT: The error shouldn't occur with scipy==1.12 though, as linalg.triu was removed in 1.13. You should see the deprecation warning in 1.12, though.

@lucascolley lucascolley closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated Items related to behavior that has been deprecated duplicate Issues that describe the same problem or that are reported multiple times wontfix Not actionable, rejected or unplanned changes
Projects
None yet
Development

No branches or pull requests

5 participants