Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Tirthchoksi22 committed May 19, 2024
2 parents 621c8d1 + 593113a commit 50fe143
Show file tree
Hide file tree
Showing 22 changed files with 353 additions and 132 deletions.
17 changes: 0 additions & 17 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.cat.set_categories PR01,PR02" \
-i "pandas.Series.dt.as_unit PR01,PR02" \
-i "pandas.Series.dt.ceil PR01,PR02" \
-i "pandas.Series.dt.components SA01" \
-i "pandas.Series.dt.day_name PR01,PR02" \
-i "pandas.Series.dt.floor PR01,PR02" \
-i "pandas.Series.dt.freq GL08" \
Expand All @@ -165,12 +164,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.dt.tz_convert PR01,PR02" \
-i "pandas.Series.dt.tz_localize PR01,PR02" \
-i "pandas.Series.dt.unit GL08" \
-i "pandas.Series.eq SA01" \
-i "pandas.Series.ge SA01" \
-i "pandas.Series.gt SA01" \
-i "pandas.Series.kurt RT03,SA01" \
-i "pandas.Series.kurtosis RT03,SA01" \
-i "pandas.Series.le SA01" \
-i "pandas.Series.list.__getitem__ SA01" \
-i "pandas.Series.list.flatten SA01" \
-i "pandas.Series.list.len SA01" \
Expand Down Expand Up @@ -248,20 +243,15 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.TimedeltaIndex.nanoseconds SA01" \
-i "pandas.TimedeltaIndex.seconds SA01" \
-i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \
-i "pandas.Timestamp.astimezone SA01" \
-i "pandas.Timestamp.ceil SA01" \
-i "pandas.Timestamp.combine PR01,SA01" \
-i "pandas.Timestamp.ctime SA01" \
-i "pandas.Timestamp.date SA01" \
-i "pandas.Timestamp.day GL08" \
-i "pandas.Timestamp.dst SA01" \
-i "pandas.Timestamp.floor SA01" \
-i "pandas.Timestamp.fold GL08" \
-i "pandas.Timestamp.fromordinal SA01" \
-i "pandas.Timestamp.fromtimestamp PR01,SA01" \
-i "pandas.Timestamp.hour GL08" \
-i "pandas.Timestamp.is_leap_year SA01" \
-i "pandas.Timestamp.isocalendar SA01" \
-i "pandas.Timestamp.isoweekday SA01" \
-i "pandas.Timestamp.max PR02" \
-i "pandas.Timestamp.microsecond GL08" \
Expand All @@ -288,7 +278,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Timestamp.today SA01" \
-i "pandas.Timestamp.toordinal SA01" \
-i "pandas.Timestamp.tz SA01" \
-i "pandas.Timestamp.tz_convert SA01" \
-i "pandas.Timestamp.tz_localize SA01" \
-i "pandas.Timestamp.tzinfo GL08" \
-i "pandas.Timestamp.tzname SA01" \
Expand All @@ -299,7 +288,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Timestamp.value GL08" \
-i "pandas.Timestamp.weekday SA01" \
-i "pandas.Timestamp.year GL08" \
-i "pandas.api.extensions.ExtensionArray._from_sequence_of_strings SA01" \
-i "pandas.api.extensions.ExtensionArray._hash_pandas_object RT03,SA01" \
-i "pandas.api.extensions.ExtensionArray._pad_or_backfill PR01,RT03,SA01" \
-i "pandas.api.extensions.ExtensionArray._reduce RT03,SA01" \
Expand All @@ -308,7 +296,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.api.extensions.ExtensionArray.dropna RT03,SA01" \
-i "pandas.api.extensions.ExtensionArray.dtype SA01" \
-i "pandas.api.extensions.ExtensionArray.duplicated RT03,SA01" \
-i "pandas.api.extensions.ExtensionArray.equals SA01" \
-i "pandas.api.extensions.ExtensionArray.fillna SA01" \
-i "pandas.api.extensions.ExtensionArray.insert PR07,RT03,SA01" \
-i "pandas.api.extensions.ExtensionArray.interpolate PR01,SA01" \
Expand All @@ -324,7 +311,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.api.extensions.ExtensionArray.view SA01" \
-i "pandas.api.indexers.VariableOffsetWindowIndexer PR01,SA01" \
-i "pandas.api.interchange.from_dataframe RT03,SA01" \
-i "pandas.api.types.infer_dtype PR07,SA01" \
-i "pandas.api.types.is_any_real_numeric_dtype SA01" \
-i "pandas.api.types.is_bool PR01,SA01" \
-i "pandas.api.types.is_bool_dtype SA01" \
Expand Down Expand Up @@ -353,7 +339,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.api.types.is_period_dtype SA01" \
-i "pandas.api.types.is_re PR07,SA01" \
-i "pandas.api.types.is_re_compilable PR07,SA01" \
-i "pandas.api.types.is_scalar SA01" \
-i "pandas.api.types.is_signed_integer_dtype SA01" \
-i "pandas.api.types.is_sparse SA01" \
-i "pandas.api.types.is_string_dtype SA01" \
Expand Down Expand Up @@ -528,7 +513,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.testing.assert_index_equal PR07,SA01" \
-i "pandas.testing.assert_series_equal PR07,SA01" \
-i "pandas.timedelta_range SA01" \
-i "pandas.tseries.api.guess_datetime_format SA01" \
-i "pandas.tseries.offsets.BDay PR02,SA01" \
-i "pandas.tseries.offsets.BMonthBegin PR02" \
-i "pandas.tseries.offsets.BQuarterBegin PR02" \
Expand Down Expand Up @@ -651,7 +635,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.tseries.offsets.DateOffset.nanos GL08" \
-i "pandas.tseries.offsets.DateOffset.normalize GL08" \
-i "pandas.tseries.offsets.DateOffset.rule_code GL08" \
-i "pandas.tseries.offsets.Day PR02" \
-i "pandas.tseries.offsets.Day.freqstr SA01" \
-i "pandas.tseries.offsets.Day.is_on_offset GL08" \
-i "pandas.tseries.offsets.Day.n GL08" \
Expand Down
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ Removal of prior version deprecations/changes
- :func:`read_excel`, :func:`read_json`, :func:`read_html`, and :func:`read_xml` no longer accept raw string or byte representation of the data. That type of data must be wrapped in a :py:class:`StringIO` or :py:class:`BytesIO` (:issue:`53767`)
- :func:`to_datetime` with a ``unit`` specified no longer parses strings into floats, instead parses them the same way as without ``unit`` (:issue:`50735`)
- :meth:`DataFrame.groupby` with ``as_index=False`` and aggregation methods will no longer exclude from the result the groupings that do not arise from the input (:issue:`49519`)
- :meth:`ExtensionArray._reduce` now requires a ``keepdims: bool = False`` parameter in the signature (:issue:`52788`)
- :meth:`Series.dt.to_pydatetime` now returns a :class:`Series` of :py:class:`datetime.datetime` objects (:issue:`52459`)
- :meth:`SeriesGroupBy.agg` no longer pins the name of the group to the input passed to the provided ``func`` (:issue:`51703`)
- All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`)
Expand All @@ -246,6 +247,7 @@ Removal of prior version deprecations/changes
- Removed the "closed" and "normalize" keywords in :meth:`DatetimeIndex.__new__` (:issue:`52628`)
- Removed the deprecated ``delim_whitespace`` keyword in :func:`read_csv` and :func:`read_table`, use ``sep=r"\s+"`` instead (:issue:`55569`)
- Require :meth:`SparseDtype.fill_value` to be a valid value for the :meth:`SparseDtype.subtype` (:issue:`53043`)
- Stopped automatically casting non-datetimelike values (mainly strings) in :meth:`Series.isin` and :meth:`Index.isin` with ``datetime64``, ``timedelta64``, and :class:`PeriodDtype` dtypes (:issue:`53111`)
- Stopped performing dtype inference when setting a :class:`Index` into a :class:`DataFrame` (:issue:`56102`)
- Stopped performing dtype inference with in :meth:`Index.insert` with object-dtype index; this often affects the index/columns that result when setting new entries into an empty :class:`Series` or :class:`DataFrame` (:issue:`51363`)
- Removed the "closed" and "unit" keywords in :meth:`TimedeltaIndex.__new__` (:issue:`52628`, :issue:`55499`)
Expand Down Expand Up @@ -461,6 +463,7 @@ Plotting

Groupby/resample/rolling
^^^^^^^^^^^^^^^^^^^^^^^^
- Bug in :meth:`.DataFrameGroupBy.__len__` and :meth:`.SeriesGroupBy.__len__` would raise when the grouping contained NA values and ``dropna=False`` (:issue:`58644`)
- Bug in :meth:`.DataFrameGroupBy.groups` and :meth:`.SeriesGroupby.groups` that would not respect groupby argument ``dropna`` (:issue:`55919`)
- Bug in :meth:`.DataFrameGroupBy.median` where nat values gave an incorrect result. (:issue:`57926`)
- Bug in :meth:`.DataFrameGroupBy.quantile` when ``interpolation="nearest"`` is inconsistent with :meth:`DataFrame.quantile` (:issue:`47942`)
Expand Down
5 changes: 0 additions & 5 deletions pandas/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"describe_option",
"option_context",
"options",
"using_copy_on_write",
]
from pandas._config import config
from pandas._config import dates # pyright: ignore[reportUnusedImport] # noqa: F401
Expand All @@ -31,10 +30,6 @@
from pandas._config.display import detect_console_encoding


def using_copy_on_write() -> bool:
return True


def using_pyarrow_string_dtype() -> bool:
_mode_options = _global_config["future"]
return _mode_options["infer_string"]
16 changes: 16 additions & 0 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ def is_scalar(val: object) -> bool:
bool
Return True if given object is scalar.

See Also
--------
api.types.is_list_like : Check if the input is list-like.
api.types.is_integer : Check if the input is an integer.
api.types.is_float : Check if the input is a float.
api.types.is_bool : Check if the input is a boolean.

Examples
--------
>>> import datetime
Expand Down Expand Up @@ -1442,6 +1449,7 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
Parameters
----------
value : scalar, list, ndarray, or pandas type
The input data to infer the dtype.
skipna : bool, default True
Ignore NaN values when inferring the type.

Expand Down Expand Up @@ -1476,6 +1484,14 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
TypeError
If ndarray-like but cannot infer the dtype

See Also
--------
api.types.is_scalar : Check if the input is a scalar.
api.types.is_list_like : Check if the input is list-like.
api.types.is_integer : Check if the input is an integer.
api.types.is_float : Check if the input is a float.
api.types.is_bool : Check if the input is a boolean.

Notes
-----
- 'mixed' is the catchall for anything that is not otherwise
Expand Down
44 changes: 44 additions & 0 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,12 @@ class NaTType(_NaT):
"""
Return a named tuple containing ISO year, week number, and weekday.
See Also
--------
DatetimeIndex.isocalendar : Return a 3-tuple containing ISO year,
week number, and weekday for the given DatetimeIndex object.
datetime.date.isocalendar : The equivalent method for `datetime.date` objects.
Examples
--------
>>> ts = pd.Timestamp('2023-01-01 10:00:00')
Expand All @@ -542,6 +548,14 @@ class NaTType(_NaT):
"""
Return the daylight saving time (DST) adjustment.
This method returns the DST adjustment as a `datetime.timedelta` object
if the Timestamp is timezone-aware and DST is applicable.
See Also
--------
Timestamp.tz_localize : Localize the Timestamp to a timezone.
Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone.
Examples
--------
>>> ts = pd.Timestamp('2000-06-01 00:00:00', tz='Europe/Brussels')
Expand Down Expand Up @@ -814,6 +828,11 @@ class NaTType(_NaT):
"""
Convert timezone-aware Timestamp to another time zone.
This method is used to convert a timezone-aware Timestamp object to a
different time zone. The original UTC time remains the same; only the
time zone information is changed. If the Timestamp is timezone-naive, a
TypeError is raised.
Parameters
----------
tz : str, pytz.timezone, dateutil.tz.tzfile or None
Expand All @@ -829,6 +848,13 @@ class NaTType(_NaT):
TypeError
If Timestamp is tz-naive.
See Also
--------
Timestamp.tz_localize : Localize the Timestamp to a timezone.
DatetimeIndex.tz_convert : Convert a DatetimeIndex to another time zone.
DatetimeIndex.tz_localize : Localize a DatetimeIndex to a specific time zone.
datetime.datetime.astimezone : Convert a datetime object to another time zone.
Examples
--------
Create a timestamp object with UTC timezone:
Expand Down Expand Up @@ -1196,6 +1222,12 @@ timedelta}, default 'raise'
------
ValueError if the freq cannot be converted.
See Also
--------
Timestamp.floor : Round down a Timestamp to the specified resolution.
Timestamp.round : Round a Timestamp to the specified resolution.
Series.dt.ceil : Ceil the datetime values in a Series.
Notes
-----
If the Timestamp has a timezone, ceiling will take place relative to the
Expand Down Expand Up @@ -1256,6 +1288,11 @@ timedelta}, default 'raise'
"""
Convert timezone-aware Timestamp to another time zone.
This method is used to convert a timezone-aware Timestamp object to a
different time zone. The original UTC time remains the same; only the
time zone information is changed. If the Timestamp is timezone-naive, a
TypeError is raised.
Parameters
----------
tz : str, pytz.timezone, dateutil.tz.tzfile or None
Expand All @@ -1271,6 +1308,13 @@ timedelta}, default 'raise'
TypeError
If Timestamp is tz-naive.
See Also
--------
Timestamp.tz_localize : Localize the Timestamp to a timezone.
DatetimeIndex.tz_convert : Convert a DatetimeIndex to another time zone.
DatetimeIndex.tz_localize : Localize a DatetimeIndex to a specific time zone.
datetime.datetime.astimezone : Convert a datetime object to another time zone.
Examples
--------
Create a timestamp object with UTC timezone:
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ cdef class Day(Tick):
"""
Offset ``n`` days.
Parameters
Attributes
----------
n : int, default 1
The number of days represented.
Expand Down
10 changes: 10 additions & 0 deletions pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None:
"""
Guess the datetime format of a given datetime string.

This function attempts to deduce the format of a given datetime string. It is
useful for situations where the datetime format is unknown and needs to be
determined for proper parsing. The function is not guaranteed to return a format.

Parameters
----------
dt_str : str
Expand All @@ -876,6 +880,12 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None:
datetime format string (for `strftime` or `strptime`),
or None if it can't be guessed.

See Also
--------
to_datetime : Convert argument to datetime.
Timestamp : Pandas replacement for python datetime.datetime object.
DatetimeIndex : Immutable ndarray-like of datetime64 data.

Examples
--------
>>> from pandas.tseries.api import guess_datetime_format
Expand Down
43 changes: 43 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,20 @@ cdef class _Timestamp(ABCTimestamp):
"""
Return True if year is a leap year.

A leap year is a year, which has 366 days (instead of 365) including 29th of
February as an intercalary day. Leap years are years which are multiples of
four with the exception of years divisible by 100 but not by 400.

Returns
-------
bool
True if year is a leap year, else False

See Also
--------
Period.is_leap_year : Return True if the period’s year is in a leap year.
DatetimeIndex.is_leap_year : Boolean indicator if the date belongs to a
leap year.

Examples
--------
Expand Down Expand Up @@ -1658,6 +1669,14 @@ class Timestamp(_Timestamp):
"""
Return the daylight saving time (DST) adjustment.
This method returns the DST adjustment as a `datetime.timedelta` object
if the Timestamp is timezone-aware and DST is applicable.
See Also
--------
Timestamp.tz_localize : Localize the Timestamp to a timezone.
Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone.
Examples
--------
>>> ts = pd.Timestamp('2000-06-01 00:00:00', tz='Europe/Brussels')
Expand All @@ -1672,6 +1691,12 @@ class Timestamp(_Timestamp):
"""
Return a named tuple containing ISO year, week number, and weekday.
See Also
--------
DatetimeIndex.isocalendar : Return a 3-tuple containing ISO year,
week number, and weekday for the given DatetimeIndex object.
datetime.date.isocalendar : The equivalent method for `datetime.date` objects.
Examples
--------
>>> ts = pd.Timestamp('2023-01-01 10:00:00')
Expand Down Expand Up @@ -2266,6 +2291,12 @@ timedelta}, default 'raise'
------
ValueError if the freq cannot be converted.
See Also
--------
Timestamp.floor : Round down a Timestamp to the specified resolution.
Timestamp.round : Round a Timestamp to the specified resolution.
Series.dt.ceil : Ceil the datetime values in a Series.
Notes
-----
If the Timestamp has a timezone, ceiling will take place relative to the
Expand Down Expand Up @@ -2451,6 +2482,11 @@ default 'raise'
"""
Convert timezone-aware Timestamp to another time zone.
This method is used to convert a timezone-aware Timestamp object to a
different time zone. The original UTC time remains the same; only the
time zone information is changed. If the Timestamp is timezone-naive, a
TypeError is raised.
Parameters
----------
tz : str, pytz.timezone, dateutil.tz.tzfile or None
Expand All @@ -2466,6 +2502,13 @@ default 'raise'
TypeError
If Timestamp is tz-naive.
See Also
--------
Timestamp.tz_localize : Localize the Timestamp to a timezone.
DatetimeIndex.tz_convert : Convert a DatetimeIndex to another time zone.
DatetimeIndex.tz_localize : Localize a DatetimeIndex to a specific time zone.
datetime.datetime.astimezone : Convert a datetime object to another time zone.
Examples
--------
Create a timestamp object with UTC timezone:
Expand Down
Loading

0 comments on commit 50fe143

Please sign in to comment.