Skip to content

Commit

Permalink
Bugfix in gt return_method (BufrFile object was not returned properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Juri Hubrig committed May 26, 2024
1 parent 4b7cae2 commit 699a8de
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
23 changes: 18 additions & 5 deletions plbufr/bufr_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ def read_bufr(
required_columns: bool | T.Iterable[str] = True,
flat: bool = False,
return_method: str = "df"
) -> T.Any #pl.DataFrame | pl.LazyFrame | T.Generator:
) -> T.Any: #pl.DataFrame | pl.LazyFrame | T.Generator:
"""
Read selected observations from a BUFR file into DataFrame.
"""

if isinstance(path_or_messages, (str, bytes, PathLike)):
with BufrFile(path_or_messages) as bufr_file: # type: ignore
if return_method == "gt":
bufr_file = BufrFile(path_or_messages)
return _read_bufr(
bufr_file,
columns=columns,
Expand All @@ -39,8 +40,20 @@ def read_bufr(
skip_na=skip_na,
required_columns=required_columns,
flat=flat,
return_method=return_method
)
return_method=return_method
), bufr_file
else:
with BufrFile(path_or_messages) as bufr_file: # type: ignore
return _read_bufr(
bufr_file,
columns=columns,
filters=filters,
filter_method=filter_method,
skip_na=skip_na,
required_columns=required_columns,
flat=flat,
return_method=return_method
)
else:
return _read_bufr(
path_or_messages,
Expand All @@ -63,7 +76,7 @@ def _read_bufr(
required_columns: bool | T.Iterable[str] = True,
flat: bool = False,
return_method: str = "df"
) -> T.Any #pl.DataFrame | pl.LazyFrame | T.Generator
) -> T.Any: #pl.DataFrame | pl.LazyFrame | T.Generator
if not flat:
observations = bufr_structure.stream_bufr(
bufr_file=bufr_obj,
Expand Down
23 changes: 18 additions & 5 deletions src/plbufr/bufr_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ def read_bufr(
required_columns: bool | T.Iterable[str] = True,
flat: bool = False,
return_method: str = "df"
) -> T.Any #pl.DataFrame | pl.LazyFrame | T.Generator:
) -> T.Any: #pl.DataFrame | pl.LazyFrame | T.Generator:
"""
Read selected observations from a BUFR file into DataFrame.
"""

if isinstance(path_or_messages, (str, bytes, PathLike)):
with BufrFile(path_or_messages) as bufr_file: # type: ignore
if return_method == "gt":
bufr_file = BufrFile(path_or_messages)
return _read_bufr(
bufr_file,
columns=columns,
Expand All @@ -39,8 +40,20 @@ def read_bufr(
skip_na=skip_na,
required_columns=required_columns,
flat=flat,
return_method=return_method
)
return_method=return_method
), bufr_file
else:
with BufrFile(path_or_messages) as bufr_file: # type: ignore
return _read_bufr(
bufr_file,
columns=columns,
filters=filters,
filter_method=filter_method,
skip_na=skip_na,
required_columns=required_columns,
flat=flat,
return_method=return_method
)
else:
return _read_bufr(
path_or_messages,
Expand All @@ -63,7 +76,7 @@ def _read_bufr(
required_columns: bool | T.Iterable[str] = True,
flat: bool = False,
return_method: str = "df"
) -> T.Any #pl.DataFrame | pl.LazyFrame | T.Generator
) -> T.Any: #pl.DataFrame | pl.LazyFrame | T.Generator
if not flat:
observations = bufr_structure.stream_bufr(
bufr_file=bufr_obj,
Expand Down
2 changes: 2 additions & 0 deletions src/plbufr/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do not change! Do not track in version control!
__version__ = "0.1.dev329+g4b7cae2.d20240526"

0 comments on commit 699a8de

Please sign in to comment.