Skip to content

Commit b5182ab

Browse files
authored
Merge pull request #8 from pandas-dev/master
Sync Fork from Upstream Repo
2 parents b5bc3a4 + bd63ece commit b5182ab

26 files changed

+146
-94
lines changed

doc/source/development/code_style.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,29 @@ For example:
127127
128128
value = str
129129
f"Unknown recived type, got: '{type(value).__name__}'"
130+
131+
132+
Imports (aim for absolute)
133+
==========================
134+
135+
In Python 3, absolute imports are recommended. In absolute import doing something
136+
like ``import string`` will import the string module rather than ``string.py``
137+
in the same directory. As much as possible, you should try to write out
138+
absolute imports that show the whole import chain from toplevel pandas.
139+
140+
Explicit relative imports are also supported in Python 3. But it is not
141+
recommended to use it. Implicit relative imports should never be used
142+
and is removed in Python 3.
143+
144+
For example:
145+
146+
::
147+
148+
# preferred
149+
import pandas.core.common as com
150+
151+
# not preferred
152+
from .common import test_base
153+
154+
# wrong
155+
from common import test_base

doc/source/whatsnew/v0.25.3.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ Groupby/resample/rolling
1919
Contributors
2020
~~~~~~~~~~~~
2121

22-
.. contributors:: v0.25.2..HEAD
22+
.. contributors:: v0.25.2..v0.25.3

doc/source/whatsnew/v1.0.0.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,13 @@ Other enhancements
218218
now preserve those data types with pyarrow >= 0.16.0 (:issue:`20612`, :issue:`28371`).
219219
- The ``partition_cols`` argument in :meth:`DataFrame.to_parquet` now accepts a string (:issue:`27117`)
220220
- :func:`pandas.read_json` now parses ``NaN``, ``Infinity`` and ``-Infinity`` (:issue:`12213`)
221-
- The ``pandas.np`` submodule is now deprecated. Import numpy directly instead (:issue:`30296`)
222221
- :func:`to_parquet` now appropriately handles the ``schema`` argument for user defined schemas in the pyarrow engine. (:issue:`30270`)
223222
- DataFrame constructor preserve `ExtensionArray` dtype with `ExtensionArray` (:issue:`11363`)
224223
- :meth:`DataFrame.sort_values` and :meth:`Series.sort_values` have gained ``ignore_index`` keyword to be able to reset index after sorting (:issue:`30114`)
225224
- :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` have gained ``ignore_index`` keyword to reset index (:issue:`30114`)
226225
- :meth:`DataFrame.drop_duplicates` has gained ``ignore_index`` keyword to reset index (:issue:`30114`)
227226
- Added new writer for exporting Stata dta files in version 118, ``StataWriter118``. This format supports exporting strings containing Unicode characters (:issue:`23573`)
228227
- :meth:`Series.map` now accepts ``collections.abc.Mapping`` subclasses as a mapper (:issue:`29733`)
229-
- The ``pandas.datetime`` class is now deprecated. Import from ``datetime`` instead (:issue:`30296`)
230228
- Added an experimental :attr:`~DataFrame.attrs` for storing global metadata about a dataset (:issue:`29062`)
231229
- :meth:`Timestamp.fromisocalendar` is now compatible with python 3.8 and above (:issue:`28115`)
232230
- :meth:`DataFrame.to_pickle` and :func:`read_pickle` now accept URL (:issue:`30163`)
@@ -707,6 +705,8 @@ Deprecations
707705
- ``pandas.SparseArray`` has been deprecated. Use ``pandas.arrays.SparseArray`` (:class:`arrays.SparseArray`) instead. (:issue:`30642`)
708706
- The parameter ``is_copy`` of :meth:`DataFrame.take` has been deprecated and will be removed in a future version. (:issue:`27357`)
709707
- Support for multi-dimensional indexing (e.g. ``index[:, None]``) on a :class:`Index` is deprecated and will be removed in a future version, convert to a numpy array before indexing instead (:issue:`30588`)
708+
- The ``pandas.np`` submodule is now deprecated. Import numpy directly instead (:issue:`30296`)
709+
- The ``pandas.datetime`` class is now deprecated. Import from ``datetime`` instead (:issue:`30610`)
710710

711711
**Selecting Columns from a Grouped DataFrame**
712712

@@ -1177,3 +1177,5 @@ Other
11771177

11781178
Contributors
11791179
~~~~~~~~~~~~
1180+
1181+
.. contributors:: v0.25.3..v1.0.0rc0

pandas/_libs/algos.pyx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,7 @@ def rank_1d(rank_t[:] in_arr, ties_method='average',
914914
ranks[argsorted[j]] = i + 1
915915
elif tiebreak == TIEBREAK_FIRST:
916916
if rank_t is object:
917-
raise ValueError('first not supported for '
918-
'non-numeric data')
917+
raise ValueError('first not supported for non-numeric data')
919918
else:
920919
for j in range(i - dups + 1, i + 1):
921920
ranks[argsorted[j]] = j + 1
@@ -971,8 +970,7 @@ def rank_1d(rank_t[:] in_arr, ties_method='average',
971970
ranks[argsorted[j]] = i + 1
972971
elif tiebreak == TIEBREAK_FIRST:
973972
if rank_t is object:
974-
raise ValueError('first not supported for '
975-
'non-numeric data')
973+
raise ValueError('first not supported for non-numeric data')
976974
else:
977975
for j in range(i - dups + 1, i + 1):
978976
ranks[argsorted[j]] = j + 1
@@ -1137,8 +1135,7 @@ def rank_2d(rank_t[:, :] in_arr, axis=0, ties_method='average',
11371135
ranks[i, argsorted[i, z]] = j + 1
11381136
elif tiebreak == TIEBREAK_FIRST:
11391137
if rank_t is object:
1140-
raise ValueError('first not supported '
1141-
'for non-numeric data')
1138+
raise ValueError('first not supported for non-numeric data')
11421139
else:
11431140
for z in range(j - dups + 1, j + 1):
11441141
ranks[i, argsorted[i, z]] = z + 1

pandas/_libs/groupby.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,7 @@ def _group_ohlc(floating[:, :] out,
686686
raise ValueError('Output array must have 4 columns')
687687

688688
if K > 1:
689-
raise NotImplementedError("Argument 'values' must have only "
690-
"one dimension")
689+
raise NotImplementedError("Argument 'values' must have only one dimension")
691690
out[:] = np.nan
692691

693692
with nogil:

pandas/_libs/hashing.pyx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def hash_object_array(object[:] arr, object key, object encoding='utf8'):
5151
k = <bytes>key.encode(encoding)
5252
kb = <uint8_t *>k
5353
if len(k) != 16:
54-
raise ValueError("key should be a 16-byte string encoded, "
55-
f"got {k} (len {len(k)})")
54+
raise ValueError(
55+
f"key should be a 16-byte string encoded, got {k} (len {len(k)})"
56+
)
5657

5758
n = len(arr)
5859

@@ -77,8 +78,10 @@ def hash_object_array(object[:] arr, object key, object encoding='utf8'):
7778
hash(val)
7879
data = <bytes>str(val).encode(encoding)
7980
else:
80-
raise TypeError(f"{val} of type {type(val)} is not a valid type "
81-
"for hashing, must be string or null")
81+
raise TypeError(
82+
f"{val} of type {type(val)} is not a valid type for hashing, "
83+
"must be string or null"
84+
)
8285

8386
l = len(data)
8487
lens[i] = l

pandas/_libs/indexing.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cdef class _NDFrameIndexerBase:
1818
if ndim is None:
1919
ndim = self._ndim = self.obj.ndim
2020
if ndim > 2:
21-
raise ValueError("NDFrameIndexer does not support "
22-
"NDFrame objects with ndim > 2")
21+
raise ValueError(
22+
"NDFrameIndexer does not support NDFrame objects with ndim > 2"
23+
)
2324
return ndim

pandas/_libs/sparse.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ cdef class IntIndex(SparseIndex):
7272
"""
7373

7474
if self.npoints > self.length:
75-
msg = (f"Too many indices. Expected "
76-
f"{self.length} but found {self.npoints}")
77-
raise ValueError(msg)
75+
raise ValueError(
76+
f"Too many indices. Expected {self.length} but found {self.npoints}"
77+
)
7878

7979
# Indices are vacuously ordered and non-negative
8080
# if the sequence of indices is empty.

pandas/_libs/testing.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ cpdef assert_almost_equal(a, b,
127127
# classes can't be the same, to raise error
128128
assert_class_equal(a, b, obj=obj)
129129

130-
assert has_length(a) and has_length(b), ("Can't compare objects without "
131-
"length, one or both is invalid: "
132-
f"({a}, {b})")
130+
assert has_length(a) and has_length(b), (
131+
f"Can't compare objects without length, one or both is invalid: ({a}, {b})"
132+
)
133133

134134
if a_is_ndarray and b_is_ndarray:
135135
na, nb = a.size, b.size

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ def round_nsint64(values, mode, freq):
161161

162162
# if/elif above should catch all rounding modes defined in enum 'RoundTo':
163163
# if flow of control arrives here, it is a bug
164-
raise ValueError("round_nsint64 called with an unrecognized "
165-
"rounding mode")
164+
raise ValueError("round_nsint64 called with an unrecognized rounding mode")
166165

167166

168167
# ----------------------------------------------------------------------
@@ -324,8 +323,10 @@ class Timestamp(_Timestamp):
324323
325324
Function is not implemented. Use pd.to_datetime().
326325
"""
327-
raise NotImplementedError("Timestamp.strptime() is not implemented."
328-
"Use to_datetime() to parse date strings.")
326+
raise NotImplementedError(
327+
"Timestamp.strptime() is not implemented. "
328+
"Use to_datetime() to parse date strings."
329+
)
329330

330331
@classmethod
331332
def combine(cls, date, time):
@@ -381,8 +382,9 @@ class Timestamp(_Timestamp):
381382
if tzinfo is not None:
382383
if not PyTZInfo_Check(tzinfo):
383384
# tzinfo must be a datetime.tzinfo object, GH#17690
384-
raise TypeError(f'tzinfo must be a datetime.tzinfo object, '
385-
f'not {type(tzinfo)}')
385+
raise TypeError(
386+
f"tzinfo must be a datetime.tzinfo object, not {type(tzinfo)}"
387+
)
386388
elif tz is not None:
387389
raise ValueError('Can provide at most one of tz, tzinfo')
388390

@@ -393,8 +395,10 @@ class Timestamp(_Timestamp):
393395
# User passed a date string to parse.
394396
# Check that the user didn't also pass a date attribute kwarg.
395397
if any(arg is not None for arg in _date_attributes):
396-
raise ValueError('Cannot pass a date attribute keyword '
397-
'argument when passing a date string')
398+
raise ValueError(
399+
"Cannot pass a date attribute keyword "
400+
"argument when passing a date string"
401+
)
398402

399403
elif ts_input is _no_input:
400404
# User passed keyword arguments.
@@ -578,8 +582,10 @@ timedelta}, default 'raise'
578582
@tz.setter
579583
def tz(self, value):
580584
# GH 3746: Prevent localizing or converting the index by setting tz
581-
raise AttributeError("Cannot directly set timezone. Use tz_localize() "
582-
"or tz_convert() as appropriate")
585+
raise AttributeError(
586+
"Cannot directly set timezone. "
587+
"Use tz_localize() or tz_convert() as appropriate"
588+
)
583589

584590
def __setstate__(self, state):
585591
self.value = state[0]
@@ -598,9 +604,10 @@ timedelta}, default 'raise'
598604

599605
if self.tz is not None:
600606
# GH#21333
601-
warnings.warn("Converting to Period representation will "
602-
"drop timezone information.",
603-
UserWarning)
607+
warnings.warn(
608+
"Converting to Period representation will drop timezone information.",
609+
UserWarning,
610+
)
604611

605612
if freq is None:
606613
freq = self.freq
@@ -810,13 +817,13 @@ default 'raise'
810817
if ambiguous == 'infer':
811818
raise ValueError('Cannot infer offset with only one time.')
812819

813-
nonexistent_options = ('raise', 'NaT', 'shift_forward',
814-
'shift_backward')
820+
nonexistent_options = ('raise', 'NaT', 'shift_forward', 'shift_backward')
815821
if nonexistent not in nonexistent_options and not isinstance(
816822
nonexistent, timedelta):
817-
raise ValueError("The nonexistent argument must be one of 'raise', "
818-
"'NaT', 'shift_forward', 'shift_backward' or "
819-
"a timedelta object")
823+
raise ValueError(
824+
"The nonexistent argument must be one of 'raise', "
825+
"'NaT', 'shift_forward', 'shift_backward' or a timedelta object"
826+
)
820827

821828
if self.tzinfo is None:
822829
# tz naive, localize
@@ -833,8 +840,9 @@ default 'raise'
833840
value = tz_convert_single(self.value, UTC, self.tz)
834841
return Timestamp(value, tz=tz, freq=self.freq)
835842
else:
836-
raise TypeError('Cannot localize tz-aware Timestamp, use '
837-
'tz_convert for conversions')
843+
raise TypeError(
844+
"Cannot localize tz-aware Timestamp, use tz_convert for conversions"
845+
)
838846

839847
def tz_convert(self, tz):
840848
"""
@@ -857,17 +865,28 @@ default 'raise'
857865
"""
858866
if self.tzinfo is None:
859867
# tz naive, use tz_localize
860-
raise TypeError('Cannot convert tz-naive Timestamp, use '
861-
'tz_localize to localize')
868+
raise TypeError(
869+
"Cannot convert tz-naive Timestamp, use tz_localize to localize"
870+
)
862871
else:
863872
# Same UTC timestamp, different time zone
864873
return Timestamp(self.value, tz=tz, freq=self.freq)
865874

866875
astimezone = tz_convert
867876

868-
def replace(self, year=None, month=None, day=None,
869-
hour=None, minute=None, second=None, microsecond=None,
870-
nanosecond=None, tzinfo=object, fold=0):
877+
def replace(
878+
self,
879+
year=None,
880+
month=None,
881+
day=None,
882+
hour=None,
883+
minute=None,
884+
second=None,
885+
microsecond=None,
886+
nanosecond=None,
887+
tzinfo=object,
888+
fold=0,
889+
):
871890
"""
872891
implements datetime.replace, handles nanoseconds.
873892
@@ -910,8 +929,9 @@ default 'raise'
910929
def validate(k, v):
911930
""" validate integers """
912931
if not is_integer_object(v):
913-
raise ValueError(f"value must be an integer, received "
914-
f"{type(v)} for {k}")
932+
raise ValueError(
933+
f"value must be an integer, received {type(v)} for {k}"
934+
)
915935
return v
916936

917937
if year is not None:

pandas/_libs/window/aggregations.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,8 +1871,7 @@ def ewmcov(float64_t[:] input_x, float64_t[:] input_y,
18711871
bint is_observation
18721872

18731873
if <Py_ssize_t>len(input_y) != N:
1874-
raise ValueError(f"arrays are of different lengths "
1875-
f"({N} and {len(input_y)})")
1874+
raise ValueError(f"arrays are of different lengths ({N} and {len(input_y)})")
18761875

18771876
output = np.empty(N, dtype=float)
18781877
if N == 0:

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class NDFrame(PandasObject, SelectionMixin, indexing.IndexingMixin):
177177
]
178178
_internal_names_set: Set[str] = set(_internal_names)
179179
_accessors: Set[str] = set()
180-
_deprecations: FrozenSet[str] = frozenset(["get_values", "ix"])
180+
_deprecations: FrozenSet[str] = frozenset(["get_values"])
181181
_metadata: List[str] = []
182182
_is_copy = None
183183
_data: BlockManager

0 commit comments

Comments
 (0)