# Feat: Add get_metadata_schema Helper for Sample Metadata Introspection - #1124
# Feat: Add get_metadata_schema Helper for Sample Metadata Introspection#1124rajat552 wants to merge 4 commits into
get_metadata_schema Helper for Sample Metadata Introspection#1124Conversation
|
@jonbrenas Could you please review this PR? |
|
Thanks @rajat552. I think you have an interesting idea. However, this PR doesn't cover the first line of your stated problem at all (i.e., PCA and diversity stats) as it only applies to the sample metadata. I am pretty sure there are pandas functions that do most of what you are doing already. |
|
@jonbrenas You're right that the current implementation focuses on sample metadata rather than directly addressing PCA or diversity statistics. My intention with this PR was to introduce a small helper that exposes metadata schema information programmatically, which could serve as a building block for safer query construction. While pandas does provide similar functionality, exposing this through the API could help users and programmatic clients discover valid metadata fields and values before constructing queries. If you think this functionality should instead be implemented differently, or placed elsewhere in the API, I would be happy to adapt the implementation based on your suggestions. |
|
@jonbrenas I have pushed a commit to resolve the linting issues reported by CI. |
Description
The Problem
Currently, when constructing a
sample_queryto filter dataset metadata or analysis methods (like PCA or Diversity calculations), users (or programmatic clients like an LLM) have no straightforward programmatic way to know what columns are available or what the possible valid values are (e.g., discovering all uniquecountryortaxonvalues).The Solution
This PR introduces a small, non-breaking helper method
get_metadata_schema()to theAnophelesSampleMetadatamixin class. It programmatically introspects the sample metadata dataframe and exposes a dictionary of the schema.It automatically categorizes columns by parsing
df.columnsanddf.dtypesto build an intelligent dictionary mapping:typeas"categorical"and enumerates the possible"values"(e.g., fortaxon,country)."type": "string"."type": "numeric"and calculates the"min"and"max"bounds (e.g., foryear)."type": "boolean"and"values": [True, False].Closes #1123
Example Usage