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

Use defaults for Black code formatting #103

Merged
merged 3 commits into from
Oct 7, 2022
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
8 changes: 3 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ repos:
- id: check-json
exclude: "asv_bench/asv.conf.json"
- id: check-yaml
- id: double-quote-string-fixer

- repo: https://github.com/psf/black
rev: 22.8.0
rev: 22.10.0
hooks:
- id: black
args: ["--line-length", "80", "--skip-string-normalization"]
- id: black-jupyter

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
Expand All @@ -39,7 +37,7 @@ repos:
- id: prettier

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.981
rev: v0.982
hooks:
- id: mypy
additional_dependencies: [
Expand Down
54 changes: 26 additions & 28 deletions asv_bench/benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,53 @@ def setup(self, *args, **kwargs):
shape = (10, 50, 100)
self.ds_3d = xr.Dataset(
{
'foo': (['time', 'y', 'x'], np.random.rand(*shape)),
"foo": (["time", "y", "x"], np.random.rand(*shape)),
},
{
'x': (['x'], np.arange(shape[-1])),
'y': (['y'], np.arange(shape[-2])),
"x": (["x"], np.arange(shape[-1])),
"y": (["y"], np.arange(shape[-2])),
},
)

shape_4d = (10, 50, 100, 3)
self.ds_4d = xr.Dataset(
{
'foo': (['time', 'y', 'x', 'b'], np.random.rand(*shape_4d)),
"foo": (["time", "y", "x", "b"], np.random.rand(*shape_4d)),
},
{
'x': (['x'], np.arange(shape_4d[-2])),
'y': (['y'], np.arange(shape_4d[-3])),
'b': (['b'], np.arange(shape_4d[-1])),
"x": (["x"], np.arange(shape_4d[-2])),
"y": (["y"], np.arange(shape_4d[-3])),
"b": (["b"], np.arange(shape_4d[-1])),
},
)

self.ds_xy = xr.Dataset(
{
'x': (
['sample', 'feature'],
"x": (
["sample", "feature"],
np.random.random((shape[-1], shape[0])),
),
'y': (['sample'], np.random.random(shape[-1])),
"y": (["sample"], np.random.random(shape[-1])),
},
)


class Generator(Base):
@parameterized(['preload_batch'], ([True, False]))
@parameterized(["preload_batch"], ([True, False]))
def time_batch_preload(self, preload_batch):
"""
Construct a generator on a chunked DataSet with and without preloading
batches.
"""
ds_dask = self.ds_xy.chunk({'sample': 2})
BatchGenerator(
ds_dask, input_dims={'sample': 2}, preload_batch=preload_batch
)
ds_dask = self.ds_xy.chunk({"sample": 2})
BatchGenerator(ds_dask, input_dims={"sample": 2}, preload_batch=preload_batch)

@parameterized(
['input_dims', 'batch_dims', 'input_overlap'],
["input_dims", "batch_dims", "input_overlap"],
(
[{'x': 5}, {'x': 10}, {'x': 5, 'y': 5}, {'x': 10, 'y': 5}],
[{}, {'x': 20}, {'x': 30}],
[{}, {'x': 1}, {'x': 2}],
[{"x": 5}, {"x": 10}, {"x": 5, "y": 5}, {"x": 10, "y": 5}],
[{}, {"x": 20}, {"x": 30}],
[{}, {"x": 1}, {"x": 2}],
),
)
def time_batch_input(self, input_dims, batch_dims, input_overlap):
Expand All @@ -76,8 +74,8 @@ def time_batch_input(self, input_dims, batch_dims, input_overlap):
)

@parameterized(
['input_dims', 'concat_input_dims'],
([{'x': 5}, {'x': 10}, {'x': 5, 'y': 5}], [True, False]),
["input_dims", "concat_input_dims"],
([{"x": 5}, {"x": 10}, {"x": 5, "y": 5}], [True, False]),
)
def time_batch_concat(self, input_dims, concat_input_dims):
"""
Expand All @@ -91,10 +89,10 @@ def time_batch_concat(self, input_dims, concat_input_dims):
)

@parameterized(
['input_dims', 'batch_dims', 'concat_input_dims'],
["input_dims", "batch_dims", "concat_input_dims"],
(
[{'x': 5}, {'x': 5, 'y': 5}],
[{}, {'x': 10}, {'x': 10, 'y': 10}],
[{"x": 5}, {"x": 5, "y": 5}],
[{}, {"x": 10}, {"x": 10, "y": 10}],
[True, False],
),
)
Expand All @@ -113,8 +111,8 @@ def time_batch_concat_4d(self, input_dims, batch_dims, concat_input_dims):

class Accessor(Base):
@parameterized(
['input_dims'],
([{'x': 2}, {'x': 4}, {'x': 2, 'y': 2}, {'x': 4, 'y': 2}]),
["input_dims"],
([{"x": 2}, {"x": 4}, {"x": 2, "y": 2}, {"x": 4, "y": 2}]),
)
def time_accessor_input_dim(self, input_dims):
"""
Expand All @@ -127,8 +125,8 @@ def time_accessor_input_dim(self, input_dims):
class TorchLoader(Base):
def setup(self, *args, **kwargs):
super().setup(**kwargs)
self.x_gen = BatchGenerator(self.ds_xy['x'], {'sample': 10})
self.y_gen = BatchGenerator(self.ds_xy['y'], {'sample': 10})
self.x_gen = BatchGenerator(self.ds_xy["x"], {"sample": 10})
self.y_gen = BatchGenerator(self.ds_xy["y"], {"sample": 10})

def time_map_dataset(self):
"""
Expand Down
106 changes: 51 additions & 55 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
# sys.path.insert(0, os.path.abspath('.'))
# sys.path.insert(os.path.abspath('..'))

print('python exec:', sys.executable)
print('sys.path:', sys.path)
print('xbatcher.version:', xbatcher.__version__)
print("python exec:", sys.executable)
print("sys.path:", sys.path)
print("xbatcher.version:", xbatcher.__version__)


# -- General configuration ------------------------------------------------
Expand All @@ -40,68 +40,64 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.mathjax',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.extlinks',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
'numpydoc',
'nbsphinx',
'IPython.sphinxext.ipython_directive',
'IPython.sphinxext.ipython_console_highlighting',
'sphinx_autosummary_accessors',
'sphinx_copybutton',
"sphinx.ext.mathjax",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.extlinks",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
"numpydoc",
"nbsphinx",
"IPython.sphinxext.ipython_directive",
"IPython.sphinxext.ipython_console_highlighting",
"sphinx_autosummary_accessors",
"sphinx_copybutton",
]

# never execute notebooks: avoids lots of expensive imports on rtd
# https://nbsphinx.readthedocs.io/en/0.2.14/never-execute.html
nbsphinx_execute = 'never'
nbsphinx_execute = "never"


# http://stackoverflow.com/questions/5599254/how-to-use-sphinxs-autodoc-to-document-a-classs-init-self-method
def skip(app, what, name, obj, skip, options):
if name == '__init__':
if name == "__init__":
return False
return skip


def setup(app):
app.connect('autodoc-skip-member', skip)
app.connect("autodoc-skip-member", skip)


autodoc_mock_imports = ['torch', 'tensorflow']
autodoc_mock_imports = ["torch", "tensorflow"]

# link to github issues
extlinks = {
'issue': ('https://github.com/xarray-contrib/xbatcher/issues/%s', 'GH')
}
extlinks = {"issue": ("https://github.com/xarray-contrib/xbatcher/issues/%s", "GH")}

# sphinx-copybutton configurations (from https://github.com/pydata/xarray/blob/main/doc/conf.py)
copybutton_prompt_text = (
r'>>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: '
)
copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_is_regexp = True

autosummary_generate = True
numpydoc_class_members_toctree = False
numpydoc_show_class_members = False

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates', sphinx_autosummary_accessors.templates_path]
templates_path = ["_templates", sphinx_autosummary_accessors.templates_path]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'xbatcher'
copyright = u'2021, xbatcher developers'
project = "xbatcher"
copyright = "2021, xbatcher developers"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -124,7 +120,7 @@ def setup(app):

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]

# The reST default role (used for this markup: `text`) to use for all
# documents.
Expand All @@ -142,7 +138,7 @@ def setup(app):
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -156,15 +152,15 @@ def setup(app):
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
# tml_theme = 'default'
html_theme = 'pangeo_sphinx_book_theme'
html_theme = "pangeo_sphinx_book_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
'repository_url': 'https://github.com/xarray-contrib/xbatcher',
'use_repository_button': True,
'use_issues_button': True,
"repository_url": "https://github.com/xarray-contrib/xbatcher",
"use_repository_button": True,
"use_issues_button": True,
}

# Add any paths that contain custom themes here, relative to this directory.
Expand Down Expand Up @@ -238,7 +234,7 @@ def setup(app):
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'xbatcherdoc'
htmlhelp_basename = "xbatcherdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -257,11 +253,11 @@ def setup(app):
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(
'index',
'xbatcher.tex',
u'xbatcher Documentation',
u'xbatcher developers',
'manual',
"index",
"xbatcher.tex",
"xbatcher Documentation",
"xbatcher developers",
"manual",
),
]

Expand Down Expand Up @@ -292,10 +288,10 @@ def setup(app):
# (source start file, name, description, authors, manual section).
man_pages = [
(
'index',
'xbatcher',
u'xbatcher Documentation',
[u'xbatcher developers'],
"index",
"xbatcher",
"xbatcher Documentation",
["xbatcher developers"],
1,
)
]
Expand All @@ -311,13 +307,13 @@ def setup(app):
# dir menu entry, description, category)
texinfo_documents = [
(
'index',
'xbatcher',
u'xbatcher Documentation',
u'xbatcher developers',
'xbatcher',
'One line description of project.',
'Miscellaneous',
"index",
"xbatcher",
"xbatcher Documentation",
"xbatcher developers",
"xbatcher",
"One line description of project.",
"Miscellaneous",
),
]

Expand All @@ -336,6 +332,6 @@ def setup(app):

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'xarray': ('http://xarray.pydata.org/en/stable/', None),
"python": ("https://docs.python.org/3/", None),
"xarray": ("http://xarray.pydata.org/en/stable/", None),
}
Loading