# response.SDAResponse { #soildb.response.SDAResponse }

```python
response.SDAResponse(raw_data)
```

Represents a response from the Soil Data Access web service.

## Attributes

| Name | Description |
| --- | --- |
| [columns](#soildb.response.SDAResponse.columns) | Get column names. |
| [data](#soildb.response.SDAResponse.data) | Get raw data rows. |
| [data_quality_score](#soildb.response.SDAResponse.data_quality_score) | Get the data quality score (0.0 to 1.0). |
| [has_warnings](#soildb.response.SDAResponse.has_warnings) | Check if the response has any validation warnings. |
| [is_valid](#soildb.response.SDAResponse.is_valid) | Check if the response passed validation (no errors). |
| [metadata](#soildb.response.SDAResponse.metadata) | Get column metadata. |
| [validation_result](#soildb.response.SDAResponse.validation_result) | Get the validation result for this response. |

## Methods

| Name | Description |
| --- | --- |
| [find_fallback_columns](#soildb.response.SDAResponse.find_fallback_columns) | Find fallback column names when preferred columns are not available. |
| [from_json](#soildb.response.SDAResponse.from_json) | Create response from JSON string. |
| [get_column_types](#soildb.response.SDAResponse.get_column_types) | Extract column data types from metadata. |
| [get_python_types](#soildb.response.SDAResponse.get_python_types) | Get Python-compatible type mapping. |
| [get_validation_summary](#soildb.response.SDAResponse.get_validation_summary) | Get a summary of validation results. |
| [handle_missing_fields](#soildb.response.SDAResponse.handle_missing_fields) | Handle missing required fields with fallbacks or defaults. |
| [is_empty](#soildb.response.SDAResponse.is_empty) | Check if the response contains any data rows. |
| [recover_partial_data](#soildb.response.SDAResponse.recover_partial_data) | Attempt to recover partial data by skipping malformed records. |
| [to_dataframe](#soildb.response.SDAResponse.to_dataframe) | Convert to pandas or polars DataFrame with proper type conversion. |
| [to_dict](#soildb.response.SDAResponse.to_dict) | Convert to list of dictionaries with basic type conversion and error recovery. |
| [to_geodataframe](#soildb.response.SDAResponse.to_geodataframe) | Convert to GeoPandas GeoDataFrame if geometry column exists. |
| [to_pandas](#soildb.response.SDAResponse.to_pandas) | Convert to pandas DataFrame with proper type conversion. |
| [to_polars](#soildb.response.SDAResponse.to_polars) | Convert to polars DataFrame with proper type conversion. |
| [to_records](#soildb.response.SDAResponse.to_records) | Alias for to_dict() for compatibility. |
| [to_soilprofilecollection](#soildb.response.SDAResponse.to_soilprofilecollection) | Converts the response data to a soilprofilecollection.SoilProfileCollection object. |
| [validate_mapunit_response](#soildb.response.SDAResponse.validate_mapunit_response) | Validate a mapunit response for required fields and data integrity. |
| [validate_pedon_response](#soildb.response.SDAResponse.validate_pedon_response) | Validate a pedon response for required fields and data integrity. |
| [validate_response](#soildb.response.SDAResponse.validate_response) | Validate the response for common issues and return detailed results. |
| [validate_transformed_data](#soildb.response.SDAResponse.validate_transformed_data) | Validate transformed data dictionaries for consistency and data quality. |

### find_fallback_columns { #soildb.response.SDAResponse.find_fallback_columns }

```python
response.SDAResponse.find_fallback_columns(
    available_columns,
    preferred_columns,
    fallback_mappings=None,
)
```

Find fallback column names when preferred columns are not available.

Args:
    available_columns: List of columns actually present in the data
    preferred_columns: List of preferred column names
    fallback_mappings: Optional mapping of preferred -> [fallback1, fallback2, ...]

Returns:
    Dictionary mapping preferred column names to available fallback names

### from_json { #soildb.response.SDAResponse.from_json }

```python
response.SDAResponse.from_json(json_str)
```

Create response from JSON string.

### get_column_types { #soildb.response.SDAResponse.get_column_types }

```python
response.SDAResponse.get_column_types()
```

Extract column data types from metadata.

### get_python_types { #soildb.response.SDAResponse.get_python_types }

```python
response.SDAResponse.get_python_types()
```

Get Python-compatible type mapping.

### get_validation_summary { #soildb.response.SDAResponse.get_validation_summary }

```python
response.SDAResponse.get_validation_summary()
```

Get a summary of validation results.

### handle_missing_fields { #soildb.response.SDAResponse.handle_missing_fields }

```python
response.SDAResponse.handle_missing_fields(
    data,
    required_fields,
    fallback_values=None,
)
```

Handle missing required fields with fallbacks or defaults.

Args:
    data: The data dictionary to check
    required_fields: List of field names that must be present
    fallback_values: Optional mapping of field names to fallback values

Returns:
    Tuple of (processed_data, missing_fields_list)

### is_empty { #soildb.response.SDAResponse.is_empty }

```python
response.SDAResponse.is_empty()
```

Check if the response contains any data rows.

### recover_partial_data { #soildb.response.SDAResponse.recover_partial_data }

```python
response.SDAResponse.recover_partial_data(max_errors=10)
```

Attempt to recover partial data by skipping malformed records.

Args:
    max_errors: Maximum number of errors to tolerate before giving up

Returns:
    Tuple of (valid_records, error_records)

### to_dataframe { #soildb.response.SDAResponse.to_dataframe }

```python
response.SDAResponse.to_dataframe(library='pandas', convert_types=True)
```

Convert to pandas or polars DataFrame with proper type conversion.

### to_dict { #soildb.response.SDAResponse.to_dict }

```python
response.SDAResponse.to_dict()
```

Convert to list of dictionaries with basic type conversion and error recovery.

Returns:
    List of dictionaries where each dictionary represents a row with
    column names as keys and converted values as values.

### to_geodataframe { #soildb.response.SDAResponse.to_geodataframe }

```python
response.SDAResponse.to_geodataframe(convert_types=True)
```

Convert to GeoPandas GeoDataFrame if geometry column exists.

### to_pandas { #soildb.response.SDAResponse.to_pandas }

```python
response.SDAResponse.to_pandas(convert_types=True)
```

Convert to pandas DataFrame with proper type conversion.

### to_polars { #soildb.response.SDAResponse.to_polars }

```python
response.SDAResponse.to_polars(convert_types=True)
```

Convert to polars DataFrame with proper type conversion.

### to_records { #soildb.response.SDAResponse.to_records }

```python
response.SDAResponse.to_records()
```

Alias for to_dict() for compatibility.

### to_soilprofilecollection { #soildb.response.SDAResponse.to_soilprofilecollection }

```python
response.SDAResponse.to_soilprofilecollection(
    site_data=None,
    site_id_col='cokey',
    hz_id_col='chkey',
    hz_top_col='hzdept_r',
    hz_bot_col='hzdepb_r',
)
```

Converts the response data to a soilprofilecollection.SoilProfileCollection object.

This method is intended for horizon-level data, which can be joined with
site-level data (e.g., from the component table) to form a complete
soil profile collection.

Args:
    site_data: Optional pandas DataFrame containing site-level data.
        This will be joined with the horizon data.
    site_id_col: The name of the site ID column, used to link site and
        horizon data (default: "cokey").
    hz_id_col: The name of the unique horizon ID column (default: "chkey").
    hz_top_col: The name of the horizon top depth column (default: "hzdept_r").
    hz_bot_col: The name of the horizon bottom depth column (default: "hzdepb_r").

Returns:
    A SoilProfileCollection object.

Raises:
    ImportError: If the 'soilprofilecollection' package is not installed.
    ValueError: If required columns for creating the SoilProfileCollection
        are missing from the data.

### validate_mapunit_response { #soildb.response.SDAResponse.validate_mapunit_response }

```python
response.SDAResponse.validate_mapunit_response(response_data)
```

Validate a mapunit response for required fields and data integrity.

### validate_pedon_response { #soildb.response.SDAResponse.validate_pedon_response }

```python
response.SDAResponse.validate_pedon_response(response_data)
```

Validate a pedon response for required fields and data integrity.

### validate_response { #soildb.response.SDAResponse.validate_response }

```python
response.SDAResponse.validate_response()
```

Validate the response for common issues and return detailed results.

### validate_transformed_data { #soildb.response.SDAResponse.validate_transformed_data }

```python
response.SDAResponse.validate_transformed_data(data_dicts)
```

Validate transformed data dictionaries for consistency and data quality.

Args:
    data_dicts: List of dictionaries from to_dict() conversion

Returns:
    ValidationResult with data quality assessment