Skip to content

Commit

Permalink
OPAL-544 (#103)
Browse files Browse the repository at this point in the history
* created test to catch bug and fix
  • Loading branch information
AM-USAF committed Jul 1, 2024
1 parent c869bf5 commit e598033
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion weave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from .pantry_factory import create_pantry
from .mongo_loader import MongoLoader

__version__ = "1.9.3"

__version__ = "1.9.4"


__all__ = [
"Basket",
Expand Down
6 changes: 3 additions & 3 deletions weave/index/index_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ def generate_index(self, **kwargs):
----------
**kwargs unused for this function.
"""

if not isinstance(self.pantry_path, str):
raise TypeError("'pantry_path' must be a string: "
f"'{self.pantry_path}'")
Expand All @@ -265,8 +264,9 @@ def generate_index(self, **kwargs):
for basket_json_address in basket_jsons:
entry = create_index_from_fs(basket_json_address,
file_system=self.file_system)
if len(self.get_rows(entry['uuid'].iloc[0])) == 0:
self.track_basket(entry)
if not entry.empty:
if len(self.get_rows(entry['uuid'].iloc[0])) == 0:
self.track_basket(entry)

def to_pandas_df(self, max_rows=None, offset=0, **kwargs):
"""Returns the pandas dataframe representation of the index.
Expand Down
5 changes: 3 additions & 2 deletions weave/index/index_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ def generate_index(self, **kwargs):
for basket_json_address in basket_jsons:
entry = create_index_from_fs(basket_json_address,
file_system=self.file_system)
if len(self.get_rows(entry['uuid'].iloc[0])) == 0:
self.track_basket(entry, _commit_db=False)
if not entry.empty:
if len(self.get_rows(entry['uuid'].iloc[0])) == 0:
self.track_basket(entry, _commit_db=False)

self.con.commit()

Expand Down
25 changes: 25 additions & 0 deletions weave/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,3 +1897,28 @@ def test_read_only_generate_index(test_pantry):
os.remove(f"weave-{remove_path}.db")
if os.path.exists(f"weave-{read_only_pantry_path}.db"):
os.remove(f"weave-{read_only_pantry_path}.db")


def test_generate_index_when_pandas_index_exists(test_pantry):
"""Test that there is no error when calling generate_index() with any index
when there is an existing Pandas index.
"""
test_pantry, ind = test_pantry
# Create a pandas index
pantry = Pantry(IndexPandas,
pantry_path=test_pantry.pantry_path,
file_system=test_pantry.file_system,
sync=True,
)
pantry.index.generate_index()
# Create other index to generate index for test
pantry2 = Pantry(type(ind),
pantry_path=test_pantry.pantry_path,
file_system=test_pantry.file_system,
sync=True,
)
# Generate the index; test fails if IndexError is thrown
try:
pantry2.index.generate_index()
except IndexError:
assert False

0 comments on commit e598033

Please sign in to comment.