Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

Calling birdnames.scientific() on already scientific names raised KeyError. When from_col == to_col, the Converter attempted to select the same column twice (df[[col, col]]), creating duplicate columns that failed during index lookup.

Changes

  • Identity mapping for same-type conversions: When from_col == to_col, use temporary column _temp_col to avoid duplicate column selection
  • Fix SettingWithCopyWarning: Add .copy() to DataFrame slices in Converter initialization
  • Test coverage: Add test_identity_conversion() and extend test_scientific() to verify same-type conversions

Example

import birdnames as bn

# Previously raised KeyError
scientific_names = ["Turdus migratorius", "Cardinalis cardinalis"]
result = bn.scientific(scientific_names)
# Now returns: ["Turdus migratorius", "Cardinalis cardinalis"]

# Also fixes Converter class directly
converter = bn.Converter(from_type="scientific_name", to_type="scientific_name")
converter.convert(scientific_names)  # Works correctly
Original prompt

This section details on the original issue you should resolve

<issue_title>using birdnames.scientific() on a list of already scientific names results in key error</issue_title>
<issue_description>using birdnames.scientific() on a list of already scientific names results in key error

This is probably because the scientific name is used as the lookup index, then it tries to map this to scientific name column (but there isn't one).

The conversion behavior should be: if mapping to scientific name of the same authority, and name is already scientific name, just return the input value</issue_description>

<agent_instructions>KISS. Make sure to address the root problem, which may not be in the "def scientific()" function but instead in an underlying function. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix key error in birdnames.scientific() for existing scientific names Fix KeyError when converting same type to same type (e.g., scientific → scientific) Nov 10, 2025
Copilot AI requested a review from sammlapp November 10, 2025 14:57
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.

using birdnames.scientific() on a list of already scientific names results in key error

2 participants