Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benedict throws "unexpected keyword argument 'keypath_separator'" #230

Closed
adacable opened this issue Apr 10, 2023 · 3 comments
Closed

Benedict throws "unexpected keyword argument 'keypath_separator'" #230

adacable opened this issue Apr 10, 2023 · 3 comments

Comments

@adacable
Copy link

This was a clean install, using the tutorial as a base.

Google isn't giving me anything, I'm wondering if a dependancy has moved somewhere?

search_period = datetime.timedelta(days=20)
start_date = datetime.datetime.now() - search_period - datetime.timedelta(days=1)
end_date = datetime.datetime.now() - datetime.timedelta(days=1)

# Define the bounding box using the lat/long coordinates
bbox = (long1, lat1, long2, lat2)

time = '{}T00:00:00Z/{}T23:59:59Z'.format(start_date.strftime('%Y-%m-%d'), end_date.strftime('%Y-%m-%d')),
Query = earthaccess.collection_query()


Query.keyword('SAR').bounding_box(long1, lat1, long2, lat2).temporal(start_date.strftime('%Y-%m-%d'),end_date.strftime('%Y-%m-%d'))
print(f'Collections found: {Query.hits()}')
collections = Query.fields(['ShortName','Version'])

This throws the error:


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[38], line 1
----> 1 collections.get(10)

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/earthaccess/search.py:247, in DataCollections.get(self, limit)
    245     latest = response.json()["feed"]["entry"]
    246 elif self._format == "umm_json":
--> 247     latest = list(
    248         DataCollection(collection, self._fields)
    249         for collection in response.json()["items"]
    250     )
    251 else:
    252     latest = [response.text]

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/earthaccess/search.py:248, in <genexpr>(.0)
    245     latest = response.json()["feed"]["entry"]
    246 elif self._format == "umm_json":
    247     latest = list(
--> 248         DataCollection(collection, self._fields)
    249         for collection in response.json()["items"]
    250     )
    251 else:
    252     latest = [response.text]

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/earthaccess/results.py:20, in CustomDict.__init__(self, collection, fields, cloud_hosted)
     14 def __init__(
     15     self,
     16     collection: Dict[str, Any],
     17     fields: Optional[List[str]] = None,
     18     cloud_hosted: bool = False,
     19 ):
---> 20     super().__init__(collection)
     21     self.cloud_hosted = cloud_hosted
     22     self.uuid = str(uuid.uuid4())

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/benedict/dicts/__init__.py:50, in benedict.__init__(self, *args, **kwargs)
     48     super().__init__(obj.dict(), **kwargs)
     49     return
---> 50 super().__init__(*args, **kwargs)

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/benedict/dicts/keypath/keypath_dict.py:14, in KeypathDict.__init__(self, *args, **kwargs)
     12 super().__init__(*args, **kwargs)
     13 if check_keys:
---> 14     keypath_util.check_keys(self, self._keypath_separator)

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/benedict/dicts/keypath/keypath_util.py:22, in check_keys(d, separator)
     17     if key and type_util.is_string(key) and separator in key:
     18         raise ValueError(
     19             f"Key should not contain keypath separator '{separator}', found: '{key}'."
     20         )
---> 22 traverse(d, check_key)

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/benedict/core/traverse.py:29, in traverse(d, callback)
     27 if not callable(callback):
     28     raise ValueError("callback argument must be a callable.")
---> 29 _traverse_collection(d, callback)

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/benedict/core/traverse.py:6, in _traverse_collection(d, callback)
      4 def _traverse_collection(d, callback):
      5     if type_util.is_dict(d):
----> 6         _traverse_dict(d, callback)
      7     elif type_util.is_list_or_tuple(d):
      8         _traverse_list(d, callback)

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/benedict/core/traverse.py:14, in _traverse_dict(d, callback)
     12 keys = list(d.keys())
     13 for key in keys:
---> 14     value = d.get(key, None)
     15     callback(d, key, value)
     16     _traverse_collection(value, callback)

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/benedict/dicts/__init__.py:140, in benedict.get(self, key, default)
    139 def get(self, key, default=None):
--> 140     return self._cast(super().get(key, default))

File ~/.pyenv/versions/3.9.16/lib/python3.9/site-packages/benedict/dicts/__init__.py:69, in benedict._cast(self, value)
     67 obj_type = type(self)
     68 if isinstance(value, dict) and not isinstance(value, obj_type):
---> 69     return obj_type(
     70         value, keypath_separator=self._keypath_separator, check_keys=False
     71     )
     72 return value

TypeError: __init__() got an unexpected keyword argument 'keypath_separator'

here's the full dependancy tree:

earthaccess==0.5.1
  - fsspec [required: >=2022.1, installed: 2023.4.0]
  - multimethod [required: >=1.8, installed: 1.9.1]
  - pqdm [required: >=0.1, installed: 0.2.0]
    - bounded-pool-executor [required: Any, installed: 0.0.3]
    - tqdm [required: Any, installed: 4.65.0]
    - typing-extensions [required: Any, installed: 4.5.0]
  - python-benedict [required: >=0.25,<0.28.3, installed: 0.28.2]
    - boto3 [required: >=1.24.89,<2.0.0, installed: 1.26.76]
      - botocore [required: >=1.29.76,<1.30.0, installed: 1.29.76]
        - jmespath [required: >=0.7.1,<2.0.0, installed: 1.0.1]
        - python-dateutil [required: >=2.1,<3.0.0, installed: 2.8.2]
          - six [required: >=1.5, installed: 1.16.0]
        - urllib3 [required: >=1.25.4,<1.27, installed: 1.26.15]
      - jmespath [required: >=0.7.1,<2.0.0, installed: 1.0.1]
      - s3transfer [required: >=0.6.0,<0.7.0, installed: 0.6.0]
        - botocore [required: >=1.12.36,<2.0a.0, installed: 1.29.76]
          - jmespath [required: >=0.7.1,<2.0.0, installed: 1.0.1]
          - python-dateutil [required: >=2.1,<3.0.0, installed: 2.8.2]
            - six [required: >=1.5, installed: 1.16.0]
          - urllib3 [required: >=1.25.4,<1.27, installed: 1.26.15]
    - ftfy [required: >=6.0.0,<7.0.0, installed: 6.1.1]
      - wcwidth [required: >=0.2.5, installed: 0.2.6]
    - mailchecker [required: >=4.1.0,<6.0.0, installed: 5.0.8]
    - openpyxl [required: >=3.0.0,<4.0.0, installed: 3.1.2]
      - et-xmlfile [required: Any, installed: 1.1.0]
    - phonenumbers [required: >=8.12.0,<9.0.0, installed: 8.13.8]
    - python-dateutil [required: >=2.8.0,<3.0.0, installed: 2.8.2]
      - six [required: >=1.5, installed: 1.16.0]
    - python-fsutil [required: >=0.9.2,<1.0.0, installed: 0.10.0]
    - python-slugify [required: >=6.0.1,<8.0.0, installed: 7.0.0]
      - text-unidecode [required: >=1.3, installed: 1.3]
    - pyyaml [required: >=6.0,<7.0, installed: 6.0]
    - requests [required: >=2.26.0,<3.0.0, installed: 2.28.2]
      - certifi [required: >=2017.4.17, installed: 2022.12.7]
      - charset-normalizer [required: >=2,<4, installed: 3.1.0]
      - idna [required: >=2.5,<4, installed: 3.4]
      - urllib3 [required: >=1.21.1,<1.27, installed: 1.26.15]
    - toml [required: >=0.10.2,<1.0.0, installed: 0.10.2]
    - xlrd [required: >=2.0.0,<3.0.0, installed: 2.0.1]
    - xmltodict [required: >=0.12.0,<1.0.0, installed: 0.13.0]
  - python-cmr [required: >=0.7, installed: 0.7.0]
    - requests [required: >=2.26.0,<3.0.0, installed: 2.28.2]
      - certifi [required: >=2017.4.17, installed: 2022.12.7]
      - charset-normalizer [required: >=2,<4, installed: 3.1.0]
      - idna [required: >=2.5,<4, installed: 3.4]
      - urllib3 [required: >=1.21.1,<1.27, installed: 1.26.15]
  - requests [required: >=2.26,<3.0.0, installed: 2.28.2]
    - certifi [required: >=2017.4.17, installed: 2022.12.7]
    - charset-normalizer [required: >=2,<4, installed: 3.1.0]
    - idna [required: >=2.5,<4, installed: 3.4]
    - urllib3 [required: >=1.21.1,<1.27, installed: 1.26.15]
  - s3fs [required: >=2021.11,<2024, installed: 2023.4.0]
    - aiobotocore [required: ~=2.5.0, installed: 2.5.0]
      - aiohttp [required: >=3.3.1, installed: 3.8.4]
        - aiosignal [required: >=1.1.2, installed: 1.3.1]
          - frozenlist [required: >=1.1.0, installed: 1.3.3]
        - async-timeout [required: >=4.0.0a3,<5.0, installed: 4.0.2]
        - attrs [required: >=17.3.0, installed: 22.2.0]
        - charset-normalizer [required: >=2.0,<4.0, installed: 3.1.0]
        - frozenlist [required: >=1.1.1, installed: 1.3.3]
        - multidict [required: >=4.5,<7.0, installed: 6.0.4]
        - yarl [required: >=1.0,<2.0, installed: 1.8.2]
          - idna [required: >=2.0, installed: 3.4]
          - multidict [required: >=4.0, installed: 6.0.4]
      - aioitertools [required: >=0.5.1, installed: 0.11.0]
        - typing-extensions [required: >=4.0, installed: 4.5.0]
      - botocore [required: >=1.29.76,<1.29.77, installed: 1.29.76]
        - jmespath [required: >=0.7.1,<2.0.0, installed: 1.0.1]
        - python-dateutil [required: >=2.1,<3.0.0, installed: 2.8.2]
          - six [required: >=1.5, installed: 1.16.0]
        - urllib3 [required: >=1.25.4,<1.27, installed: 1.26.15]
      - wrapt [required: >=1.10.10, installed: 1.14.1]
    - aiohttp [required: !=4.0.0a1,!=4.0.0a0, installed: 3.8.4]
      - aiosignal [required: >=1.1.2, installed: 1.3.1]
        - frozenlist [required: >=1.1.0, installed: 1.3.3]
      - async-timeout [required: >=4.0.0a3,<5.0, installed: 4.0.2]
      - attrs [required: >=17.3.0, installed: 22.2.0]
      - charset-normalizer [required: >=2.0,<4.0, installed: 3.1.0]
      - frozenlist [required: >=1.1.1, installed: 1.3.3]
      - multidict [required: >=4.5,<7.0, installed: 6.0.4]
      - yarl [required: >=1.0,<2.0, installed: 1.8.2]
        - idna [required: >=2.0, installed: 3.4]
        - multidict [required: >=4.0, installed: 6.0.4]
    - fsspec [required: ==2023.4.0, installed: 2023.4.0]
  - tinynetrc [required: >=1.3.1,<2.0.0, installed: 1.3.1]
 
@betolink
Copy link
Member

@adacable I couldn't reproduce the error but for what it's worth, we are moving away from benedict.
Here is the code I ran:

import datetime 
import earthaccess


search_period = datetime.timedelta(days=20)
start_date = datetime.datetime.now() - search_period - datetime.timedelta(days=1)
end_date = datetime.datetime.now() - datetime.timedelta(days=1)

Query = earthaccess.collection_query()

Query.keyword('SAR').temporal(start_date.strftime('%Y-%m-%d'),end_date.strftime('%Y-%m-%d'))

print(f'Collections found: {Query.hits()}')

collections = Query.fields(['ShortName','version']).get()
collections

And here are some of the results:

[{
   "meta": {
     "concept-id": "C1214353986-ASF",
     "granule-count": 0,
     "provider-id": "ASF"
   },
   "umm": {
     "ShortName": "UAVSAR_POL_META"
   }
 },
 {
   "meta": {
     "concept-id": "C1214336045-ASF",
     "granule-count": 0,
     "provider-id": "ASF"
   },
   "umm": {
     "ShortName": "UAVSAR_INSAR_INT"
   }
 },
 {
   "meta": {
     "concept-id": "C1214336717-ASF",
     "granule-count": 0,
     "provider-id": "ASF"
   },
   "umm": {
     "ShortName": "UAVSAR_INSAR_META"
   }
 },
 {
   "meta": {
     "concept-id": "C1214335430-ASF",
     "granule-count": 0,
     "provider-id": "ASF"
   },
   "umm": {
     "ShortName": "UAVSAR_INSAR_AMP"
   }
 }]

Can you try installing the library from source and see if this keeps happening?

pip install git+https://github.com/nsidc/earthaccess.git@main

also note that in order to download the granules (or opening them) we need an account with NASA Earthdata and another line with

earthdata.login()

@psarka
Copy link
Contributor

psarka commented Apr 20, 2023

We are hitting this issue too, and installing from the main works. Maybe you could make a new release? 🙏

@betolink
Copy link
Member

this was fixed on the last release, closing it!

@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in earthaccess project Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants