Skip to content

Commit

Permalink
Add support to pandas 2
Browse files Browse the repository at this point in the history
  • Loading branch information
alifbe committed Nov 14, 2023
1 parent aeb0953 commit f5b197c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ecl2df.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
pandas-version: ['<2', '>2']
include:
# For one of the Python versions we
# install the extra dependency ert
Expand All @@ -44,6 +45,7 @@ jobs:
run: |
pip install --upgrade pip
pip install .
pip install "pandas${{matrix.pandas-version}}"
python -c "import ecl2df"
- name: Install ert
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ docs/ecl2df.rst
ecl2df/version.py
\#*
.\#*
venv*
build
2 changes: 1 addition & 1 deletion ecl2df/compdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def applywelopen(
new_state["KEYWORD_IDX"] = row["KEYWORD_IDX"]
new_state["DATE"] = row["DATE"]

compdat_df = compdat_df.append(new_state)
compdat_df = pd.concat([compdat_df, new_state], ignore_index=True)

if not compdat_df.empty:
compdat_df = (
Expand Down
2 changes: 1 addition & 1 deletion ecl2df/gruptree.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def prettyprint(dframe: pd.DataFrame) -> str:
output = ""
for date in dframe["DATE"].dropna().unique():
df_date = dframe[dframe.DATE == date]
output += "Date: " + str(date.astype("M8[D]")) + "\n"
output += "Date: " + pd.to_datetime(date).strftime("%Y-%m-%d") + "\n"

for treetype in ["GRUPTREE", "BRANPROP"]:
if treetype in df_date["KEYWORD"].unique():
Expand Down
10 changes: 5 additions & 5 deletions ecl2df/rft.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,15 @@ def merge_icd_seg_conseg(

if logger.level <= logging.DEBUG:
logger.debug("Writing connection data to con.csv")
con_data[CON_TOPOLOGY_COLS.intersection(con_data.columns)].to_csv(
con_data[list(CON_TOPOLOGY_COLS.intersection(con_data.columns))].to_csv(
"con.csv", index=False
)
logger.debug("Writing segment data to seg.csv")
seg_data[SEG_TOPOLOGY_COLS.intersection(seg_data.columns)].to_csv(
seg_data[list(SEG_TOPOLOGY_COLS.intersection(seg_data.columns))].to_csv(
"seg.csv", index=False
)
logger.debug("Writing ICD data to icd.csv")
icd_data[ICD_TOPOLOGY_COLS.intersection(icd_data.columns)].to_csv(
icd_data[list(ICD_TOPOLOGY_COLS.intersection(icd_data.columns))].to_csv(
"icd.csv", index=False
)

Expand All @@ -445,7 +445,7 @@ def merge_icd_seg_conseg(
# Gather connections that are not associated to ICDs:
no_icd_con_segments = set(con_data["CONSEGNO"]) - set(icd_data["ICD_SEGIDX"])
con_data_no_icd = (
con_data.set_index("CONSEGNO").loc[no_icd_con_segments].reset_index()
con_data.set_index("CONSEGNO").loc[list(no_icd_con_segments)].reset_index()
)
else:
con_data_no_icd = con_data
Expand Down Expand Up @@ -614,7 +614,7 @@ def df(
"ICD_LONELYSEG",
}
)
con_icd_seg = con_icd_seg[set(con_icd_seg.columns) - delete_cols]
con_icd_seg = con_icd_seg[list(set(con_icd_seg.columns) - delete_cols)]

rftdata.append(con_icd_seg)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ecl",
"numpy",
"opm>=2020.10.2,<=2022.4", # NB: Pypi versions.
"pandas<2.0",
"pandas",
"pyarrow",
"pyyaml>=5.1",
"treelib",
Expand Down
5 changes: 4 additions & 1 deletion tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,10 @@ def test_smry_meta_synthetic():
def test_fix_dframe_for_libecl(dframe, expected_dframe):
"""Test the dataframe preprocessor/validator for df2eclsum works"""
pd.testing.assert_frame_equal(
_fix_dframe_for_libecl(dframe), expected_dframe, check_index_type=False
_fix_dframe_for_libecl(dframe),
expected_dframe,
check_index_type=False,
check_column_type=False,
)


Expand Down
8 changes: 6 additions & 2 deletions tests/test_wellconnstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ def test_extract_status_changes(smry, expected_wellconnstatus):
"""Testing that the extract_status_changes function is working
correctly with various summary input
"""
smry["DATE"] = pd.to_datetime(smry["DATE"])
time_format = None if int(pd.__version__.split(".")[0]) == 1 else "mixed"

smry["DATE"] = pd.to_datetime(smry["DATE"], format=time_format, dayfirst=True)
smry.set_index("DATE", inplace=True)
expected_wellconnstatus["DATE"] = pd.to_datetime(expected_wellconnstatus["DATE"])
expected_wellconnstatus["DATE"] = pd.to_datetime(
expected_wellconnstatus["DATE"], format=time_format, dayfirst=True
)

# pylint: disable=protected-access
pd.testing.assert_frame_equal(
Expand Down

0 comments on commit f5b197c

Please sign in to comment.