Skip to content

Commit

Permalink
rename to get_patch_names
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers committed Dec 24, 2024
1 parent 3068541 commit fb0707a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dascore/core/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dascore.core.coords import BaseCoord
from dascore.utils.display import array_to_text, attrs_to_text, get_dascore_text
from dascore.utils.models import ArrayLike
from dascore.utils.patch import check_patch_attrs, check_patch_coords, get_patch_name
from dascore.utils.patch import check_patch_attrs, check_patch_coords, get_patch_names
from dascore.utils.time import to_float
from dascore.viz import VizPatchNameSpace

Expand Down Expand Up @@ -260,7 +260,7 @@ def channel_count(self) -> int:
coords_from_df = dascore.proc.coords_from_df
make_broadcastable_to = dascore.proc.make_broadcastable_to
apply_ufunc = dascore.proc.apply_ufunc
get_name = get_patch_name
get_patch_names = get_patch_names

def assign_coords(self, *args, **kwargs):
"""Deprecated method for update_coords."""
Expand Down
4 changes: 2 additions & 2 deletions dascore/core/spool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
_force_patch_merge,
_spool_up,
concatenate_patches,
get_patch_name,
get_patch_names,
patches_to_df,
stack_patches,
)
Expand Down Expand Up @@ -602,7 +602,7 @@ def get_contents(self) -> pd.DataFrame:
"""{doc}."""
return self._df[filter_df(self._df, **self._select_kwargs)]

get_name = get_patch_name
get_patch_names = get_patch_names


class MemorySpool(DataFrameSpool):
Expand Down
4 changes: 2 additions & 2 deletions dascore/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from dascore.utils.docs import compose_docstring
from dascore.utils.downloader import fetch
from dascore.utils.misc import register_func
from dascore.utils.patch import get_patch_name
from dascore.utils.patch import get_patch_names
from dascore.utils.time import to_timedelta64

EXAMPLE_PATCHES = {}
Expand Down Expand Up @@ -506,7 +506,7 @@ def spool_to_directory(spool, path=None, file_format="DASDAE", extention="hdf5")
path = Path(tempfile.mkdtemp())
assert path.exists()
for patch in spool:
name = get_patch_name(patch).iloc[0]
name = get_patch_names(patch).iloc[0]
out_path = path / (f"{name}.{extention}")
patch.io.write(out_path, file_format=file_format)
return path
Expand Down
6 changes: 3 additions & 3 deletions dascore/io/dasdae/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
PyTablesWriter,
)
from dascore.utils.misc import unbyte
from dascore.utils.patch import get_patch_name
from dascore.utils.patch import get_patch_names

from .utils import (
_get_contents_from_patch_groups,
Expand Down Expand Up @@ -78,7 +78,7 @@ def write(self, spool: SpoolType, resource: PyTablesWriter, index=False, **kwarg
resource.create_group(resource.root, "waveforms")
waveforms = resource.get_node("/waveforms")
# write new patches to file
patch_names = get_patch_name(patches).values
patch_names = get_patch_names(patches).values
for patch, name in zip(patches, patch_names):
_save_patch(patch, waveforms, resource, name)
indexer = HDFPatchIndexManager(resource)
Expand All @@ -91,7 +91,7 @@ def _get_patch_summary(self, patches) -> pd.DataFrame:
df = (
dc.scan_to_df(patches)
.assign(
path=lambda x: get_patch_name(x),
path=lambda x: get_patch_names(x),
file_format=self.name,
file_version=self.version,
)
Expand Down
6 changes: 3 additions & 3 deletions dascore/utils/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def get_start_stop_step(patch: PatchType, dim):
return start, stop, step


def get_patch_name(
def get_patch_names(
patch_data: pd.DataFrame | dc.Patch | dc.BaseSpool,
prefix="DAS",
attrs=("network", "station", "tag"),
Expand Down Expand Up @@ -465,9 +465,9 @@ def get_patch_name(
Examples
--------
>>> import dascore as dc
>>> from dascore.utils.patch import get_patch_name
>>> from dascore.utils.patch import get_patch_names
>>> patch = dc.get_example_patch()
>>> name = get_patch_name(patch)
>>> name = get_patch_names(patch)
"""

def _format_time_column(ser):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_io/test_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import dascore as dc
from dascore.examples import spool_to_directory
from dascore.io.indexer import DirectoryIndexer
from dascore.utils.patch import get_patch_name
from dascore.utils.patch import get_patch_names


@pytest.fixture(scope="class")
Expand Down Expand Up @@ -224,7 +224,7 @@ def index_new_version(self, monkeypatch, tmp_path_factory):

def test_add_one_patch(self, empty_index, random_patch):
"""Ensure a new patch added to the directory shows up."""
path = empty_index.path / get_patch_name(random_patch).iloc[0]
path = empty_index.path / get_patch_names(random_patch).iloc[0]
random_patch.io.write(path, file_format="dasdae")
new_index = empty_index.update()
contents = new_index()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_utils/test_patch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
align_patch_coords,
concatenate_patches,
get_dim_axis_value,
get_patch_name,
get_patch_names,
merge_compatible_coords_attrs,
patches_to_df,
stack_patches,
Expand Down Expand Up @@ -616,30 +616,30 @@ class TestGetPatchName:

def test_single_patch(self, random_patch):
"""Ensure the random patch can have a name."""
out = get_patch_name(random_patch)
out = get_patch_names(random_patch)
assert isinstance(out, pd.Series)
assert len(out) == 1

def test_spool(self, random_spool):
"""Ensure names can be generated from a spool as well."""
out = get_patch_name(random_spool)
out = get_patch_names(random_spool)
assert len(out) == len(random_spool)

def test_empty(self):
"""Ensure an empty thing returns a series of the right type."""
out = get_patch_name([])
out = get_patch_names([])
assert isinstance(out, pd.Series)

def test_name_column_exists(self, random_spool):
"""If the name or path field already exist this should be used."""
df = random_spool.get_contents().assign(name=lambda x: np.arange(len(x)))
# This should convert to string type and return.
names = get_patch_name(df)
names = get_patch_names(df)
assert np.all(names.values == np.arange(len(df)).astype(str))

def test_path_column(self, random_spool_directory):
"""Ensure the path column works."""
names = get_patch_name(random_spool_directory)
names = get_patch_names(random_spool_directory)
df = random_spool_directory.get_contents()
expected = pd.Series([x[-1].split(".")[0] for x in df["path"].str.split("/")])
assert np.all(names == expected)

0 comments on commit fb0707a

Please sign in to comment.