import os
import numpy as np
import pytest
import las_rs
test_dir = os.path.dirname(__file__)
def fixture(*parts):
return os.path.join(test_dir, "fixtures", *parts)
_LAS_SRC = """\
~VERSION INFORMATION
VERS. 2.0 : LAS VERSION 2.0
WRAP. NO : ONE LINE PER DEPTH STEP
~WELL INFORMATION
STRT.M 6000.0 : START DEPTH
STOP.M 6004.0 : STOP DEPTH
STEP.M 1.0 : STEP VALUE
NULL. -999.25 : NULL VALUE
COMP. SILVERGATE EXPLORATION : COMPANY
WELL. CLOUDPEAK-8 #5 : WELL NAME
~CURVE INFORMATION
DEPT.M : MEASURED DEPTH
RES .OHM.M : RESISTIVITY
DT .US/M : SONIC TRANSIT TIME
PORO.V/V : POROSITY
~ASCII LOG DATA
6000.0 18.55 295.10 0.241
6001.0 22.13 312.40 0.228
6002.0 15.87 287.60 0.256
6003.0 30.44 330.20 0.212
6004.0 25.09 305.80 0.235
"""
N_ROWS = 5
_DEPTH_AT_ROW2 = 6002.0
def _read():
return las_rs.read(_LAS_SRC)
@pytest.mark.xfail(reason="not yet implemented")
def test_df_index_by_depth():
pd = pytest.importorskip("pandas")
las = _read()
df = las.df()
row = df.loc[_DEPTH_AT_ROW2]
assert float(row["RES"]) == pytest.approx(15.87)
@pytest.mark.xfail(reason="not yet implemented")
def test_df_curve_names_match_keys():
pytest.importorskip("pandas")
las = _read()
keys = list(las.keys())
df_cols = list(las.df().columns.values)
assert keys[1:] == df_cols
@pytest.mark.xfail(reason="not yet implemented")
def test_df_string_dtype_conversion():
pd = pytest.importorskip("pandas")
las = _read()
df = las.df()
for col in df.columns:
assert df[col].dtype == np.float64 or np.issubdtype(df[col].dtype, np.floating), (
f"Column '{col}' has dtype {df[col].dtype}, expected float64"
)
@pytest.mark.xfail(reason="not yet implemented")
def test_df_include_units_uses_original_mnemonic():
pytest.importorskip("pandas")
las = _read()
df = las.df(include_units=True)
col_str = " ".join(str(c) for c in df.columns)
assert "OHM" in col_str or "ohm" in col_str.lower() assert "US" in col_str or "us" in col_str.lower() assert "V/V" in col_str or "v/v" in col_str.lower()
@pytest.mark.xfail(reason="not yet implemented")
def test_set_data_from_df_truncate():
pd = pytest.importorskip("pandas")
las = _read()
narrow_df = pd.DataFrame(
{"RES": [18.55, 22.13, 15.87]},
index=pd.Index([6000.0, 6001.0, 6002.0], name="DEPT"),
)
las.set_data_from_df(narrow_df, truncate=True)
assert len(las.curves) == 2