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

Call fake.zipcode_in_state('AZ'), the return zipcode not valid AZ zip code #2011

Open
pengdada00100 opened this issue Mar 18, 2024 · 3 comments

Comments

@pengdada00100
Copy link

  • Faker version: 24.0
  • OS:Macos

Call fake.zipcode_in_state('AZ'), the return zipcode not valid AZ zip code

Steps to reproduce

Run code:
`from faker import Faker

if name == "main":
fake = Faker()
f = fake.zipcode_in_state('AZ')
print(f)`

get 85800 which not in AZ state

Expected behavior

The zip code should in AZ

Actual behavior

The zipcode not in AZ

@stefan6419846
Copy link
Contributor

The implementation is in

self.generator.random.randint(
self.states_postcode[state_abbr][0],
self.states_postcode[state_abbr][1],
)
)
Feel free to submit a corresponding PR.

@lozik4
Copy link
Contributor

lozik4 commented Mar 19, 2024

  • Faker version: 24.0
  • OS:Macos

Call fake.zipcode_in_state('AZ'), the return zipcode not valid AZ zip code

Steps to reproduce

Run code: `from faker import Faker

if name == "main": fake = Faker() f = fake.zipcode_in_state('AZ') print(f)`

get 85800 which not in AZ state

Expected behavior

The zip code should in AZ

Actual behavior

The zipcode not in AZ

@pengdada00100
You can add locale to your code
For example:

if __name__ == "__main__":
    fake = Faker("en_US") # add locale
    f = fake.zipcode_in_state('AZ')
    print(f)

@tonyk232
Copy link

tonyk232 commented Apr 6, 2024

I think this issue can be closed. The problem is that not all 5 digits are valid ZIP codes, and faker can't create valid ones without checking them from a database/API.

However, 85775 is Tucson, AZ and 85901 is Show Low, AZ, so the randomly created 85800 is in the correct range for AZ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants