Skip to content

Commit 81c5aa5

Browse files
author
MomIsBestFriend
committed
Merge remote-tracking branch 'upstream/master' into STY-repr-batch-3
2 parents c18cf48 + acbba97 commit 81c5aa5

File tree

7 files changed

+66
-57
lines changed

7 files changed

+66
-57
lines changed

ci/deps/azure-windows-36.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies:
2020
- numexpr
2121
- numpy=1.15.*
2222
- openpyxl
23+
- jinja2
2324
- pyarrow>=0.12.0
2425
- pytables
2526
- python-dateutil

pandas/io/pytables.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import pandas.core.common as com
5959
from pandas.core.computation.pytables import PyTablesExpr, maybe_expression
6060
from pandas.core.index import ensure_index
61-
from pandas.core.internals import BlockManager, _block_shape, make_block
6261

6362
from pandas.io.common import _stringify_path
6463
from pandas.io.formats.printing import adjoin, pprint_thing
@@ -2392,7 +2391,7 @@ def set_atom_categorical(self, block, items, info=None):
23922391
# write the codes; must be in a block shape
23932392
self.ordered = values.ordered
23942393
self.typ = self.get_atom_data(block, kind=codes.dtype.name)
2395-
self.set_data(_block_shape(codes))
2394+
self.set_data(codes)
23962395

23972396
# write the categories
23982397
self.meta = "category"
@@ -3186,17 +3185,23 @@ def read(
31863185
axes.append(ax)
31873186

31883187
items = axes[0]
3189-
blocks = []
3188+
dfs = []
3189+
31903190
for i in range(self.nblocks):
31913191

31923192
blk_items = self.read_index(f"block{i}_items")
31933193
values = self.read_array(f"block{i}_values", start=_start, stop=_stop)
3194-
blk = make_block(
3195-
values, placement=items.get_indexer(blk_items), ndim=len(axes)
3196-
)
3197-
blocks.append(blk)
31983194

3199-
return self.obj_type(BlockManager(blocks, axes))
3195+
columns = items[items.get_indexer(blk_items)]
3196+
df = DataFrame(values.T, columns=columns, index=axes[1])
3197+
dfs.append(df)
3198+
3199+
if len(dfs) > 0:
3200+
out = concat(dfs, axis=1)
3201+
out = out.reindex(columns=items, copy=False)
3202+
return out
3203+
3204+
return DataFrame(columns=axes[0], index=axes[1])
32003205

32013206
def write(self, obj, **kwargs):
32023207
super().write(obj, **kwargs)
@@ -4432,9 +4437,15 @@ def read(
44324437
if values.ndim == 1 and isinstance(values, np.ndarray):
44334438
values = values.reshape((1, values.shape[0]))
44344439

4435-
block = make_block(values, placement=np.arange(len(cols_)), ndim=2)
4436-
mgr = BlockManager([block], [cols_, index_])
4437-
frames.append(DataFrame(mgr))
4440+
if isinstance(values, np.ndarray):
4441+
df = DataFrame(values.T, columns=cols_, index=index_)
4442+
elif isinstance(values, Index):
4443+
df = DataFrame(values, columns=cols_, index=index_)
4444+
else:
4445+
# Categorical
4446+
df = DataFrame([values], columns=cols_, index=index_)
4447+
assert (df.dtypes == values.dtype).all(), (df.dtypes, values.dtype)
4448+
frames.append(df)
44384449

44394450
if len(frames) == 1:
44404451
df = frames[0]

pandas/tests/arithmetic/test_datetime64.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ class TestDatetime64SeriesComparison:
171171
],
172172
)
173173
@pytest.mark.parametrize("reverse", [True, False])
174-
@pytest.mark.parametrize("box", [Series, pd.Index])
175174
@pytest.mark.parametrize("dtype", [None, object])
176-
def test_nat_comparisons(self, dtype, box, reverse, pair):
175+
def test_nat_comparisons(self, dtype, index_or_series, reverse, pair):
176+
box = index_or_series
177177
l, r = pair
178178
if reverse:
179179
# add lhs / rhs switched data
@@ -2383,14 +2383,16 @@ def test_dti_add_series(self, tz, names):
23832383
result4 = index + ser.values
23842384
tm.assert_index_equal(result4, expected)
23852385

2386-
@pytest.mark.parametrize("other_box", [pd.Index, Series])
23872386
@pytest.mark.parametrize("op", [operator.add, roperator.radd, operator.sub])
23882387
@pytest.mark.parametrize(
23892388
"names", [(None, None, None), ("foo", "bar", None), ("foo", "foo", "foo")]
23902389
)
2391-
def test_dti_addsub_offset_arraylike(self, tz_naive_fixture, names, op, other_box):
2390+
def test_dti_addsub_offset_arraylike(
2391+
self, tz_naive_fixture, names, op, index_or_series
2392+
):
23922393
# GH#18849, GH#19744
23932394
box = pd.Index
2395+
other_box = index_or_series
23942396
from .test_timedelta64 import get_upcast_box
23952397

23962398
tz = tz_naive_fixture

pandas/tests/frame/test_dtypes.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55
import pytest
66

7-
from pandas.core.dtypes.dtypes import CategoricalDtype, DatetimeTZDtype
7+
from pandas.core.dtypes.dtypes import CategoricalDtype, DatetimeTZDtype, IntervalDtype
88

99
import pandas as pd
1010
from pandas import (
@@ -699,14 +699,7 @@ def test_astype_categorical(self, dtype):
699699
expected = DataFrame({k: Categorical(d[k], dtype=dtype) for k in d})
700700
tm.assert_frame_equal(result, expected)
701701

702-
@pytest.mark.parametrize(
703-
"cls",
704-
[
705-
pd.api.types.CategoricalDtype,
706-
pd.api.types.DatetimeTZDtype,
707-
pd.api.types.IntervalDtype,
708-
],
709-
)
702+
@pytest.mark.parametrize("cls", [CategoricalDtype, DatetimeTZDtype, IntervalDtype])
710703
def test_astype_categoricaldtype_class_raises(self, cls):
711704
df = DataFrame({"A": ["a", "a", "b", "c"]})
712705
xpr = "Expected an instance of {}".format(cls.__name__)

pandas/tests/test_downstream.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ def test_pandas_datareader():
102102

103103

104104
# importing from pandas, Cython import warning
105-
@pytest.mark.filterwarnings("ignore:The 'warn':DeprecationWarning")
106-
@pytest.mark.filterwarnings("ignore:pandas.util:DeprecationWarning")
107105
@pytest.mark.filterwarnings("ignore:can't resolve:ImportWarning")
108-
@pytest.mark.skip(reason="gh-25778: geopandas stack issue")
109106
def test_geopandas():
110107

111108
geopandas = import_module("geopandas") # noqa

pandas/tests/test_nanops.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def setup_method(self, method):
2424
np.random.seed(11235)
2525
nanops._USE_BOTTLENECK = False
2626

27-
arr_shape = (11, 7, 5)
27+
arr_shape = (11, 7)
2828

2929
self.arr_float = np.random.randn(*arr_shape)
3030
self.arr_float1 = np.random.randn(*arr_shape)
@@ -68,21 +68,21 @@ def setup_method(self, method):
6868
self.arr_nan_infj = self.arr_inf * 1j
6969
self.arr_complex_nan_infj = np.vstack([self.arr_complex, self.arr_nan_infj])
7070

71-
self.arr_float_2d = self.arr_float[:, :, 0]
72-
self.arr_float1_2d = self.arr_float1[:, :, 0]
71+
self.arr_float_2d = self.arr_float
72+
self.arr_float1_2d = self.arr_float1
7373

74-
self.arr_nan_2d = self.arr_nan[:, :, 0]
75-
self.arr_float_nan_2d = self.arr_float_nan[:, :, 0]
76-
self.arr_float1_nan_2d = self.arr_float1_nan[:, :, 0]
77-
self.arr_nan_float1_2d = self.arr_nan_float1[:, :, 0]
74+
self.arr_nan_2d = self.arr_nan
75+
self.arr_float_nan_2d = self.arr_float_nan
76+
self.arr_float1_nan_2d = self.arr_float1_nan
77+
self.arr_nan_float1_2d = self.arr_nan_float1
7878

79-
self.arr_float_1d = self.arr_float[:, 0, 0]
80-
self.arr_float1_1d = self.arr_float1[:, 0, 0]
79+
self.arr_float_1d = self.arr_float[:, 0]
80+
self.arr_float1_1d = self.arr_float1[:, 0]
8181

82-
self.arr_nan_1d = self.arr_nan[:, 0, 0]
83-
self.arr_float_nan_1d = self.arr_float_nan[:, 0, 0]
84-
self.arr_float1_nan_1d = self.arr_float1_nan[:, 0, 0]
85-
self.arr_nan_float1_1d = self.arr_nan_float1[:, 0, 0]
82+
self.arr_nan_1d = self.arr_nan[:, 0]
83+
self.arr_float_nan_1d = self.arr_float_nan[:, 0]
84+
self.arr_float1_nan_1d = self.arr_float1_nan[:, 0]
85+
self.arr_nan_float1_1d = self.arr_nan_float1[:, 0]
8686

8787
def teardown_method(self, method):
8888
nanops._USE_BOTTLENECK = use_bn

pandas/tseries/frequencies.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import timedelta
22
import re
3-
from typing import Dict
3+
from typing import Dict, Optional
44

55
import numpy as np
66
from pytz import AmbiguousTimeError
@@ -52,8 +52,10 @@
5252
_offset_map: Dict[str, DateOffset] = {}
5353

5454

55-
def get_period_alias(offset_str):
56-
""" alias to closest period strings BQ->Q etc"""
55+
def get_period_alias(offset_str: str) -> Optional[str]:
56+
"""
57+
Alias to closest period strings BQ->Q etc.
58+
"""
5759
return _offset_to_period_map.get(offset_str, None)
5860

5961

@@ -68,7 +70,7 @@ def get_period_alias(offset_str):
6870
}
6971

7072

71-
def to_offset(freq):
73+
def to_offset(freq) -> Optional[DateOffset]:
7274
"""
7375
Return DateOffset object from string or tuple representation
7476
or datetime.timedelta object.
@@ -179,9 +181,9 @@ def to_offset(freq):
179181
return delta
180182

181183

182-
def get_offset(name):
184+
def get_offset(name: str) -> DateOffset:
183185
"""
184-
Return DateOffset object associated with rule name
186+
Return DateOffset object associated with rule name.
185187
186188
Examples
187189
--------
@@ -214,7 +216,7 @@ def get_offset(name):
214216
# Period codes
215217

216218

217-
def infer_freq(index, warn=True):
219+
def infer_freq(index, warn: bool = True) -> Optional[str]:
218220
"""
219221
Infer the most likely frequency given the input index. If the frequency is
220222
uncertain, a warning will be printed.
@@ -247,6 +249,7 @@ def infer_freq(index, warn=True):
247249
)
248250
index = values
249251

252+
inferer: _FrequencyInferer
250253
if is_period_arraylike(index):
251254
raise TypeError(
252255
"PeriodIndex given. Check the `freq` attribute "
@@ -280,7 +283,7 @@ class _FrequencyInferer:
280283
Not sure if I can avoid the state machine here
281284
"""
282285

283-
def __init__(self, index, warn=True):
286+
def __init__(self, index, warn: bool = True):
284287
self.index = index
285288
self.values = index.asi8
286289

@@ -315,7 +318,7 @@ def is_unique(self) -> bool:
315318
def is_unique_asi8(self):
316319
return len(self.deltas_asi8) == 1
317320

318-
def get_freq(self):
321+
def get_freq(self) -> Optional[str]:
319322
"""
320323
Find the appropriate frequency string to describe the inferred
321324
frequency of self.values
@@ -388,7 +391,7 @@ def mdiffs(self):
388391
def ydiffs(self):
389392
return unique_deltas(self.fields["Y"].astype("i8"))
390393

391-
def _infer_daily_rule(self):
394+
def _infer_daily_rule(self) -> Optional[str]:
392395
annual_rule = self._get_annual_rule()
393396
if annual_rule:
394397
nyears = self.ydiffs[0]
@@ -424,7 +427,9 @@ def _infer_daily_rule(self):
424427
if wom_rule:
425428
return wom_rule
426429

427-
def _get_annual_rule(self):
430+
return None
431+
432+
def _get_annual_rule(self) -> Optional[str]:
428433
if len(self.ydiffs) > 1:
429434
return None
430435

@@ -434,7 +439,7 @@ def _get_annual_rule(self):
434439
pos_check = self.month_position_check()
435440
return {"cs": "AS", "bs": "BAS", "ce": "A", "be": "BA"}.get(pos_check)
436441

437-
def _get_quarterly_rule(self):
442+
def _get_quarterly_rule(self) -> Optional[str]:
438443
if len(self.mdiffs) > 1:
439444
return None
440445

@@ -444,13 +449,13 @@ def _get_quarterly_rule(self):
444449
pos_check = self.month_position_check()
445450
return {"cs": "QS", "bs": "BQS", "ce": "Q", "be": "BQ"}.get(pos_check)
446451

447-
def _get_monthly_rule(self):
452+
def _get_monthly_rule(self) -> Optional[str]:
448453
if len(self.mdiffs) > 1:
449454
return None
450455
pos_check = self.month_position_check()
451456
return {"cs": "MS", "bs": "BMS", "ce": "M", "be": "BM"}.get(pos_check)
452457

453-
def _is_business_daily(self):
458+
def _is_business_daily(self) -> bool:
454459
# quick check: cannot be business daily
455460
if self.day_deltas != [1, 3]:
456461
return False
@@ -465,7 +470,7 @@ def _is_business_daily(self):
465470
| ((weekdays > 0) & (weekdays <= 4) & (shifts == 1))
466471
)
467472

468-
def _get_wom_rule(self):
473+
def _get_wom_rule(self) -> Optional[str]:
469474
# wdiffs = unique(np.diff(self.index.week))
470475
# We also need -47, -49, -48 to catch index spanning year boundary
471476
# if not lib.ismember(wdiffs, set([4, 5, -47, -49, -48])).all():
@@ -501,11 +506,11 @@ def _infer_daily_rule(self):
501506
return _maybe_add_count("D", days)
502507

503508

504-
def _is_multiple(us, mult):
509+
def _is_multiple(us, mult: int) -> bool:
505510
return us % mult == 0
506511

507512

508-
def _maybe_add_count(base, count):
513+
def _maybe_add_count(base: str, count: float) -> str:
509514
if count != 1:
510515
assert count == int(count)
511516
count = int(count)

0 commit comments

Comments
 (0)