Skip to content

added legal_balls to pokemon species from mariomaniac432's ball legality sheet - #1735

Open
cardtable wants to merge 1 commit into
PokeAPI:masterfrom
cardtable:feat/ball-legality
Open

cardtable wants to merge 1 commit into
PokeAPI:masterfrom
cardtable:feat/ball-legality

Conversation

@cardtable

@cardtable cardtable commented Nov 22, 2026 •

Copy link
Copy Markdown

Change description

Closes #1612 (Ball legality). This adds a legal_balls field to /api/v2/pokemon-species/{id}/, listing ball legality for all pokemons

Scope

Covers 24 balls: Poké, Great, Ultra, Premier, Nest, Repeat, Dive, Net, Timer, Luxury, Dusk, Heal, Quick, Safari, Sport, Fast, Friend, Heavy, Level, Love, Lure, Moon, Dream and Beast. Master Ball, Cherish Ball and the Legends Arceus balls are not included.

Data source & credit

The data comes from mariomaniac432's spreadsheet.
https://docs.google.com/spreadsheets/d/1jbYzsjuIIGtf7VFgIgV3NDgX4Ym_rXtW4qp-dHbLHbo

How to test

make test
make migrate && make build-db
make serve
curl http://localhost:8000/api/v2/pokemon-species/1/    # Bulbasaur: 24 balls
curl http://localhost:8000/api/v2/pokemon-species/803/

Test results

BallLegalityCSVDataIntegrityTestCase.test_ball_legality_rows checked that every species id exists in pokemon_species.csv, that every item is one of the 24 supported balls, that there are no duplicate rows, and that the file isn't empty.
APITests.test_pokemon_species_legal_balls checked that a species with no data returns [], that one species' balls don't appear on another, and that results are ordered by item id.
APITests.test_pokemon_species_api now also asserts the legal_balls names and URLs.

AI coding assistance disclosure

Used AI to decode the sheet's value codes and column order from its ReadMe and header images, writing the CSV conversion script, and flagging data issues.

Contributor check list

  • I have written a description of the contribution and explained its motivation.
  • I have written tests for my code changes (if applicable).
  • I have read and understood the AI Assisted Contribution guidelines.
  • I will own this change in production, and I am prepared to fix any bugs caused by my code change.

@Naramsim

Copy link
Copy Markdown
Member

Hi! just a quick question, currently you used the pokemon-species to link pokemons and balls.

is it correct? Should we use pokemons or pokemon-forms?

Example: Gumshoos. https://pokeapi.co/api/v2/pokemon-species/735/ we have two pokemon for it:

According to the chart you posted the two pokemons don have the same legality set:

Gumshoos 735 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Gumshoos (Totem) 735 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

@cardtable

Copy link
Copy Markdown
Author

Hi! just a quick question, currently you used the pokemon-species to link pokemons and balls.

is it correct? Should we use pokemons or pokemon-forms?

Example: Gumshoos. https://pokeapi.co/api/v2/pokemon-species/735/ we have two pokemon for it:

According to the chart you posted the two pokemons don have the same legality set:

Gumshoos 735 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Gumshoos (Totem) 735 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Thanks for the quick review! I used species on purpose. Couple reasons.

Although the spreadsheet has more precise information, for this feature I defined ball legality as "can this species exist in this ball, in any form, in any game", and combined the sheet's variant rows per species. "In any form" includes variants like Totem Gumshoos. I think this will make more sense to most users and avoid confusion. It also loses very little, because only 26 species have variants with different legality at all, and most of them are pretty obvious like pokeball only gifts.

Going with pokemon-form would be especially problematic. Someone checking Vivillon's legality would have to work out which of the 20 patterns they have, when 19 of them have identical legality anyway. Nobody's first instinct would be to look up vivillon-archipelago instead of just Vivillon.

Some technical issues as well. Right now, I just had to map the data by using the pokedex number. Going per pokemon would mean hand mapping sheet names to PokeAPI names ("Mega Venusaur" → venusaur-mega, "Nidoran♀" → nidoran-f) and writing rules for about 250 pokemon the sheet doesn't cover, like Megas, Gmax and battle forms. That leaves room for errors, and every future sheet update would need the mapping maintained too, which makes contributing harder as new games add more forms and strange ways to name pokemon.

However, if you think that one of the two would be a better idea, I'm happy to switch. Again it might be a difficult job in the future to integrate new data, but for now I should be able to build a working name map. In that case, should Megas, Gmax and battle-only forms be empty, or copy their base form's balls?

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

Successfully merging this pull request may close these issues.

Ball legality

2 participants