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

UnboundLocalError Returned for dataframe filters that have no results #56

Closed
blaklaybul opened this issue Nov 19, 2019 · 1 comment · Fixed by #57
Closed

UnboundLocalError Returned for dataframe filters that have no results #56

blaklaybul opened this issue Nov 19, 2019 · 1 comment · Fixed by #57
Assignees
Labels
bug Something isn't working

Comments

@blaklaybul
Copy link
Contributor

blaklaybul commented Nov 19, 2019

If the query returns no results, the following Exception is thrown. This should result in returning an empty dataframe.

eland

>>> df2 = ed.read_es('localhost:9200', 'ecommerce')
>>> df2[df2['currency']=='USD']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/michael/projects/eland/eland/dataframe.py", line 273, in __repr__
    line_width=width, show_dimensions=show_dimensions)
  File "/Users/michael/projects/eland/eland/dataframe.py", line 662, in to_string
    line_width=line_width)
  File "/Users/michael/projects/eland/venv/lib/python3.7/site-packages/pandas/core/frame.py", line 759, in to_string
    line_width=line_width,
  File "/Users/michael/projects/eland/venv/lib/python3.7/site-packages/pandas/io/formats/format.py", line 502, in __init__
    self._chk_truncate()
  File "/Users/michael/projects/eland/venv/lib/python3.7/site-packages/pandas/io/formats/format.py", line 525, in _chk_truncate
    n_add_rows = self.header + dot_row + show_dimension_rows + prompt_row
UnboundLocalError: local variable 'show_dimension_rows' referenced before assignment

pandas

>>> pdf = ed.eland_to_pandas(df2)
>>> pdf[pdf['currency']=='USD']
Empty DataFrame
Columns: [category, currency, customer_birth_date, customer_first_name, customer_full_name, customer_gender, customer_id, customer_last_name, customer_phone, day_of_week, day_of_week_i, email, geoip.city_name, geoip.continent_name, geoip.country_iso_code, geoip.location, geoip.region_name, manufacturer, order_date, order_id, products._id, products.base_price, products.base_unit_price, products.category, products.created_on, products.discount_amount, products.discount_percentage, products.manufacturer, products.min_price, products.price, products.product_id, products.product_name, products.quantity, products.sku, products.tax_amount, products.taxful_price, products.taxless_price, products.unit_discount_amount, sku, taxful_total_price, taxless_total_price, total_quantity, total_unique_products, type, user]
Index: []
@blaklaybul blaklaybul added the bug Something isn't working label Nov 19, 2019
@blaklaybul blaklaybul self-assigned this Nov 19, 2019
@blaklaybul
Copy link
Contributor Author

this is a nasty bug that results from https://github.com/pandas-dev/pandas/blob/547f128eff607479c0fcda4b363595303b6272c8/pandas/io/formats/format.py#L620.

Essentially, when we encounter an empty dataframe, we pass max_rows=0 over to pandas formatting. Since we handle printing dimensions in eland, we also initially pass show_dimensions=False. This combination results in unexpected behavior in pandas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant