Skip to content

DOC: Fix quotes position in Timestamp and Timedelta #24243

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

Closed
wants to merge 12 commits into from
Closed
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
42 changes: 28 additions & 14 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ def array_to_timedelta64(object[:] values, unit='ns', errors='raise'):


cdef inline int64_t cast_from_unit(object ts, object unit) except? -1:
""" return a casting of the unit represented to nanoseconds
round the fractional part of a float to our precision, p """
"""
return a casting of the unit represented to nanoseconds
round the fractional part of a float to our precision, p
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not aligned here

cdef:
int64_t m
int p
Expand Down Expand Up @@ -482,7 +484,6 @@ cdef inline parse_timedelta_string(object ts):

cdef inline int64_t timedelta_as_neg(int64_t value, bint neg):
"""

Parameters
----------
value : int64_t of the timedelta value
Expand All @@ -495,7 +496,6 @@ cdef inline int64_t timedelta_as_neg(int64_t value, bint neg):

cdef inline timedelta_from_spec(object number, object frac, object unit):
"""

Parameters
----------
number : a list of number digits
Expand Down Expand Up @@ -739,9 +739,18 @@ cdef _to_py_int_float(v):
# heavy lifting.
cdef class _Timedelta(timedelta):
cdef readonly:
int64_t value # nanoseconds
object freq # frequency reference
bint is_populated # are my components populated
int64_t value
Copy link
Contributor

Choose a reason for hiding this comment

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

huh? this is so much harder to read, just revert this

"""
nanoseconds
"""
object freq
"""
frequency reference
"""
bint is_populated
"""
are my components populated
"""
int64_t _d, _h, _m, _s, _ms, _us, _ns

# higher than np.ndarray and np.matrix
Expand Down Expand Up @@ -813,7 +822,9 @@ cdef class _Timedelta(timedelta):
return timedelta(microseconds=int(self.value) / 1000)

def to_timedelta64(self):
""" Returns a numpy.timedelta64 object with 'ns' precision """
"""
Returns a numpy.timedelta64 object with 'ns' precision
"""
return np.timedelta64(self.value, 'ns')

def total_seconds(self):
Expand All @@ -823,12 +834,16 @@ cdef class _Timedelta(timedelta):
return self.value / 1e9

def view(self, dtype):
""" array view compat """
"""
array view compat
"""
return np.timedelta64(self.value).view(dtype)

@property
def components(self):
""" Return a Components NamedTuple-like """
"""
Return a Components NamedTuple-like
"""
self._ensure_components()
# return the named tuple
return Components(self._d, self._h, self._m, self._s,
Expand Down Expand Up @@ -897,6 +912,7 @@ cdef class _Timedelta(timedelta):
>>> td.asm8
numpy.timedelta64(42,'ns')
"""

return np.int64(self.value).view('m8[ns]')

@property
Expand Down Expand Up @@ -993,15 +1009,13 @@ cdef class _Timedelta(timedelta):

def _repr_base(self, format=None):
"""

Parameters
----------
format : None|all|sub_day|long

Returns
-------
converted : string of a Timedelta

"""
cdef object sign, seconds_pretty, subs, fmt, comp_dict

Expand Down Expand Up @@ -1127,7 +1141,6 @@ class Timedelta(_Timedelta):
Notes
-----
The ``.value`` attribute is always in ns.

"""
def __new__(cls, object value=_no_input, unit=None, **kwargs):
cdef _Timedelta td_base
Expand Down Expand Up @@ -1473,7 +1486,8 @@ cdef _rfloordiv(int64_t value, right):
cdef _broadcast_floordiv_td64(int64_t value, object other,
object (*operation)(int64_t value,
object right)):
"""Boilerplate code shared by Timedelta.__floordiv__ and
"""
Boilerplate code shared by Timedelta.__floordiv__ and
Timedelta.__rfloordiv__ because np.timedelta64 does not implement these.

Parameters
Expand Down
27 changes: 20 additions & 7 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def maybe_integer_op_deprecated(obj):
cdef inline object create_timestamp_from_ts(int64_t value,
npy_datetimestruct dts,
object tz, object freq):
""" convenience routine to construct a Timestamp from its parts """
"""
onvenience routine to construct a Timestamp from its parts
"""
cdef _Timestamp ts_base
ts_base = _Timestamp.__new__(Timestamp, dts.year, dts.month,
dts.day, dts.hour, dts.min,
Expand Down Expand Up @@ -113,7 +115,9 @@ class RoundTo(enum.Enum):


cdef inline _npdivmod(x1, x2):
"""implement divmod for numpy < 1.13"""
"""
implement divmod for numpy < 1.13
"""
return np.floor_divide(x1, x2), np.remainder(x1, x2)


Expand Down Expand Up @@ -326,7 +330,9 @@ cdef class _Timestamp(datetime):
self.microsecond, self.tzinfo)

cpdef to_datetime64(self):
""" Returns a numpy.datetime64 object with 'ns' precision """
"""
Returns a numpy.datetime64 object with 'ns' precision
"""
return np.datetime64(self.value, 'ns')

def __add__(self, other):
Expand Down Expand Up @@ -413,7 +419,9 @@ cdef class _Timestamp(datetime):
return datetime.__sub__(self, other)

cdef int64_t _maybe_convert_value_to_local(self):
"""Convert UTC i8 value to local i8 value if tz exists"""
"""
Convert UTC i8 value to local i8 value if tz exists
"""
cdef:
int64_t val
val = self.value
Expand Down Expand Up @@ -500,7 +508,9 @@ cdef class _Timestamp(datetime):
return Timedelta(nanoseconds=1)

def timestamp(self):
"""Return POSIX timestamp as float."""
"""
Return POSIX timestamp as float.
"""
# py27 compat, see GH#17329
return round(self.value / 1e9, 6)

Expand All @@ -512,7 +522,8 @@ cdef class _Timestamp(datetime):


class Timestamp(_Timestamp):
"""Pandas replacement for datetime.datetime
"""
Pandas replacement for datetime.datetime

Timestamp is the pandas equivalent of python's Datetime
and is interchangeable with it in most cases. It's the type used
Expand Down Expand Up @@ -1189,7 +1200,9 @@ class Timestamp(_Timestamp):

# replace
def validate(k, v):
""" validate integers """
"""
validate integers
"""
if not is_integer_object(v):
raise ValueError("value must be an integer, received "
"{v} for {k}".format(v=type(v), k=k))
Expand Down
22 changes: 16 additions & 6 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@


def _new_DatetimeIndex(cls, d):
""" This is called upon unpickling, rather than the default which doesn't
have arguments and breaks __new__ """
"""
This is called upon unpickling, rather than the default which doesn't
have arguments and breaks __new__
"""

# data are already in UTC
# so need to localize
Expand Down Expand Up @@ -397,7 +399,9 @@ def nbytes(self):

@cache_readonly
def _is_dates_only(self):
"""Return a boolean if we are only dates (and don't have a timezone)"""
"""
Return a boolean if we are only dates (and don't have a timezone)
"""
from pandas.io.formats.format import _is_dates_only
return _is_dates_only(self.values) and self.tz is None

Expand All @@ -411,7 +415,9 @@ def __reduce__(self):
return _new_DatetimeIndex, (self.__class__, d), None

def __setstate__(self, state):
"""Necessary for making this object picklable"""
"""
Necessary for making this object picklable
"""
if isinstance(state, dict):
super(DatetimeIndex, self).__setstate__(state)

Expand Down Expand Up @@ -439,13 +445,17 @@ def __setstate__(self, state):
_unpickle_compat = __setstate__

def _convert_for_op(self, value):
""" Convert value to be insertable to ndarray """
"""
Convert value to be insertable to ndarray
"""
if self._has_same_tz(value):
return _to_m8(value)
raise ValueError('Passed item and index have different timezone')

def _maybe_update_attributes(self, attrs):
""" Update Index attributes (e.g. freq) depending on op """
"""
Update Index attributes (e.g. freq) depending on op
"""
freq = attrs.get('freq', None)
if freq is not None:
# no need to infer if freq is None
Expand Down
35 changes: 26 additions & 9 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" define the IntervalIndex """
"""
define the IntervalIndex
"""
import textwrap
import warnings

Expand Down Expand Up @@ -225,7 +227,9 @@ def _shallow_copy(self, left=None, right=None, **kwargs):

@cache_readonly
def _isnan(self):
"""Return a mask indicating if each value is NA"""
"""
Return a mask indicating if each value is NA
"""
if self._mask is None:
self._mask = isna(self.left)
return self._mask
Expand Down Expand Up @@ -381,7 +385,9 @@ def _ndarray_values(self):
return np.array(self._data)

def __array__(self, result=None):
""" the array interface, return my values """
"""
the array interface, return my values
"""
return self._ndarray_values

def __array_wrap__(self, result, context=None):
Expand Down Expand Up @@ -413,12 +419,16 @@ def astype(self, dtype, copy=True):

@cache_readonly
def dtype(self):
"""Return the dtype object of the underlying data"""
"""
Return the dtype object of the underlying data
"""
return self._data.dtype

@property
def inferred_type(self):
"""Return a string of the type inferred from the values"""
"""
Return a string of the type inferred from the values
"""
return 'interval'

@Appender(Index.memory_usage.__doc__)
Expand Down Expand Up @@ -718,7 +728,8 @@ def _find_non_overlapping_monotonic_bounds(self, key):
return start, stop

def get_loc(self, key, method=None):
"""Get integer location, slice or boolean mask for requested label.
"""
Get integer location, slice or boolean mask for requested label.

Parameters
----------
Expand Down Expand Up @@ -1014,7 +1025,9 @@ def _format_with_header(self, header, **kwargs):
return header + list(self._format_native_types(**kwargs))

def _format_native_types(self, na_rep='', quoting=None, **kwargs):
""" actually format my specific types """
"""
actually format my specific types
"""
from pandas.io.formats.format import IntervalArrayFormatter
return IntervalArrayFormatter(values=self,
na_rep=na_rep,
Expand Down Expand Up @@ -1140,15 +1153,19 @@ def is_all_dates(self):


def _is_valid_endpoint(endpoint):
"""helper for interval_range to check if start/end are valid types"""
"""
helper for interval_range to check if start/end are valid types
"""
return any([is_number(endpoint),
isinstance(endpoint, Timestamp),
isinstance(endpoint, Timedelta),
endpoint is None])


def _is_type_compatible(a, b):
"""helper for interval_range to check type compat of start/end/freq"""
"""
helper for interval_range to check type compat of start/end/freq
"""
is_ts_compat = lambda x: isinstance(x, (Timestamp, DateOffset))
is_td_compat = lambda x: isinstance(x, (Timedelta, DateOffset))
return ((is_number(a) and is_number(b)) or
Expand Down
Loading