Skip to content

Commit

Permalink
REF: remove unused box keyword from Timedelta64Formatter (#55417)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Oct 6, 2023
1 parent 7ec95e4 commit 494df5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
5 changes: 2 additions & 3 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1748,16 +1748,15 @@ def __init__(
self,
values: TimedeltaArray,
nat_rep: str = "NaT",
box: bool = False,
**kwargs,
) -> None:
# TODO: nat_rep is never passed, na_rep is.
super().__init__(values, **kwargs)
self.nat_rep = nat_rep
self.box = box

def _format_strings(self) -> list[str]:
formatter = self.formatter or get_format_timedelta64(
self.values, nat_rep=self.nat_rep, box=self.box
self.values, nat_rep=self.nat_rep, box=False
)
return [formatter(x) for x in self.values]

Expand Down
42 changes: 21 additions & 21 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3187,49 +3187,49 @@ def test_all(self):
class TestTimedelta64Formatter:
def test_days(self):
x = pd.to_timedelta(list(range(5)) + [NaT], unit="D")._values
result = fmt._Timedelta64Formatter(x, box=True).get_result()
assert result[0].strip() == "'0 days'"
assert result[1].strip() == "'1 days'"
result = fmt._Timedelta64Formatter(x).get_result()
assert result[0].strip() == "0 days"
assert result[1].strip() == "1 days"

result = fmt._Timedelta64Formatter(x[1:2], box=True).get_result()
assert result[0].strip() == "'1 days'"
result = fmt._Timedelta64Formatter(x[1:2]).get_result()
assert result[0].strip() == "1 days"

result = fmt._Timedelta64Formatter(x, box=False).get_result()
result = fmt._Timedelta64Formatter(x).get_result()
assert result[0].strip() == "0 days"
assert result[1].strip() == "1 days"

result = fmt._Timedelta64Formatter(x[1:2], box=False).get_result()
result = fmt._Timedelta64Formatter(x[1:2]).get_result()
assert result[0].strip() == "1 days"

def test_days_neg(self):
x = pd.to_timedelta(list(range(5)) + [NaT], unit="D")._values
result = fmt._Timedelta64Formatter(-x, box=True).get_result()
assert result[0].strip() == "'0 days'"
assert result[1].strip() == "'-1 days'"
result = fmt._Timedelta64Formatter(-x).get_result()
assert result[0].strip() == "0 days"
assert result[1].strip() == "-1 days"

def test_subdays(self):
y = pd.to_timedelta(list(range(5)) + [NaT], unit="s")._values
result = fmt._Timedelta64Formatter(y, box=True).get_result()
assert result[0].strip() == "'0 days 00:00:00'"
assert result[1].strip() == "'0 days 00:00:01'"
result = fmt._Timedelta64Formatter(y).get_result()
assert result[0].strip() == "0 days 00:00:00"
assert result[1].strip() == "0 days 00:00:01"

def test_subdays_neg(self):
y = pd.to_timedelta(list(range(5)) + [NaT], unit="s")._values
result = fmt._Timedelta64Formatter(-y, box=True).get_result()
assert result[0].strip() == "'0 days 00:00:00'"
assert result[1].strip() == "'-1 days +23:59:59'"
result = fmt._Timedelta64Formatter(-y).get_result()
assert result[0].strip() == "0 days 00:00:00"
assert result[1].strip() == "-1 days +23:59:59"

def test_zero(self):
x = pd.to_timedelta(list(range(1)) + [NaT], unit="D")._values
result = fmt._Timedelta64Formatter(x, box=True).get_result()
assert result[0].strip() == "'0 days'"
result = fmt._Timedelta64Formatter(x).get_result()
assert result[0].strip() == "0 days"

x = pd.to_timedelta(list(range(1)), unit="D")._values
result = fmt._Timedelta64Formatter(x, box=True).get_result()
assert result[0].strip() == "'0 days'"
result = fmt._Timedelta64Formatter(x).get_result()
assert result[0].strip() == "0 days"


class Test_Datetime64Formatter:
class TestDatetime64Formatter:
def test_mixed(self):
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 1, 12), NaT])._values
result = fmt._Datetime64Formatter(x).get_result()
Expand Down

0 comments on commit 494df5c

Please sign in to comment.