It appears that this behavior happens because it's the "last batch" and the APICache callback expects that the file already exists at that point.
/opt/conda/lib/python3.7/site-packages/phc/easy/procedure.py in get_data_frame(all_results, raw, patient_id, query_overrides, auth_args, ignore_cache, expand_args)
96 query_overrides,
97 auth_args,
---> 98 ignore_cache,
99 )
/opt/conda/lib/python3.7/site-packages/phc/easy/query/__init__.py in execute_fhir_dsl_with_options(query, transform, all_results, raw, query_overrides, auth_args, ignore_cache)
157 auth_args,
158 callback=APICache.build_cache_fhir_dsl_callback(
--> 159 query, transform
160 ),
161 )
/opt/conda/lib/python3.7/site-packages/phc/easy/query/__init__.py in execute_fhir_dsl(query, all_results, auth_args, callback)
110 return with_progress(
111 lambda: tqdm(total=MAX_RESULT_SIZE),
--> 112 lambda progress: recursive_execute_fhir_dsl(
113 {
114 "limit": [
/opt/conda/lib/python3.7/site-packages/phc/easy/query/fhir_dsl.py in with_progress(init_progress, func)
20 if _has_tqdm:
21 progress = init_progress()
---> 22 result = func(progress)
23 progress.close()
24 return result
/opt/conda/lib/python3.7/site-packages/phc/easy/query/__init__.py in <lambda>(progress)
126 progress=progress,
127 callback=callback,
--> 128 auth_args=auth_args,
129 ),
130 )
/opt/conda/lib/python3.7/site-packages/phc/easy/query/fhir_dsl.py in recursive_execute_fhir_dsl(query, scroll, progress, auth_args, callback, _scroll_id, _prev_hits)
72 callback(current_results, False)
73 elif callback and is_last_batch:
---> 74 return callback(current_results, True)
75 elif is_last_batch:
76 suffix = "+" if actual_count == MAX_RESULT_SIZE else ""
/opt/conda/lib/python3.7/site-packages/phc/util/api_cache.py in handle_batch(batch, is_finished)
76 if is_finished:
77 print(f'Loading data frame from "{filename}"')
---> 78 return APICache.read_csv(filename)
79
80 df = pd.DataFrame(map(lambda r: r["_source"], batch))
/opt/conda/lib/python3.7/site-packages/phc/util/api_cache.py in read_csv(filename)
85 @staticmethod
86 def read_csv(filename: str) -> pd.DataFrame:
---> 87 df = pd.read_csv(filename)
88 min_count = max(min(int(len(df) / 3), 5), 1)
89
/opt/conda/lib/python3.7/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
674 )
675
--> 676 return _read(filepath_or_buffer, kwds)
677
678 parser_f.__name__ = name
/opt/conda/lib/python3.7/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
446
447 # Create the parser.
--> 448 parser = TextFileReader(fp_or_buf, **kwds)
449
450 if chunksize or iterator:
/opt/conda/lib/python3.7/site-packages/pandas/io/parsers.py in __init__(self, f, engine, **kwds)
878 self.options["has_index_names"] = kwds["has_index_names"]
879
--> 880 self._make_engine(self.engine)
881
882 def close(self):
/opt/conda/lib/python3.7/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
1112 def _make_engine(self, engine="c"):
1113 if engine == "c":
-> 1114 self._engine = CParserWrapper(self.f, **self.options)
1115 else:
1116 if engine == "python":
/opt/conda/lib/python3.7/site-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
1889 kwds["usecols"] = self.usecols
1890
-> 1891 self._reader = parsers.TextReader(src, **kwds)
1892 self.unnamed_cols = self._reader.unnamed_cols
1893
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()
FileNotFoundError: [Errno 2] File ~/Downloads/phc/api-cache/fhir_dsl_procedure_where_********.csv does not exist: '~/Downloads/phc/api-cache/fhir_dsl_procedure_where_********.csv'