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

after allowing characters in the data section, df() function was retu… #249

Merged
merged 1 commit into from Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lasio/las.py
Expand Up @@ -557,7 +557,14 @@ def header(self):
def df(self):
'''Return data as a :class:`pandas.DataFrame` structure.'''
import pandas as pd
from pandas.api.types import is_object_dtype
df = pd.DataFrame(self.data, columns=[c.mnemonic for c in self.curves])
for column in df.columns:
if is_object_dtype(df[column].dtype):
try:
df[column] = df[column].astype(np.float64)
except ValueError:
pass
if len(self.curves) > 0:
df = df.set_index(self.curves[0].mnemonic)
return df
Expand Down
9 changes: 9 additions & 0 deletions tests/test_read.py
Expand Up @@ -208,3 +208,12 @@ def test_data_characters():
las = lasio.read(egfn('data_characters.las'))
assert las['TIME'][0] == '00:00:00'
assert las['DATE'][0] == '01-Jan-20'

def test_data_characters_types():
from pandas.api.types import is_object_dtype
from pandas.api.types import is_float_dtype
las = lasio.read(egfn('data_characters.las'))
assert is_object_dtype(las.df().index.dtype)
assert is_object_dtype(las.df()['DATE'].dtype)
assert is_float_dtype(las.df()['DEPT'].dtype)
assert is_float_dtype(las.df()['ARC_GR_UNC_RT'].dtype)