Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7321b87
Added __repr__ implementation on all locators and formators
Daniil-Aleshechkin Apr 26, 2023
0605320
Fixed flake8 issues
Daniil-Aleshechkin Apr 26, 2023
fc305e4
Whitespace
Daniil-Aleshechkin Apr 26, 2023
afbf1ec
Make some methods that don't need to be public private
Daniil-Aleshechkin Apr 26, 2023
b6781c7
Added functools.wraps decorator
Daniil-Aleshechkin Apr 26, 2023
d3aef45
Removed added __init__ method on runtime
Daniil-Aleshechkin Apr 26, 2023
e6cc3b1
Added a seperate default init implemetation that should match the sig…
Daniil-Aleshechkin Apr 26, 2023
a0754b7
Fixed wrong function call
Daniil-Aleshechkin Apr 26, 2023
0845b90
Removed git artifact
Daniil-Aleshechkin Apr 26, 2023
8db91fc
Added missing if check and fixed flake issues
Daniil-Aleshechkin Apr 26, 2023
03006f7
Fixed bad undo
Daniil-Aleshechkin Apr 26, 2023
e51f4e8
Added extra check to ensure we're not wrapping inherited wrapped func…
Daniil-Aleshechkin Apr 26, 2023
95ab01f
Updated check to check a marker to account for the default case
Daniil-Aleshechkin Apr 26, 2023
5de2d24
Made the check for the marker safer
Daniil-Aleshechkin Apr 26, 2023
26de7ab
Updated my solution to avoid double wrapping functions
Daniil-Aleshechkin Apr 26, 2023
68252ae
Removed overriden default init for the wrapper
Daniil-Aleshechkin Apr 27, 2023
23d9ba9
Removed general repr and manually created reprs
Daniil-Aleshechkin-IQ May 8, 2023
06a7da4
Whitespace
Daniil-Aleshechkin-IQ May 8, 2023
6298a59
Removed depricated attribute
Daniil-Aleshechkin-IQ May 8, 2023
ff128da
Added unit tests
Daniil-Aleshechkin-IQ May 8, 2023
6d3c802
Fixed flake8 issues
Daniil-Aleshechkin-IQ May 8, 2023
3b96310
Whitespace
Daniil-Aleshechkin-IQ May 8, 2023
1b520ae
Fixed tests
Daniil-Aleshechkin-IQ May 8, 2023
16d693d
Fixed typo
Daniil-Aleshechkin-IQ May 8, 2023
32b3266
Updated assertions
Daniil-Aleshechkin-IQ May 8, 2023
5e614b1
Fix unit test class name
Daniil-Aleshechkin-IQ May 9, 2023
471b852
Fixed tests
Daniil-Aleshechkin-IQ May 9, 2023
8bb64ac
Added import from numpy
Daniil-Aleshechkin-IQ May 9, 2023
98d59e9
Properly imported numpy.array for eval
Daniil-Aleshechkin-IQ May 9, 2023
3e874f7
added references to sut classes
Daniil-Aleshechkin-IQ May 9, 2023
bbef256
Removed unused import
Daniil-Aleshechkin-IQ May 9, 2023
075e9c7
Formattin
Daniil-Aleshechkin-IQ May 9, 2023
94daa84
Fixed array assertion
Daniil-Aleshechkin-IQ May 9, 2023
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: 8 additions & 0 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ class ThetaLocator(mticker.Locator):
locations of every 45 degrees are returned.
"""

def __repr__(self):
return f"{self.__class__.__name__}(base={self.base.__repr__()})"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These __repr__ should all be:

Suggested change
return f"{self.__class__.__name__}(base={self.base.__repr__()})"
return f"{self.__class__.__name__}(base={self.base!r})"


def __init__(self, base):
self.base = base
self.axis = self.base.axis = _AxisWrapper(self.base.axis)
Expand Down Expand Up @@ -455,6 +458,11 @@ class RadialLocator(mticker.Locator):
scale of the *r*-axis).
"""

def __repr__(self):
return f"{self.__class__.__name__}(" + \
f"base={self.base.__repr__()}, " + \
f"axes={self._axes.__repr__()})"

def __init__(self, base, axes=None):
self.base = base
self._axes = axes
Expand Down
133 changes: 133 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1633,3 +1633,136 @@ def test_set_offset_string(formatter):
assert formatter.get_offset() == ''
formatter.set_offset_string('mpl')
assert formatter.get_offset() == 'mpl'


class TestReprImplementation:
def test_LogLocator(self):
sut = mticker.LogLocator(base=10, numticks=15)

result = sut.__repr__()

assert result.startswith("LogLocator(")
assert "base=10" in result
assert "numticks=15" in result
assert result.endswith(")")

def test_NullLocator(self):
sut = mticker.NullFormatter()

assert sut.__repr__() == "NullFormatter()"

def test_MultipleLocator(self):
sut = mticker.MultipleLocator(0.5)

assert sut.__repr__() == "MultipleLocator(base=0.5)"

def test_FixedLocator(self):
sut = mticker.FixedLocator([0, 1, 5])
result = sut.__repr__()

assert result.startswith("FixedLocator(")
assert "locs=array([0, 1, 5])" in result
assert "nbins=None" in result
assert result.endswith(")")

def test_LinearLocator(self):
sut = mticker.LinearLocator(numticks=3)

result = sut.__repr__()

assert result.startswith("LinearLocator(")
assert "numticks=3" in result
assert r"presets={}" in result
assert result.endswith(")")

def test_IndexLocator(self):
sut = mticker.IndexLocator(base=0.5, offset=0.25)

result = sut.__repr__()

assert result.startswith("IndexLocator(")
assert "base=0.5" in result
assert "offset=0.25" in result
assert result.endswith(")")

def test_AutoLocator(self):
sut = mticker.AutoLocator()

assert sut.__repr__() == "AutoLocator()"

def test_MaxNLocator(self):
sut = mticker.MaxNLocator(nbins=4)

result = sut.__repr__()
assert result.startswith("MaxNLocator(")
assert "nbins=4" in result
assert result.endswith(")")


class TestEvalReprImplementation:
def test_LogLocator(self):
sut = mticker.LogLocator(base=10, numticks=15)

result = eval(sut.__repr__(), {"array": np.array,
"LogLocator": mticker.LogLocator})

assert result.__class__ == sut.__class__
assert result._base == sut._base
assert result._subs == sut._subs

def test_NullLocator(self):
sut = mticker.NullFormatter()

result = eval(sut.__repr__(), {"NullFormatter": mticker.NullFormatter})

assert result.__class__ == sut.__class__

def test_MultipleLocator(self):
sut = mticker.MultipleLocator(0.5)

result = eval(sut.__repr__(), {"MultipleLocator": mticker.MultipleLocator})

assert result.__class__ == sut.__class__
assert result._edge.step == sut._edge.step

def test_FixedLocator(self):
sut = mticker.FixedLocator([0, 1, 5])

result = eval(sut.__repr__(), {"array": np.array,
"FixedLocator": mticker.FixedLocator})

assert result.__class__ == sut.__class__
assert np.array_equal(sut.locs, result.locs)

def test_LinearLocator(self):
sut = mticker.LinearLocator(numticks=3)

result = eval(sut.__repr__(), {"LinearLocator": mticker.LinearLocator})

assert result.__class__ == sut.__class__
assert result.numticks == sut.numticks

def test_IndexLocator(self):
sut = mticker.IndexLocator(base=0.5, offset=0.25)

result = eval(sut.__repr__(), {"IndexLocator": mticker.IndexLocator})

assert result.__class__ == sut.__class__
assert result._base == sut._base
assert result.offset == sut.offset

def test_AutoLocator(self):
sut = mticker.AutoLocator()

result = eval(sut.__repr__(), {"AutoLocator": mticker.AutoLocator})

assert result.__class__ == sut.__class__

def test_MaxNLocator(self):
sut = mticker.MaxNLocator(nbins=4)

result = eval(sut.__repr__(), {"array": np.array,
"MaxNLocator": mticker.MaxNLocator})

assert result.__class__ == sut.__class__
assert result._nbins == sut._nbins
Loading