Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion erddapy/erddapy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import (absolute_import, division, print_function)

import requests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rsignell-usgs if we leave this inside the function it would be to make it optional only when using get_var_by_attr.
In my next version requests will be mandatory , so instead of adding a try/except here I just moved it to the top already.


try:
from urllib.parse import quote_plus
except ImportError:
Expand Down Expand Up @@ -273,16 +275,20 @@ def get_var_by_attr(self, dataset_id, **kwargs):
['latitude', 'longitude', 'time', 'depth']

"""
from io import StringIO

try:
import pandas as pd

except ImportError:
raise ImportError('pandas is needed to use `get_var_by_attr`.')
info_url = self.get_info_url(dataset_id, response='csv')

# Creates the variables dictionary for the `get_var_by_attr` lookup.
if not self._variables or self._dataset_id != dataset_id:
variables = {}
_df = pd.read_csv(info_url)
r = requests.get(info_url, verify=True)
_df = pd.read_csv(StringIO(r.text))
self._dataset_id = dataset_id
for variable in set(_df['Variable Name']):
attributes = _df.loc[
Expand Down