Skip to content

Commit

Permalink
issue with repeatable iterator but only on OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
hugopendlebury committed Feb 21, 2024
1 parent a1d0988 commit 0ee2d7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
22 changes: 14 additions & 8 deletions src/gribreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,24 @@ optional<function<arrow::Result<shared_ptr<arrow::Array>>(shared_ptr<arrow::Arra
}

Iterator GribReader::begin() {
std::cout << "Creating iterator" << endl;
codes_handle* h = codes_handle_new_from_file(0, fin, PRODUCT_GRIB, &err);
auto m = new GribMessage(this, h, 0l);
return Iterator(this, m, m_endMessage);
if(isRepeatable) {
fseek(fin, 0, SEEK_SET);
}
if (!isExhausted || isRepeatable) {
std::cout << "Creating iterator" << endl;
codes_handle* h = codes_handle_new_from_file(0, fin, PRODUCT_GRIB, &err);
auto m = new GribMessage(this, h, 0l);
return Iterator(this, m, m_endMessage);
} else {
std::cout << "Iterator is exhausted returning end_message" << endl;
return Iterator( this, m_endMessage, m_endMessage );
}
}

Iterator GribReader::end() {

if (isRepeatable) {
std::cout << "At end of message and is repeatable" << endl;
fseek(fin, 0, SEEK_SET);
}
isExhausted = true;
std::cout << "At end of message and is not repeatable" << endl;
return Iterator( this, m_endMessage, m_endMessage );

}
Expand Down
1 change: 1 addition & 0 deletions src/gribreader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class GribReader
string filepath;
int err = 0;
bool isRepeatable = false;
bool isExhausted = false;
std::shared_ptr<arrow::Table> shared_locations;
arrow::Table* conversions = NULLPTR;
std::unordered_map<GridArea, std::shared_ptr<arrow::Table>> locations_in_area;
Expand Down
10 changes: 4 additions & 6 deletions tests/test_iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ def test_iterate_once(self, resource):
reader = GribReader(str(resource) + "/meps_weatherapi_sorlandet.grb")

cnt = self.get_iterator_count(reader)
assert cnt == 269
assert cnt == 268
cnt = self.get_iterator_count(reader)
assert cnt == 0

def test_iterate_once(self, resource):
def test_iterate_repeatable(self, resource):
from gribtoarrow import GribReader

reader = GribReader(str(resource) + "/meps_weatherapi_sorlandet.grb").withRepeatableIterator(True)

it = iter(reader)

cnt = self.get_iterator_count(reader)
assert cnt == 269
assert cnt == 268
cnt = self.get_iterator_count(reader)
assert cnt == 269
assert cnt == 268

0 comments on commit 0ee2d7d

Please sign in to comment.