Skip to content

Commit

Permalink
Changes Requested
Browse files Browse the repository at this point in the history
  • Loading branch information
V1NAY8 committed Nov 16, 2020
1 parent 84a07c7 commit 9a88bb9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
20 changes: 13 additions & 7 deletions eland/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import pandas as pd # type: ignore
from elasticsearch import Elasticsearch
from elasticsearch.helpers import parallel_bulk
from pandas.core.config_init import is_terminal # type: ignore
from pandas.io.parsers import _c_parser_defaults # type: ignore
from tqdm.notebook import tqdm # type: ignore

Expand Down Expand Up @@ -218,7 +217,14 @@ def pandas_to_eland(

if show_progressbar is None or show_progressbar is True:
# Detect jupyter notebook
show_progressbar = False if is_terminal() else True
try:
from IPython import get_ipython

ip = get_ipython()
if hasattr(ip, "kernel"):
show_progressbar = True
except ImportError:
show_progressbar = False

def action_generator(
pd_df: pd.DataFrame,
Expand Down Expand Up @@ -260,11 +266,11 @@ def action_generator(
parallel_bulk(
client=es_client,
actions=action_generator(
pd_df,
es_dropna,
use_pandas_index_for_es_ids,
es_dest_index,
show_progressbar,
pd_df=pd_df,
es_dropna=es_dropna,
use_pandas_index_for_es_ids=use_pandas_index_for_es_ids,
es_dest_index=es_dest_index,
show_progressbar=show_progressbar,
),
thread_count=thread_count,
chunk_size=int(chunksize / thread_count),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
classifiers=CLASSIFIERS,
keywords="elastic eland pandas python",
packages=find_packages(include=["eland", "eland.*"]),
install_requires=["elasticsearch>=7.7", "pandas>=1", "matplotlib", "numpy"],
install_requires=["elasticsearch>=7.7", "pandas>=1", "matplotlib", "numpy", "tqdm"],
python_requires=">=3.6",
package_data={"eland": ["py.typed"]},
include_package_data=True,
Expand Down
4 changes: 3 additions & 1 deletion tests/etl/test_pandas_to_eland.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ def test_es_if_exists_fail(self):
"to 'append' or 'replace' data."
)

def test_es_if_exists_replace(self):
@pytest.mark.parametrize("show_progressbar", [True, False, None])
def test_es_if_exists_replace(self, show_progressbar):
# Assert that 'replace' allows for creation
df1 = pandas_to_eland(
pd_df2,
es_client=ES_TEST_CLIENT,
es_dest_index="test-index",
es_if_exists="replace",
es_refresh=True,
show_progressbar=show_progressbar,
).to_pandas()
assert_frame_equal(pd_df2, df1)

Expand Down
19 changes: 13 additions & 6 deletions tests/notebook/test_etl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"2020-10-28 16:20:43.614617: read 10000 rows\n",
"2020-10-28 16:20:44.276337: read 13059 rows\n"
"2020-11-17 00:02:17.869106: read 10000 rows\n",
"2020-11-17 00:02:18.873135: read 13059 rows\n"
]
}
],
Expand Down Expand Up @@ -80,7 +80,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2743ed058a8b44919ad4908f9cac0e95",
"model_id": "a1871aae58ca4aada70ab4df4e1b9673",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -238,7 +238,7 @@
{
"data": {
"text/plain": [
"{'took': 0,\n",
"{'took': 4,\n",
" 'timed_out': False,\n",
" '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},\n",
" 'hits': {'total': {'value': 2, 'relation': 'eq'},\n",
Expand Down Expand Up @@ -308,7 +308,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "97224e2219bf4d828739103324748fb2",
"model_id": "b70a238f828c41cd9ebbb1e74164b057",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -390,7 +390,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "37529288403e4db7b3ae8d97c8666d2e",
"model_id": "877234408b3d40f7af37b0bd9dec9c05",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -433,6 +433,13 @@
"source": [
"es.indices.delete(index='pandas_flights', ignore=[400, 404])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 9a88bb9

Please sign in to comment.