Skip to content

Commit 88a736c

Browse files
committed
added conventions
1 parent a7d145e commit 88a736c

File tree

9 files changed

+22
-25
lines changed

9 files changed

+22
-25
lines changed

example_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from copy import copy
22
import pandas_to_sql
33
from pandas_to_sql.testing.utils.fake_data_creation import create_fake_dataset
4-
from pandas_to_sql.utils.helpers import flatten_grouped_dataframe
4+
from pandas_to_sql.conventions import flatten_grouped_dataframe
55

66
table_name = 'random_data'
77
df, _ = create_fake_dataset()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from pandas_to_sql.conventions.groupby_conventions import flatten_grouped_dataframe
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pandas as pd
2+
from pandas_to_sql.utils.pandas_dataframe_intercepter import PandasDataFrameIntercepter
3+
from copy import copy
4+
5+
def flatten_grouped_dataframe(df):
6+
if not isinstance(df, PandasDataFrameIntercepter):
7+
raise Exception(f"can only get type {str(type(PandasDataFrameIntercepter))}")
8+
9+
df_c = copy(df.df_pandas)
10+
if isinstance(df_c, pd.core.series.Series):
11+
series_name = df_c.name
12+
new_col_name = list(filter(lambda k: k.startswith(series_name), df.df_sql_convert_table.columns.keys()))[0]
13+
df_c = df_c.reset_index().rename(columns={series_name: new_col_name})
14+
else:
15+
df_c.columns = df_c.columns.map('_'.join)
16+
df_c = df_c.reset_index()
17+
return PandasDataFrameIntercepter(df_c, copy(df.df_sql_convert_table))

pandas_to_sql/testing/tests/test_concat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from pandas_to_sql.testing.utils.asserters import assert_
3-
from pandas_to_sql.utils.helpers import flatten_grouped_dataframe
3+
from pandas_to_sql.conventions import flatten_grouped_dataframe
44
from copy import copy
55
import pandas as pd
66
import pandas_to_sql

pandas_to_sql/testing/tests/test_datetime.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import timedelta, datetime
22
import pytest
33
from pandas_to_sql.testing.utils.asserters import assert_, get_expected_and_actual
4-
from pandas_to_sql.utils.helpers import flatten_grouped_dataframe
54
from copy import copy
65
import pandas as pd
76
import pandas_to_sql

pandas_to_sql/testing/tests/test_groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from pandas_to_sql.testing.utils.asserters import assert_
3-
from pandas_to_sql.utils.helpers import flatten_grouped_dataframe
3+
from pandas_to_sql.conventions import flatten_grouped_dataframe
44

55

66

pandas_to_sql/testing/tests/test_merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from pandas_to_sql.testing.utils.asserters import assert_
3-
from pandas_to_sql.utils.helpers import flatten_grouped_dataframe
3+
from pandas_to_sql.conventions import flatten_grouped_dataframe
44
from copy import copy
55

66

pandas_to_sql/testing/tests/test_str.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import timedelta, datetime
22
import pytest
33
from pandas_to_sql.testing.utils.asserters import assert_, get_expected_and_actual
4-
from pandas_to_sql.utils.helpers import flatten_grouped_dataframe
54
from copy import copy
65
import pandas as pd
76
import pandas_to_sql

pandas_to_sql/utils/helpers.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
11
import pandas as pd
2-
from pandas_to_sql.engine.table import Table
3-
from pandas_to_sql.engine.grouped_table import GroupedTable
4-
from pandas_to_sql.utils.pandas_dataframe_intercepter import PandasDataFrameIntercepter
5-
from copy import copy
6-
7-
## Conventions
8-
def flatten_grouped_dataframe(df):
9-
if not isinstance(df, PandasDataFrameIntercepter):
10-
raise Exception(f"can only get type {str(type(PandasDataFrameIntercepter))}")
11-
12-
df_c = copy(df.df_pandas)
13-
if isinstance(df_c, pd.core.series.Series):
14-
series_name = df_c.name
15-
new_col_name = list(filter(lambda k: k.startswith(series_name), df.df_sql_convert_table.columns.keys()))[0]
16-
df_c = df_c.reset_index().rename(columns={series_name: new_col_name})
17-
else:
18-
df_c.columns = df_c.columns.map('_'.join)
19-
df_c = df_c.reset_index()
20-
return PandasDataFrameIntercepter(df_c, copy(df.df_sql_convert_table))
212

223

234
## Types

0 commit comments

Comments
 (0)