Skip to content

Conversation

@MarcoGorelli
Copy link
Member

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.
Comment on lines -90 to -94
if ts == "now":
return Timestamp.utcnow()
elif ts == "today":
return Timestamp.now().normalize()

Copy link
Member Author

Choose a reason for hiding this comment

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

this function is only used for testing of the ISO fastpath. there's no test that has 'now' or 'today', and they wouldn't test the ISO fastpath anyway, so might as well remove them

tz: tzinfo | None = ...,
format: str | None = ...,
na_rep: object = ...,
na_rep: str | float = ...,
Copy link
Member Author

Choose a reason for hiding this comment

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

format_array_from_datetime is only called from

def _format_native_types(
self, *, na_rep: str | float = "NaT", date_format=None, **kwargs
) -> npt.NDArray[np.object_]:
from pandas.io.formats.format import get_format_datetime64_from_values
fmt = get_format_datetime64_from_values(self, date_format)
return tslib.format_array_from_datetime(
self.asi8, tz=self.tz, format=fmt, na_rep=na_rep, reso=self._creso
)

, where na_rep can't be None

Comment on lines +47 to +57
result = index._format_native_types(date_format="%Y-%m-%d %H:%M:%S.%f")
expected = np.array(
["2017-01-01 00:00:00.000000", "NaT", "2017-01-03 00:00:00.000000"],
dtype=object,
)
tm.assert_numpy_array_equal(result, expected)

# invalid format
result = index._format_native_types(date_format="foo")
expected = np.array(["foo", "NaT", "foo"], dtype=object)
tm.assert_numpy_array_equal(result, expected)
Copy link
Member Author

Choose a reason for hiding this comment

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

just increasing coverage

("2011\\01\\02", datetime(2011, 1, 2)),
("2013-01-01 05:30:00", datetime(2013, 1, 1, 5, 30)),
("2013-1-1 5:30:00", datetime(2013, 1, 1, 5, 30)),
("2013-1-1 5:30:00+01:00", Timestamp(2013, 1, 1, 5, 30, tz="UTC+01:00")),
Copy link
Member Author

Choose a reason for hiding this comment

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

increasing coverage

@MarcoGorelli MarcoGorelli added Datetime Datetime data dtype Clean labels Dec 26, 2022
@MarcoGorelli MarcoGorelli changed the title CLN, TST: clean up, increase coverage in tslib.pyx CLN, TST: clean up and increase coverage in tslib.pyx Dec 26, 2022
@mroeschke mroeschke added this to the 2.0 milestone Dec 27, 2022
@mroeschke mroeschke merged commit 761b59f into pandas-dev:main Dec 27, 2022
@mroeschke
Copy link
Member

Thanks @MarcoGorelli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Clean Datetime Datetime data dtype

2 participants