daplapath 2.0.10__tar.gz → 2.0.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: daplapath
3
- Version: 2.0.10
3
+ Version: 2.0.12
4
4
  Summary: A pathlib.Path class for dapla
5
5
  License: MIT
6
6
  Author: ort
@@ -416,7 +416,9 @@ class Path(str, _PathBase):
416
416
  if timeout:
417
417
  timestamp: datetime.datetime = highest_numbered.timestamp
418
418
 
419
- time_should_be_at_least = pd.Timestamp.now() - pd.Timedelta(minutes=timeout)
419
+ time_should_be_at_least = pd.Timestamp.now(tz="Europe/Oslo").replace(
420
+ tzinfo=None
421
+ ).round("s") - pd.Timedelta(minutes=timeout)
420
422
  if timestamp > time_should_be_at_least:
421
423
  raise ValueError(
422
424
  f"Latest version of the file was updated {timestamp[0]}, which "
@@ -506,6 +508,8 @@ class Path(str, _PathBase):
506
508
  """
507
509
  if not isinstance(period, (str, int)):
508
510
  raise TypeError(f"'period' should be string or int. Got {type(period)}")
511
+ if not self.period:
512
+ raise ValueError(f"Cannot set period to path without period. {self}")
509
513
  if str(period) == self.period:
510
514
  return self
511
515
  return self.with_periods(period)
@@ -529,6 +533,8 @@ class Path(str, _PathBase):
529
533
  raise TypeError(
530
534
  f"'to_period' should be string or int. Got {type(to_period)}"
531
535
  )
536
+ if not self.periods:
537
+ raise ValueError(f"Cannot set period to path without period. {self}")
532
538
 
533
539
  periods: tuple[str] = (
534
540
  (str(from_period), str(to_period)) if to_period else (str(from_period),)
@@ -719,14 +725,14 @@ class Path(str, _PathBase):
719
725
 
720
726
  @property
721
727
  def partition_root(self) -> "Path":
722
- if ".parquet" not in self:
728
+ if not self.suffix or self.count(self.suffix) != 2:
723
729
  return self
724
- return self._new(self.split(".parquet")[0] + ".parquet")
730
+ return self._new(self.split(self.suffix)[0] + self.suffix)
725
731
 
726
732
  def is_partitioned(self) -> bool:
727
- if ".parquet" not in self or self.isfile() and self.count(".parquet") != 2:
733
+ if not self.suffix or self.count(self.suffix) != 2:
728
734
  return False
729
- return bool(len(self.glob("**/*.parquet")))
735
+ return bool(len(self.glob(f"**/*{self.suffix}")))
730
736
 
731
737
  def isfile(self) -> bool:
732
738
  return not self.isdir()
@@ -999,32 +1005,44 @@ class PathSeries(pd.Series, _PathBase):
999
1005
 
1000
1006
  def within_minutes(self, minutes: int):
1001
1007
  """Select files with a timestamp within the given number of minutes."""
1002
- time_then = pd.Timestamp.now() - pd.Timedelta(minutes=minutes)
1008
+ time_then = pd.Timestamp.now(tz="Europe/Oslo").replace(tzinfo=None).round(
1009
+ "s"
1010
+ ) - pd.Timedelta(minutes=minutes)
1003
1011
  return self.files[lambda x: x.timestamp > time_then]
1004
1012
 
1005
1013
  def within_hours(self, hours: int):
1006
1014
  """Select files with a timestamp within the given number of hours."""
1007
- time_then = pd.Timestamp.now() - pd.Timedelta(hours=hours)
1015
+ time_then = pd.Timestamp.now(tz="Europe/Oslo").replace(tzinfo=None).round(
1016
+ "s"
1017
+ ) - pd.Timedelta(hours=hours)
1008
1018
  return self.files[lambda x: x.timestamp > time_then]
1009
1019
 
1010
1020
  def within_days(self, days: int):
1011
1021
  """Select files with a timestamp within the given number of days."""
1012
- time_then = pd.Timestamp.now() - pd.Timedelta(days=days)
1022
+ time_then = pd.Timestamp.now(tz="Europe/Oslo").replace(tzinfo=None).round(
1023
+ "s"
1024
+ ) - pd.Timedelta(days=days)
1013
1025
  return self.files[lambda x: x.timestamp > time_then]
1014
1026
 
1015
1027
  def not_within_minutes(self, minutes: int):
1016
1028
  """Select files with a timestamp within the given number of minutes."""
1017
- time_then = pd.Timestamp.now() - pd.Timedelta(minutes=minutes)
1029
+ time_then = pd.Timestamp.now(tz="Europe/Oslo").replace(tzinfo=None).round(
1030
+ "s"
1031
+ ) - pd.Timedelta(minutes=minutes)
1018
1032
  return self.files[lambda x: x.timestamp < time_then]
1019
1033
 
1020
1034
  def not_within_hours(self, hours: int):
1021
1035
  """Select files with a timestamp within the given number of hours."""
1022
- time_then = pd.Timestamp.now() - pd.Timedelta(hours=hours)
1036
+ time_then = pd.Timestamp.now(tz="Europe/Oslo").replace(tzinfo=None).round(
1037
+ "s"
1038
+ ) - pd.Timedelta(hours=hours)
1023
1039
  return self.files[lambda x: x.timestamp < time_then]
1024
1040
 
1025
1041
  def not_within_days(self, days: int):
1026
1042
  """Select files with a timestamp within the given number of days."""
1027
- time_then = pd.Timestamp.now() - pd.Timedelta(days=days)
1043
+ time_then = pd.Timestamp.now(tz="Europe/Oslo").replace(tzinfo=None).round(
1044
+ "s"
1045
+ ) - pd.Timedelta(days=days)
1028
1046
  return self.files[lambda x: x.timestamp < time_then]
1029
1047
 
1030
1048
  @property
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "daplapath"
3
- version = "2.0.10"
3
+ version = "2.0.12"
4
4
  description = "A pathlib.Path class for dapla"
5
5
  authors = ["ort <ort@ssb.no>"]
6
6
  license = "MIT"
File without changes
File without changes