daplapath 2.0.5__tar.gz → 2.0.7__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.
- {daplapath-2.0.5 → daplapath-2.0.7}/PKG-INFO +1 -1
- {daplapath-2.0.5 → daplapath-2.0.7}/daplapath/__init__.py +1 -0
- {daplapath-2.0.5 → daplapath-2.0.7}/daplapath/path.py +24 -18
- {daplapath-2.0.5 → daplapath-2.0.7}/pyproject.toml +1 -1
- {daplapath-2.0.5 → daplapath-2.0.7}/LICENSE.md +0 -0
- {daplapath-2.0.5 → daplapath-2.0.7}/README.md +0 -0
|
@@ -206,16 +206,15 @@ class Path(str, _PathBase):
|
|
|
206
206
|
.rstrip("/")
|
|
207
207
|
)
|
|
208
208
|
|
|
209
|
-
def __new__(cls, gcs_path: str | PurePath | None = None):
|
|
209
|
+
def __new__(cls, gcs_path: str | PurePath | None = None, file_system=None):
|
|
210
210
|
"""Construct Path with '/' as delimiter."""
|
|
211
211
|
gcs_path = cls._standardize_path(gcs_path or "")
|
|
212
212
|
obj = super().__new__(cls, gcs_path)
|
|
213
213
|
obj._path = PurePosixPath(obj)
|
|
214
|
-
obj._file_system =
|
|
214
|
+
obj._file_system = file_system
|
|
215
215
|
return obj
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
def local_path(self) -> "Path":
|
|
217
|
+
def buckets_path(self) -> "Path":
|
|
219
218
|
if self.startswith("/buckets"):
|
|
220
219
|
return self
|
|
221
220
|
|
|
@@ -223,9 +222,9 @@ class Path(str, _PathBase):
|
|
|
223
222
|
bucket = root.split("-data-")[-1].split("-prod")[0]
|
|
224
223
|
|
|
225
224
|
try:
|
|
226
|
-
return self.
|
|
225
|
+
return self._new(f"/buckets/{bucket}/{'/'.join(self.parts[1:])}")
|
|
227
226
|
except IndexError:
|
|
228
|
-
return self.
|
|
227
|
+
return self._new(f"/buckets/{bucket}")
|
|
229
228
|
|
|
230
229
|
def tree(
|
|
231
230
|
self,
|
|
@@ -402,7 +401,7 @@ class Path(str, _PathBase):
|
|
|
402
401
|
'file_v201.parquet'
|
|
403
402
|
"""
|
|
404
403
|
version_text = f"{self._version_prefix}{version}" if version is not None else ""
|
|
405
|
-
return self.
|
|
404
|
+
return self._new(
|
|
406
405
|
f"{self.parent}/{self.versionless_stem}{version_text}{self.suffix}"
|
|
407
406
|
)
|
|
408
407
|
|
|
@@ -505,7 +504,7 @@ class Path(str, _PathBase):
|
|
|
505
504
|
|
|
506
505
|
parent = f"{self.parent}/" if self.parent != "." else ""
|
|
507
506
|
|
|
508
|
-
return self.
|
|
507
|
+
return self._new(
|
|
509
508
|
f"{parent}{stem}{period_string}{version_string}{self.suffix}".replace(
|
|
510
509
|
"".join(self.periods), period_string.strip(self._period_prefix)
|
|
511
510
|
)
|
|
@@ -546,17 +545,17 @@ class Path(str, _PathBase):
|
|
|
546
545
|
@property
|
|
547
546
|
def versionless_stem(self) -> str:
|
|
548
547
|
"""Return the file stem before the version pattern."""
|
|
549
|
-
return self.
|
|
548
|
+
return self._new(re.split(self._version_pattern, self._path.name)[0]).stem
|
|
550
549
|
|
|
551
550
|
@property
|
|
552
551
|
def parent(self) -> "Path":
|
|
553
552
|
"""Parent path."""
|
|
554
|
-
return self.
|
|
553
|
+
return self._new(self._path.parent)
|
|
555
554
|
|
|
556
555
|
@property
|
|
557
556
|
def parents(self) -> "list[Path]":
|
|
558
557
|
"""Parent path."""
|
|
559
|
-
return [self.
|
|
558
|
+
return [self._new(parent) for parent in self._path.parents]
|
|
560
559
|
|
|
561
560
|
@property
|
|
562
561
|
def name(self) -> str:
|
|
@@ -606,7 +605,9 @@ class Path(str, _PathBase):
|
|
|
606
605
|
try:
|
|
607
606
|
with self.open("rb") as file:
|
|
608
607
|
return get_schema(file)
|
|
609
|
-
except (
|
|
608
|
+
except (
|
|
609
|
+
Exception
|
|
610
|
+
): # (PermissionError, FileNotFoundError, TypeError, IsADirectoryError):
|
|
610
611
|
return get_schema(self)
|
|
611
612
|
|
|
612
613
|
@property
|
|
@@ -624,7 +625,9 @@ class Path(str, _PathBase):
|
|
|
624
625
|
try:
|
|
625
626
|
with self.open("rb") as file:
|
|
626
627
|
return get_shape(file)
|
|
627
|
-
except (
|
|
628
|
+
except (
|
|
629
|
+
Exception
|
|
630
|
+
): # (PermissionError, FileNotFoundError, TypeError, IsADirectoryError):
|
|
628
631
|
return get_shape(self)
|
|
629
632
|
|
|
630
633
|
@property
|
|
@@ -695,13 +698,13 @@ class Path(str, _PathBase):
|
|
|
695
698
|
return self.isdir()
|
|
696
699
|
|
|
697
700
|
def with_suffix(self, suffix: str):
|
|
698
|
-
return self.
|
|
701
|
+
return self._new(self._path.with_suffix(suffix))
|
|
699
702
|
|
|
700
703
|
def with_name(self, new_name: str):
|
|
701
|
-
return self.
|
|
704
|
+
return self._new(self._path.with_name(new_name))
|
|
702
705
|
|
|
703
706
|
def with_stem(self, new_with_stem: str):
|
|
704
|
-
return self.
|
|
707
|
+
return self._new(self._path.with_stem(new_with_stem))
|
|
705
708
|
|
|
706
709
|
@property
|
|
707
710
|
def file_system(self):
|
|
@@ -729,7 +732,7 @@ class Path(str, _PathBase):
|
|
|
729
732
|
"unsupported operand type(s) for /: "
|
|
730
733
|
f"{self.__class__.__name__} and {other.__class__.__name__}"
|
|
731
734
|
)
|
|
732
|
-
return self.
|
|
735
|
+
return self._new(f"{self}/{as_str(other)}")
|
|
733
736
|
|
|
734
737
|
def __getattribute__(self, name):
|
|
735
738
|
"""stackoverflow hack to ensure we return Path when using string methods.
|
|
@@ -777,6 +780,9 @@ class Path(str, _PathBase):
|
|
|
777
780
|
path._file_system = self._file_system
|
|
778
781
|
return self._iterable_type(series, **kwargs)
|
|
779
782
|
|
|
783
|
+
def _new(self, new_path: str | Path) -> "Path":
|
|
784
|
+
return self.__class__(new_path, self.file_system)
|
|
785
|
+
|
|
780
786
|
|
|
781
787
|
class PathSeries(pd.Series, _PathBase):
|
|
782
788
|
"""A pandas Series for working with GCS (Google Cloud Storage) paths.
|
|
@@ -1508,7 +1514,7 @@ def get_schema(file) -> pyarrow.Schema:
|
|
|
1508
1514
|
FileNotFoundError,
|
|
1509
1515
|
IsADirectoryError,
|
|
1510
1516
|
OSError,
|
|
1511
|
-
):
|
|
1517
|
+
) as e:
|
|
1512
1518
|
# try:
|
|
1513
1519
|
# return ds.dataset(file).schema
|
|
1514
1520
|
# except (TypeError, FileNotFoundError) as e:
|
|
File without changes
|
|
File without changes
|