<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dask bag read_sequence(...).map(...).compute() returning ValueError: too many values to unpack (expected 2) in ArcGIS Notebooks Questions</title>
    <link>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1084661#M342</link>
    <description>&lt;P&gt;Hi Ahmad - could you show how 'itms' is being defined? The dask.Bag documentation doesn't list any size restrictions but it does however mention "&lt;SPAN&gt;This sequence should be relatively small in memory. Dask Bag works best when it handles loading your data itself.". It's also possible that Bag does not support a sequence of ArcGIS item objects.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.dask.org/en/latest/generated/dask.bag.from_sequence.html#dask.bag.from_sequence" target="_blank" rel="nofollow noopener noreferrer"&gt;https://docs.dask.org/en/latest/generated/dask.bag.from_sequence.html#dask.bag.from_sequence&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Josh&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jul 2021 23:32:07 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-07-30T23:32:07Z</dc:date>
    <item>
      <title>Dask bag read_sequence(...).map(...).compute() returning ValueError: too many values to unpack (expected 2)</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1084493#M340</link>
      <description>&lt;P&gt;Hello everyone,&lt;BR /&gt;I would appreciate it if you can help me of what is wrong in my code. I have a list of objects, specifically ArcGIS items.&amp;nbsp;My code is basically:&lt;/P&gt;&lt;DIV class="snippet-clipboard-content position-relative"&gt;&lt;PRE&gt;import dask.bag as db

def get_attribute(i):
    return i.title

bag = db.from_sequence(itms)
result = db.map(lambda x: get_attribute(x) , bag).compute()&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Then I am getting this error:&lt;/P&gt;&lt;P&gt;ValueError: too many values to unpack (expected 2)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I thought maybe dask bag does not work with sequences of objects. It might be only for sequences of literal values. But I tried the same code with objects based on a simple class called Point:&lt;/STRONG&gt;&lt;/P&gt;&lt;DIV class="snippet-clipboard-content position-relative"&gt;&lt;PRE&gt;class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def get_x(self):
        return self.x
    
    def get_y(self):
        return self.y
######################
######################
def get_x(p):
    return p.get_x()
    
p1 = Point(1,2)
p2 = Point(-3,-1)
p3 = Point(0,0)

pnts = [p1,p2,p3]

bag = db.from_sequence(pnts)
result = db.map(lambda x: get_x(x) , bag).compute()&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;STRONG&gt;And it is working fine!!&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So please let me know what I'am doing wrong.&lt;/P&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 16:52:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1084493#M340</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-30T16:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Dask bag read_sequence(...).map(...).compute() returning ValueError: too many values to unpack (expected 2)</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1084661#M342</link>
      <description>&lt;P&gt;Hi Ahmad - could you show how 'itms' is being defined? The dask.Bag documentation doesn't list any size restrictions but it does however mention "&lt;SPAN&gt;This sequence should be relatively small in memory. Dask Bag works best when it handles loading your data itself.". It's also possible that Bag does not support a sequence of ArcGIS item objects.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.dask.org/en/latest/generated/dask.bag.from_sequence.html#dask.bag.from_sequence" target="_blank" rel="nofollow noopener noreferrer"&gt;https://docs.dask.org/en/latest/generated/dask.bag.from_sequence.html#dask.bag.from_sequence&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Josh&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 23:32:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1084661#M342</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-30T23:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dask bag read_sequence(...).map(...).compute() returning ValueError: too many values to unpack (expected 2)</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1084665#M345</link>
      <description>&lt;P&gt;Hi Josh,&lt;/P&gt;&lt;P&gt;I basically created items using group.content() as a test of a small sample (9 items).&lt;/P&gt;&lt;P&gt;But in reality, I need to collect usage of last year, last 6 months, and last 60 days for 4K items. When I do so synchronously, it takes almost 1 minute per item, which means more than 2 days to finish 4K items.&lt;/P&gt;&lt;P&gt;This is the code snippet:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;import dask.bag as dbag
from arcgis.gis import GIS, Group
from datetime import datetime

# user defined function
# basically it returns a dictionary of usage metrics for each item
def get_usage_dct(i):
    today = datetime.now().strftime('%Y-%m-%d')
    i_usage_df_1y = i.usage(date_range='1Y', as_df=True)
    i_usage_df_1y = i_usage_df_1y[i_usage_df_1y['Date'] &amp;lt; today]
    i_usage_df_6m = i.usage(date_range='6M', as_df=True)
    i_usage_df_6m = i_usage_df_6m[i_usage_df_6m['Date'] &amp;lt; today]
    i_usage_df_2m = i.usage(date_range='60D', as_df=True)
    i_usage_df_2m = i_usage_df_2m[i_usage_df_2m['Date'] &amp;lt; today]
    return {'item_name':i.title,'usage_count_1Y':i_usage_df_1y['Usage'].sum(),'usage_count_6m':i_usage_df_6m['Usage'].sum(),'usage_count_2m':i_usage_df_2m['Usage'].sum()}

# define the GIS object
mapit = GIS("home")

# getting items of a specific group (9 items for this example)
g = Group(mapit,'xxxxxxxxx')
itms = g.content()

# create items bag from the itms list
itms_bag = dbag.from_sequence(itms, npartitions = 9)

# this line is causing the error
final_bag = dbag.map(lambda x: get_usage_dct(x), itms_bag).compute()&lt;/PRE&gt;&lt;P&gt;I then added the scheduler attribute in compute in the last line as:&lt;/P&gt;&lt;PRE&gt;final_bag = dbag.map(lambda x: get_usage_dct(x), itms_bag).&lt;SPAN&gt;compute(scheduler="threads")&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;But now it gave me&lt;/P&gt;&lt;PRE&gt;Exception: Too many requests. Please try again later.
(Error Code: 400)&lt;/PRE&gt;&lt;P&gt;Which I believe is related to API limits since the item usage method is basically an API call. Please correct me if I am wrong.&lt;/P&gt;&lt;P&gt;I hope you have a good advice &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 23:56:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1084665#M345</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-30T23:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dask bag read_sequence(...).map(...).compute() returning ValueError: too many values to unpack (expected 2)</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1088736#M347</link>
      <description>&lt;P&gt;Anyone?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 01:29:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/dask-bag-read-sequence-map-compute-returning/m-p/1088736#M347</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-13T01:29:39Z</dc:date>
    </item>
  </channel>
</rss>

