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

Bug module 'numpy' has no attribute 'int'. Did you mean: 'inf'? #151

Closed
JavaProgswing opened this issue Dec 21, 2022 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@JavaProgswing
Copy link

Traceback (most recent call last):
File "C:\Users\HP\Desktop\Programs\Python\Testing\test.py", line 1, in
import pygad
File "C:\Users\HP.virtualenvs\Testing-x9UQs_eI\lib\site-packages\pygad_init_.py", line 1, in
from .pygad import * # Relative import.
File "C:\Users\HP.virtualenvs\Testing-x9UQs_eI\lib\site-packages\pygad\pygad.py", line 9, in
class GA:
File "C:\Users\HP.virtualenvs\Testing-x9UQs_eI\lib\site-packages\pygad\pygad.py", line 11, in GA
supported_int_types = [int, numpy.int, numpy.int8, numpy.int16, numpy.int32, numpy.int64, numpy.uint, numpy.uint8, numpy.uint16, numpy.uint32, numpy.uint64]
File "C:\Users\HP.virtualenvs\Testing-x9UQs_eI\lib\site-packages\numpy_init_.py", line 284, in getattr
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'int'. Did you mean: 'inf'?

@JavaProgswing JavaProgswing changed the title Bug Bug module 'numpy' has no attribute 'int'. Did you mean: 'inf'? Dec 21, 2022
@BenoitMiquey
Copy link

Hi,

Can you give the steps to reproduce this bug ?

@JavaProgswing
Copy link
Author

I actually tried a sample code in a pipenv and it gave me this error.

`
import pygad

Define the function to be optimized

def fitness_func(x):
return x**2

Set the number of variables (in this case, x) and the number of generations

num_variables = 1
num_generations = 100

Set the lower and upper bounds for x

lower_bound = [0]
upper_bound = [10]

Set the crossover and mutation rate

crossover_rate = 0.8
mutation_rate = 0.2

Create the PyGAD object

ga = pygad.GeneticAlgorithm(num_variables=num_variables,
num_generations=num_generations,
lower_bound=lower_bound,
upper_bound=upper_bound,
crossover_rate=crossover_rate,
mutation_rate=mutation_rate,
fitness_func=fitness_func)

Run the optimization

best_solution = ga.run()

Print the best solution

print(best_solution)
`

@julianbieber
Copy link

I think I had the same issue.
From what I understand, numpy 1.24.0 was released 3 days ago, and they removed some deprecated aliases, one of which is numpy.int.

https://github.com/numpy/numpy/releases/tag/v1.24.0:

The deprecation for the aliases np.object, np.bool, np.float,
np.complex, np.str, and np.int is expired (introduces NumPy
1.20). Some of these will now give a FutureWarning in addition to
raising an error since they will be mapped to the NumPy scalars in
the future.

By using a previous version of numpy I was able to work around the issue.

python3 -m pip install numpy==1.23.5

@EgorBlagov
Copy link
Contributor

Here is the PR fixing the issue: #152

@connorfuhrman
Copy link

Had a similar issue and had to revert to numpy<=1.20. I then had troubles installing that version of numpy with Python > 3.9.

@uid89626
Copy link

Happened to me too on python 3.10.5 with numpy 1.24.1.
numpy.int and numpy.float seem removed. fix is to update pygad.py like
`class GA:

supported_int_types = [int, numpy.int8, numpy.int16, numpy.int32, numpy.int64, numpy.uint, numpy.uint8, numpy.uint16, numpy.uint32, numpy.uint64]
supported_float_types = [float, numpy.float16, numpy.float32, numpy.float64]

`

@johnosbb
Copy link

Same issue, using the reference code provided on the main page:

raise AttributeError("module {!r} has no attribute "

AttributeError: module 'numpy' has no attribute 'int'. Did you mean: 'inf'?

@ahmedfgad
Copy link
Owner

The issue is solved in this PR: #152

A new release will be pushed soon.

ahmedfgad added a commit that referenced this issue Feb 14, 2023
Release Date: 14 February 2023

1. Remove `numpy.int` and `numpy.float` from the list of supported data types. #151 #152
2. Call the `on_crossover()` callback function even if `crossover_type` is `None`. #138
3. Call the `on_mutation()` callback function even if `mutation_type` is `None`. #138
@ahmedfgad ahmedfgad added the bug Something isn't working label Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants