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

Fix readlatest #26

Merged
merged 3 commits into from
Feb 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-arbmark-fagfunksjoner"
version = "0.0.8"
version = "0.0.9"
description = "SSB Arbeidsmarked og lønn Fag-fellesfunksjoner"
authors = ["Jan Sebastian Rothe <[email protected]>"]
license = "MIT"
Expand Down
15 changes: 4 additions & 11 deletions src/ssb_arbmark_fagfunksjoner/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,8 @@ def read_latest(path: str, name: str, dottype: str = ".parquet") -> str | None:
# Join directory and file name
file_path = os.path.join(path, file_name_pattern)

# Checking environment
wenv = os.environ.get("DAPLA_REGION")

# If environment is Dapla
if wenv == "BIP":
# If path is a google cloud bucket
if path[:4] in ["ssb-", "gs:/"]:

# Get filesystem
fs = FileClient.get_gcs_file_system()
Expand All @@ -587,14 +584,10 @@ def read_latest(path: str, name: str, dottype: str = ".parquet") -> str | None:
# Use glob to find all files matching the pattern
file_list = glob.glob(file_path)

# Sorting key based on file modification time
# Sorting key based on file version
file_versions = sorted(
file_list,
key=lambda x: (
os.path.getmtime(x),
# Fallback to filename sorting
x,
),
key=lambda x: int(x.split("_v")[-1].split(".")[0]),
)

# Check if any files were found. If not, inform the user and return None
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,6 @@ def test_read_latest() -> None:
result = read_latest(
path=os.path.normpath(f"{cwd}/tests/test_data"), name="dataset"
)
expected = os.path.normpath(f"{cwd}/tests/test_data/dataset3.parquet")
expected = os.path.normpath(f"{cwd}/tests/test_data/dataset_v3.parquet")

assert result == expected, f"Expected {expected}, but got {result}."
Loading