Skip to content

Commit

Permalink
Fix most formatting errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
vnmabus committed Jan 19, 2024
1 parent 7100406 commit a71f295
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 56 deletions.
Empty file removed conftest.py
Empty file.
1 change: 1 addition & 0 deletions docs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Documentation."""
22 changes: 5 additions & 17 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
"""Configuration of the Sphinx documentation."""

# rdata documentation build configuration file, created by
# sphinx-quickstart on Tue Aug 7 12:49:32 2018.
#
Expand All @@ -27,7 +26,7 @@
# General information about the project.
project = "rdata"
author = "Carlos Ramos Carreño"
copyright = "2018, Carlos Ramos Carreño"
copyright = "2018, Carlos Ramos Carreño" # noqa: A001
github_url = "https://github.com/vnmabus/rdata"
rtd_version = os.environ.get("READTHEDOCS_VERSION")
rtd_version_type = os.environ.get("READTHEDOCS_VERSION_TYPE")
Expand All @@ -44,7 +43,7 @@
try:
release = importlib.metadata.version("rdata")
except importlib.metadata.PackageNotFoundError:
print(
print( # noqa: T201
f"To build the documentation, The distribution information of\n"
f"{project} has to be available. Either install the package\n"
f"into your development environment or run 'setup.py develop'\n"
Expand All @@ -57,8 +56,6 @@
# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand Down Expand Up @@ -166,7 +163,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, "rdata", "rdata Documentation", [author], 1)
(master_doc, "rdata", "rdata Documentation", [author], 1),
]

# -- Options for Texinfo output -------------------------------------------
Expand Down Expand Up @@ -194,15 +191,6 @@
epub_publisher = author
epub_copyright = copyright

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ["search.html"]

Expand Down
1 change: 1 addition & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Documentation examples."""
5 changes: 2 additions & 3 deletions examples/plot_cran.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@


def graph_constructor(obj, attrs):
"""Construct graph object from R representation."""
n_vertices = int(obj[0][0])
is_directed = obj[1]
edge_from = obj[2].astype(int)
Expand All @@ -119,7 +120,7 @@ def graph_constructor(obj, attrs):
vertex_attrs = obj[8][2]
edge_attrs = obj[8][3]

graph = igraph.Graph(
return igraph.Graph(
n=n_vertices,
directed=is_directed,
edges=list(zip(edge_from, edge_to)),
Expand All @@ -128,8 +129,6 @@ def graph_constructor(obj, attrs):
edge_attrs=edge_attrs,
)

return graph


# %%
# We create a dict with all the constructors that we want to apply.
Expand Down
1 change: 1 addition & 0 deletions examples/plot_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@interact(files=FileUpload(accept="*.rd*", multiple=True))
def convert_from_file(files):
"""Open a rds or rdata file and display its contents as Python objects."""
for f in files:
parsed = rdata.parser.parse_data(f.content)
converted = rdata.conversion.convert(parsed)
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ ignore = [
"TID252", # relative imports allowed
]

[tool.ruff.per-file-ignores]
"plot_*.py" = [
"ANN", # no type hints in examples
"ARG001", # Some unused args are needed
"B018", # single object expressions are not useless in examples (they display the object)
"D205", # examples do not have a blank line in docstring
"D415", # first line in examples does not end with period
"ERA001", # Commented code may be useful for the reader
"S310", # URLs in examples have been validated
"T201", # print allowed in examples
]

[tool.ruff.isort]
combine-as-imports = true

[tool.ruff.pydocstyle]
convention = "google"

Expand Down
8 changes: 5 additions & 3 deletions rdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from __future__ import annotations

from importlib.resources import files
from typing import Final
from typing import TYPE_CHECKING, Final

from . import conversion, parser
from .parser._parser import Traversable
from . import conversion as conversion, parser as parser

if TYPE_CHECKING:
from .parser._parser import Traversable


def _get_test_data_path() -> Traversable:
Expand Down
1 change: 1 addition & 0 deletions rdata/conversion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Utilities for converting R objects to Python ones."""
from ._conversion import (
DEFAULT_CLASS_MAP as DEFAULT_CLASS_MAP,
Converter as Converter,
Expand Down
1 change: 1 addition & 0 deletions rdata/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for the rdata package."""
64 changes: 32 additions & 32 deletions rdata/tests/test_rdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import ChainMap
from fractions import Fraction
from types import SimpleNamespace
from typing import Any, Dict
from typing import Any

import numpy as np
import pandas as pd
Expand All @@ -15,16 +15,16 @@
TESTDATA_PATH = rdata.TESTDATA_PATH


class SimpleTests(unittest.TestCase): # noqa:WPS214
class SimpleTests(unittest.TestCase):
"""Collection of simple test cases."""

def test_opened_file(self) -> None:
"""Test that an opened file can be passed to parse_file."""
with open(TESTDATA_PATH / "test_vector.rda") as f:
with (TESTDATA_PATH / "test_vector.rda").open() as f:
parsed = rdata.parser.parse_file(f)
converted = rdata.conversion.convert(parsed)

self.assertIsInstance(converted, dict)
assert isinstance(converted, dict)

def test_opened_string(self) -> None:
"""Test that a string can be passed to parse_file."""
Expand All @@ -33,7 +33,7 @@ def test_opened_string(self) -> None:
)
converted = rdata.conversion.convert(parsed)

self.assertIsInstance(converted, dict)
assert isinstance(converted, dict)

def test_logical(self) -> None:
"""Test parsing of logical vectors."""
Expand Down Expand Up @@ -228,9 +228,9 @@ def test_list(self) -> None:
"test_list":
[
np.array([1.0]),
['a', 'b', 'c'],
["a", "b", "c"],
np.array([2.0, 3.0]),
['hi'],
["hi"],
],
})

Expand All @@ -251,7 +251,7 @@ def test_expression(self) -> None:
np.testing.assert_equal(converted, {
"test_expression": rdata.conversion.RExpression([
rdata.conversion.RLanguage(
['^', 'base', 'exponent'],
["^", "base", "exponent"],
attributes={},
),
]),
Expand All @@ -275,7 +275,7 @@ def test_minimal_function_uncompiled(self) -> None:

converted_fun = converted["test_minimal_function_uncompiled"]

self.assertIsInstance(
assert isinstance(
converted_fun,
rdata.conversion.RFunction,
)
Expand All @@ -297,7 +297,7 @@ def test_minimal_function(self) -> None:

converted_fun = converted["test_minimal_function"]

self.assertIsInstance(
assert isinstance(
converted_fun,
rdata.conversion.RFunction,
)
Expand All @@ -307,7 +307,7 @@ def test_minimal_function(self) -> None:

converted_body = converted_fun.body

self.assertIsInstance(
assert isinstance(
converted_body,
rdata.conversion.RBytecode,
)
Expand All @@ -329,17 +329,17 @@ def test_empty_function_uncompiled(self) -> None:

converted_fun = converted["test_empty_function_uncompiled"]

self.assertIsInstance(
assert isinstance(
converted_fun,
rdata.conversion.RFunction,
)

np.testing.assert_equal(converted_fun.environment, ChainMap({}))
np.testing.assert_equal(converted_fun.formals, None)
self.assertIsInstance(converted_fun.body, rdata.conversion.RLanguage)
assert isinstance(converted_fun.body, rdata.conversion.RLanguage)
np.testing.assert_equal(
converted_fun.source,
"test_empty_function_uncompiled <- function() {}\n", # noqa:P103
"test_empty_function_uncompiled <- function() {}\n",
)

def test_empty_function(self) -> None:
Expand All @@ -351,7 +351,7 @@ def test_empty_function(self) -> None:

converted_fun = converted["test_empty_function"]

self.assertIsInstance(
assert isinstance(
converted_fun,
rdata.conversion.RFunction,
)
Expand All @@ -361,7 +361,7 @@ def test_empty_function(self) -> None:

converted_body = converted_fun.body

self.assertIsInstance(
assert isinstance(
converted_body,
rdata.conversion.RBytecode,
)
Expand All @@ -371,7 +371,7 @@ def test_empty_function(self) -> None:

np.testing.assert_equal(
converted_fun.source,
"test_empty_function <- function() {}\n", # noqa:P103
"test_empty_function <- function() {}\n",
)

def test_function(self) -> None:
Expand All @@ -383,7 +383,7 @@ def test_function(self) -> None:

converted_fun = converted["test_function"]

self.assertIsInstance(
assert isinstance(
converted_fun,
rdata.conversion.RFunction,
)
Expand All @@ -393,7 +393,7 @@ def test_function(self) -> None:

converted_body = converted_fun.body

self.assertIsInstance(
assert isinstance(
converted_body,
rdata.conversion.RBytecode,
)
Expand All @@ -418,7 +418,7 @@ def test_function_arg(self) -> None:

converted_fun = converted["test_function_arg"]

self.assertIsInstance(
assert isinstance(
converted_fun,
rdata.conversion.RFunction,
)
Expand All @@ -428,7 +428,7 @@ def test_function_arg(self) -> None:

converted_body = converted_fun.body

self.assertIsInstance(
assert isinstance(
converted_body,
rdata.conversion.RBytecode,
)
Expand Down Expand Up @@ -495,7 +495,7 @@ def test_dataframe(self) -> None:
"value": pd.Series(
[1, 2, 3],
dtype=pd.Int32Dtype(),
).values,
).array,
},
index=pd.RangeIndex(start=1, stop=4),
),
Expand All @@ -520,7 +520,7 @@ def test_dataframe_rds(self) -> None:
"value": pd.Series(
[1, 2, 3],
dtype=pd.Int32Dtype(),
).values,
).array,
},
index=pd.RangeIndex(start=1, stop=4),
),
Expand All @@ -543,9 +543,9 @@ def test_dataframe_rownames(self) -> None:
"value": pd.Series(
[1, 2, 3],
dtype=pd.Int32Dtype(),
).values,
).array,
},
index=('Madrid', 'Frankfurt', 'Herzberg am Harz'),
index=("Madrid", "Frankfurt", "Herzberg am Harz"),
),
)

Expand All @@ -572,7 +572,7 @@ def test_s4(self) -> None:
"test_s4": SimpleNamespace(
age=np.array(28),
name=["Carlos"],
**{'class': ["Person"]}, # noqa: WPS517
**{"class": ["Person"]},
),
})

Expand All @@ -583,8 +583,8 @@ def test_environment(self) -> None:
)
converted = rdata.conversion.convert(parsed)

dict_env = {'string': ['test']}
empty_global_env: Dict[str, Any] = {}
dict_env = {"string": ["test"]}
empty_global_env: dict[str, Any] = {}

np.testing.assert_equal(converted, {
"test_environment": ChainMap(dict_env, ChainMap(empty_global_env)),
Expand All @@ -608,17 +608,17 @@ def test_emptyenv(self) -> None:
)
converted = rdata.conversion.convert(parsed)

self.assertEqual(converted, {
assert converted == {
"test_emptyenv": ChainMap({}),
})
}

def test_list_attrs(self) -> None:
"""Test that lists accept attributes."""
parsed = rdata.parser.parse_file(TESTDATA_PATH / "test_list_attrs.rda")
converted = rdata.conversion.convert(parsed)

np.testing.assert_equal(converted, {
"test_list_attrs": [['list'], [5]],
"test_list_attrs": [["list"], [5]],
})

def test_altrep_compact_intseq(self) -> None:
Expand Down Expand Up @@ -683,7 +683,7 @@ def test_altrep_deferred_string(self) -> None:
converted = rdata.conversion.convert(parsed)

np.testing.assert_equal(converted, {
"test_altrep_deferred_string": [ # noqa: WPS317
"test_altrep_deferred_string": [
"1", "2.3", "10000",
"1e+05", "-10000", "-1e+05",
"0.001", "1e-04", "1e-05",
Expand Down
Loading

0 comments on commit a71f295

Please sign in to comment.